From 595247d51d6b01f397307794183dcfdea6a88cef Mon Sep 17 00:00:00 2001 From: boubouleuh Date: Mon, 2 Feb 2026 22:33:58 +0100 Subject: [PATCH] adding logchat boolean to MP.SendChatMessage --- include/LuaAPI.h | 2 +- src/LuaAPI.cpp | 10 +++++++--- src/TLuaEngine.cpp | 10 +++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/LuaAPI.h b/include/LuaAPI.h index 4c4f361..772d35c 100644 --- a/include/LuaAPI.h +++ b/include/LuaAPI.h @@ -34,7 +34,7 @@ namespace MP { std::pair TriggerClientEventJson(int PlayerID, const std::string& EventName, const sol::table& Data); inline size_t GetPlayerCount() { return Engine->Server().ClientCount(); } std::pair DropPlayer(int ID, std::optional MaybeReason); - std::pair SendChatMessage(int ID, const std::string& Message); + std::pair SendChatMessage(int ID, const std::string& Message, const bool& LogChat = true); std::pair SendNotification(int ID, const std::string& Message, const std::string& Icon, const std::string& Category); std::pair ConfirmationDialog(int ID, const std::string& Title, const std::string& Body, const sol::table& buttons, const std::string& InteractionID, const bool& warning = false, const bool& reportToServer = true, const bool& reportToExtensions = true); std::pair RemoveVehicle(int PlayerID, int VehicleID); diff --git a/src/LuaAPI.cpp b/src/LuaAPI.cpp index c71ff29..9ee2462 100644 --- a/src/LuaAPI.cpp +++ b/src/LuaAPI.cpp @@ -178,11 +178,13 @@ std::pair LuaAPI::MP::DropPlayer(int ID, std::optional LuaAPI::MP::SendChatMessage(int ID, const std::string& Message) { +std::pair LuaAPI::MP::SendChatMessage(int ID, const std::string& Message, const bool& LogChat) { std::pair Result; std::string Packet = "C:Server: " + Message; if (ID == -1) { - LogChatMessage(" (to everyone) ", -1, Message); + if (LogChat) { + LogChatMessage(" (to everyone) ", -1, Message); + } Engine->Network().SendToAll(nullptr, StringToVector(Packet), true, true); Result.first = true; } else { @@ -194,7 +196,9 @@ std::pair LuaAPI::MP::SendChatMessage(int ID, const std::stri Result.second = "Player still syncing data"; return Result; } - LogChatMessage(" (to \"" + c->GetName() + "\")", -1, Message); + if (LogChat) { + LogChatMessage(" (to \"" + c->GetName() + "\")", -1, Message); + } if (!Engine->Network().Respond(*c, StringToVector(Packet), true)) { beammp_errorf("Failed to send chat message back to sender (id {}) - did the sender disconnect?", ID); // TODO: should we return an error here? diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index 49dd445..e75cc0c 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -857,7 +857,15 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI MPTable.set_function("GetPositionRaw", [&](int PID, int VID) -> std::pair { return Lua_GetPositionRaw(PID, VID); }); - MPTable.set_function("SendChatMessage", &LuaAPI::MP::SendChatMessage); + MPTable.set_function("SendChatMessage", [&](sol::variadic_args Args) { + if (Args.size() == 2) { + LuaAPI::MP::SendChatMessage(Args.get(0), Args.get(1)); + } else if (Args.size() == 3) { + LuaAPI::MP::SendChatMessage(Args.get(0), Args.get(1), Args.get(2)); + } else { + beammp_lua_error("SendChatMessage expects 2 or 3 arguments."); + } + }); MPTable.set_function("SendNotification", [&](sol::variadic_args Args) { if (Args.size() == 2) { LuaAPI::MP::SendNotification(Args.get(0), Args.get(1), "", Args.get(1));