From a5508d8cead013a0b08e9c2cddb5914e46be1abd Mon Sep 17 00:00:00 2001 From: Nikita Obrekht Date: Sat, 1 Feb 2020 00:06:47 +0200 Subject: [PATCH] Fix #1223: Regression: double chat messages if player is in team (#1241) --- .../logic/CStaticFunctionDefinitions.cpp | 18 ++--------------- .../logic/lua/CLuaFunctionDefs.Server.cpp | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index bd11b33471..20669ff1dd 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -9970,6 +9970,8 @@ bool CStaticFunctionDefinitions::OutputChatBox(const char* szText, CElement* pEl { assert(pElement); assert(szText); + + RUN_CHILDREN(OutputChatBox(szText, *iter, ucRed, ucGreen, ucBlue, bColorCoded, pLuaMain)) if (IS_PLAYER(pElement)) { @@ -9977,22 +9979,6 @@ bool CStaticFunctionDefinitions::OutputChatBox(const char* szText, CElement* pEl pPlayer->Send(CChatEchoPacket(szText, ucRed, ucGreen, ucBlue, bColorCoded)); return true; } - else if (IS_TEAM(pElement)) - { - CTeam* pTeam = static_cast(pElement); - list::const_iterator iter = pTeam->PlayersBegin(); - for (; iter != pTeam->PlayersEnd(); iter++) - { - CPlayer* pPlayer = *iter; - pPlayer->Send(CChatEchoPacket(szText, ucRed, ucGreen, ucBlue, bColorCoded)); - } - return true; - } - else - { - // Fixes issue 1223: https://github.com/multitheftauto/mtasa-blue/issues/1223 (Luxy.c) - RUN_CHILDREN(OutputChatBox(szText, *iter, ucRed, ucGreen, ucBlue, bColorCoded, pLuaMain)) - } if (pElement == m_pMapManager->GetRootElement()) { diff --git a/Server/mods/deathmatch/logic/lua/CLuaFunctionDefs.Server.cpp b/Server/mods/deathmatch/logic/lua/CLuaFunctionDefs.Server.cpp index c12c679c79..c7135a0c65 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaFunctionDefs.Server.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaFunctionDefs.Server.cpp @@ -83,11 +83,23 @@ int CLuaFunctionDefs::OutputChatBox(lua_State* luaVM) { if (pElement) { - CStaticFunctionDefinitions::OutputChatBox((const char*)ssChat, pElement, ucRed, ucGreen, ucBlue, bColorCoded, pLuaMain); - lua_pushboolean(luaVM, true); - return 1; + if (IS_TEAM(pElement)) + { + CTeam* pTeam = static_cast(pElement); + for (auto iter = pTeam->PlayersBegin(); iter != pTeam->PlayersEnd(); iter++) + { + sendList.push_back(*iter); + } + } + else + { + CStaticFunctionDefinitions::OutputChatBox((const char*)ssChat, pElement, ucRed, ucGreen, ucBlue, bColorCoded, pLuaMain); + lua_pushboolean(luaVM, true); + return 1; + } } - else if (sendList.size() > 0) + + if (sendList.size() > 0) { CStaticFunctionDefinitions::OutputChatBox((const char*)ssChat, sendList, ucRed, ucGreen, ucBlue, bColorCoded); lua_pushboolean(luaVM, true);