feat: add player:RunCommand (#176)

This commit is contained in:
Tralenor
2024-06-15 11:34:57 +02:00
committed by GitHub
parent 067fa20bad
commit 3fea22bc41
2 changed files with 21 additions and 0 deletions

View File

@@ -705,6 +705,8 @@ ElunaRegister<Player> PlayerMethods[] =
{ "ModifyMoney", &LuaPlayer::ModifyMoney },
{ "LearnSpell", &LuaPlayer::LearnSpell },
{ "LearnTalent", &LuaPlayer::LearnTalent },
{ "RunCommand", &LuaPlayer::RunCommand },
{ "SetGlyph", &LuaPlayer::SetGlyph },
{ "GetGlyph", &LuaPlayer::GetGlyph },
#if !defined(CLASSIC)

View File

@@ -3935,6 +3935,25 @@ namespace LuaPlayer
#endif
return 0;
}
/**
* Run a chat command as if the player typed it into the chat
*
* @param string command: text to display in chat or console
*/
int RunCommand(lua_State* L, Player* player)
{
auto command = Eluna::CHECKVAL<std::string>(L, 2);
// In _ParseCommands which is used below no leading . or ! is allowed for the command string.
if (command[0] == '.' || command[0] == '!') {
command = command.substr(1);
}
auto handler = ChatHandler(player->GetSession());
handler._ParseCommands(command);
return 0;
}
/**
* Adds a glyph specified by `glyphId` to the [Player]'s current talent specialization into the slot with the index `slotIndex`