diff --git a/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp index 6756bace22..b438b02bf0 100644 --- a/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp @@ -23,6 +23,7 @@ void CPlayerRPCs::LoadFunctions() AddHandler(SET_PLAYER_NAMETAG_SHOWING, SetPlayerNametagShowing, "SetPlayerNametagShowing"); AddHandler(SET_PLAYER_TEAM, SetPlayerTeam, "SetPlayerTeam"); AddHandler(TAKE_PLAYER_SCREEN_SHOT, TakePlayerScreenShot, "TakePlayerScreenShot"); + AddHandler(REMOTE_PLAYER_WEAPON_SWITCH, RemotePlayerSwitchWeapon, "RemotePlayerSwitchWeapon"); } void CPlayerRPCs::SetPlayerMoney(NetBitStreamInterface& bitStream) @@ -168,3 +169,19 @@ void CPlayerRPCs::TakePlayerScreenShot(NetBitStreamInterface& bitStream) m_pClientGame->TakePlayerScreenShot(usSizeX, usSizeY, strTag, ucQuality, uiMaxBandwidth, usMaxPacketSize, pResource, uiServerSentTime); } + +void CPlayerRPCs::RemotePlayerSwitchWeapon(CClientEntity* pSource, NetBitStreamInterface& bitStream) +{ + uint lastSlot, currentSlot; + if (bitStream.Read(lastSlot) && bitStream.Read(currentSlot)) + { + CClientPlayer* pPlayer = m_pPlayerManager->Get(pSource->GetID()); + if (IS_REMOTE_PLAYER(pPlayer)) + { + CLuaArguments Arguments; + Arguments.PushNumber(lastSlot); + Arguments.PushNumber(currentSlot); + pPlayer->CallEvent("onClientPlayerWeaponSwitch", Arguments, true); + } + } +} diff --git a/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h b/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h index ec60fd2c35..9a193f2ddb 100644 --- a/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h +++ b/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h @@ -27,4 +27,5 @@ class CPlayerRPCs : public CRPCFunctions DECLARE_ELEMENT_RPC(SetPlayerNametagShowing); DECLARE_ELEMENT_RPC(SetPlayerTeam); DECLARE_RPC(TakePlayerScreenShot); + DECLARE_ELEMENT_RPC(RemotePlayerSwitchWeapon); }; diff --git a/Server/mods/deathmatch/logic/CRPCFunctions.cpp b/Server/mods/deathmatch/logic/CRPCFunctions.cpp index d926c2a271..7eb1636602 100644 --- a/Server/mods/deathmatch/logic/CRPCFunctions.cpp +++ b/Server/mods/deathmatch/logic/CRPCFunctions.cpp @@ -17,6 +17,7 @@ #include "CElementIDs.h" #include "CWeaponNames.h" #include "CPerfStatManager.h" +#include "packets/CElementRPCPacket.h" #include "CKeyBinds.h" #include "CStaticFunctionDefinitions.h" #include "net/SyncStructures.h" @@ -178,6 +179,26 @@ void CRPCFunctions::PlayerWeapon(NetBitStreamInterface& bitStream) Arguments.PushNumber(m_pSourcePlayer->GetWeaponType(uiSlot)); m_pSourcePlayer->CallEvent("onPlayerWeaponSwitch", Arguments); + + SViewerMapType& nearList = m_pSourcePlayer->GetNearPlayerList(); + if (!nearList.empty()) + { + static std::vector playersInNearList; + playersInNearList.reserve(nearList.size()); + playersInNearList.clear(); + + for (const auto& player : nearList) + playersInNearList.push_back(player.first); + + if (!playersInNearList.empty()) + { + CBitStream BitStream; + BitStream.pBitStream->Write((unsigned int)ucPrevSlot); + BitStream.pBitStream->Write(uiSlot); + + m_pPlayerManager->Broadcast(CElementRPCPacket(m_pSourcePlayer, REMOTE_PLAYER_WEAPON_SWITCH, *BitStream.pBitStream), playersInNearList); + } + } } m_pSourcePlayer->SetWeaponSlot(uiSlot); diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index 2749267f09..05661039cf 100644 --- a/Shared/sdk/net/rpc_enums.h +++ b/Shared/sdk/net/rpc_enums.h @@ -104,6 +104,7 @@ enum eElementRPCFunctions TAKE_ALL_WEAPONS, SET_WEAPON_AMMO, SET_WEAPON_SLOT, + REMOTE_PLAYER_WEAPON_SWITCH, DESTROY_ALL_BLIPS, SET_BLIP_ICON,