From 3fea22bc41fc205b66b188bcaff859e7d6a9a3e3 Mon Sep 17 00:00:00 2001 From: Tralenor <76077537+Tralenor@users.noreply.github.com> Date: Sat, 15 Jun 2024 11:34:57 +0200 Subject: [PATCH] feat: add player:RunCommand (#176) --- src/LuaEngine/LuaFunctions.cpp | 2 ++ src/LuaEngine/PlayerMethods.h | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index 8eb804a..a4c75b0 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -705,6 +705,8 @@ ElunaRegister PlayerMethods[] = { "ModifyMoney", &LuaPlayer::ModifyMoney }, { "LearnSpell", &LuaPlayer::LearnSpell }, { "LearnTalent", &LuaPlayer::LearnTalent }, + + { "RunCommand", &LuaPlayer::RunCommand }, { "SetGlyph", &LuaPlayer::SetGlyph }, { "GetGlyph", &LuaPlayer::GetGlyph }, #if !defined(CLASSIC) diff --git a/src/LuaEngine/PlayerMethods.h b/src/LuaEngine/PlayerMethods.h index 503ca48..8ede7c8 100644 --- a/src/LuaEngine/PlayerMethods.h +++ b/src/LuaEngine/PlayerMethods.h @@ -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(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`