Skip to content

Commit

Permalink
add player:RunCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Tralenor committed Jun 2, 2024
1 parent 152a491 commit 11a490b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/LuaEngine/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ ElunaRegister<Player> PlayerMethods[] =
{ "ModifyMoney", &LuaPlayer::ModifyMoney },
{ "LearnSpell", &LuaPlayer::LearnSpell },
{ "LearnTalent", &LuaPlayer::LearnTalent },

{ "RunCommand", &LuaPlayer::RunCommand },
{ "SetGlyph", &LuaPlayer::SetGlyph },
#if !defined(CLASSIC)
{ "RemoveArenaSpellCooldowns", &LuaPlayer::RemoveArenaSpellCooldowns },
Expand Down
19 changes: 19 additions & 0 deletions src/LuaEngine/PlayerMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 11a490b

Please sign in to comment.