From 141d7761588dc5af06f0a936dc8a4dac449e2082 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 15 Sep 2025 18:05:49 +0300 Subject: [PATCH 1/8] Add onPlayerWeaponGiven/onPlayerWeaponTaken events --- Server/mods/deathmatch/logic/CGame.cpp | 4 ++ .../logic/CStaticFunctionDefinitions.cpp | 62 +++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index 9827804cfc0..43d830d4194 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -1654,6 +1654,8 @@ void CGame::AddBuiltInEvents() m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false); m_Events.AddEvent("onPlayerChangesWorldSpecialProperty", "property, enabled", nullptr, false); m_Events.AddEvent("onPlayerTeleport", "previousX, previousY, previousZ, currentX, currentY, currentZ", nullptr, false); + m_Events.AddEvent("onPlayerWeaponGiven", "weaponID", nullptr, false); + m_Events.AddEvent("onPlayerWeaponTaken", "weaponID, weaponAmmo, weaponSlot", nullptr, false); // Ped events m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false); @@ -1662,6 +1664,8 @@ void CGame::AddBuiltInEvents() m_Events.AddEvent("onPedWeaponSwitch", "previous, current", NULL, false); m_Events.AddEvent("onPedWeaponReload", "weapon, clip, ammo", nullptr, false); m_Events.AddEvent("onPedDamage", "loss", NULL, false); + m_Events.AddEvent("onPedWeaponGiven", "weaponID", nullptr, false); + m_Events.AddEvent("onPedWeaponTaken", "weaponID, weaponAmmo, weaponSlot", nullptr, false); // Element events m_Events.AddEvent("onElementColShapeHit", "colshape, matchingDimension", NULL, false); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index d42467bc53c..b82d5ffed8d 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4823,6 +4823,18 @@ bool CStaticFunctionDefinitions::GiveWeapon(CElement* pElement, unsigned char uc unsigned char ucWeaponSlot = CWeaponNames::GetSlotFromWeapon(ucWeaponID); unsigned char ucPreviousWeaponID = pPed->GetWeaponType(ucWeaponSlot); + + CLuaArguments arguments; + arguments.PushNumber(ucWeaponID); + arguments.PushNumber(usAmmo); + arguments.PushNumber(ucWeaponSlot); + if (IS_PLAYER(pElement)) + if (!pPed->CallEvent("onPlayerWeaponGiven", arguments)) + return false; + else + if (!pPed->CallEvent("onPedWeaponGiven", arguments)) + return false; + pPed->SetWeaponType(ucWeaponID, ucWeaponSlot); if (bSetAsCurrent) pPed->SetWeaponSlot(ucWeaponSlot); @@ -4878,6 +4890,17 @@ bool CStaticFunctionDefinitions::TakeWeapon(CElement* pElement, unsigned char uc { CBitStream BitStream; + CLuaArguments arguments; + arguments.PushNumber(ucWeaponID); + arguments.PushNumber(usAmmo); + arguments.PushNumber(ucWeaponSlot); + if (IS_PLAYER(pElement)) + if (!pPed->CallEvent("onPlayerWeaponTaken", arguments)) + return false; + else + if (!pPed->CallEvent("onPedWeaponTaken", arguments)) + return false; + SWeaponTypeSync weaponType; weaponType.data.ucWeaponType = ucWeaponID; BitStream.pBitStream->Write(&weaponType); @@ -4928,14 +4951,43 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) CPed* pPed = static_cast(pElement); if (pPed->IsSpawned()) { - CBitStream BitStream; - m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_ALL_WEAPONS, *BitStream.pBitStream)); for (unsigned char ucWeaponSlot = 0; ucWeaponSlot < WEAPON_SLOTS; ++ucWeaponSlot) { - pPed->SetWeaponType(0, ucWeaponSlot); - pPed->SetWeaponAmmoInClip(0, ucWeaponSlot); - pPed->SetWeaponTotalAmmo(0, ucWeaponSlot); + unsigned char ucWeaponID = pPed->GetWeaponType(ucWeaponSlot); + unsigned char ucAmmo = pPed->GetWeaponTotalAmmo(ucWeaponSlot); + if (ucWeaponID > 0) + { + CLuaArguments arguments; + arguments.PushNumber(ucWeaponID); + arguments.PushNumber(ucAmmo); + arguments.PushNumber(ucWeaponSlot); + + bool bTake = true; + if (IS_PLAYER(pElement)) + { + if (!pPed->CallEvent("onPlayerWeaponTaken", arguments)) + bTake = false; + } + else + { + if (!pPed->CallEvent("onPedWeaponTaken", arguments)) + bTake = false; + } + + if (bTake) + { + CBitStream BitStream; + SWeaponTypeSync weaponType; + weaponType.data.ucWeaponType = ucWeaponID; + BitStream.pBitStream->Write(&weaponType); + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_WEAPON, *BitStream.pBitStream)); + + pPed->SetWeaponType(0, ucWeaponSlot); + pPed->SetWeaponAmmoInClip(0, ucWeaponSlot); + pPed->SetWeaponTotalAmmo(0, ucWeaponSlot); + } + } } return true; From 8fb4efc24cf3b79448d0a2b5294afdf2c2d5a5c2 Mon Sep 17 00:00:00 2001 From: Omar Date: Tue, 16 Sep 2025 16:36:23 +0300 Subject: [PATCH 2/8] Fixes --- Server/mods/deathmatch/logic/CGame.cpp | 4 ++-- .../logic/CStaticFunctionDefinitions.cpp | 24 +++++-------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index 43d830d4194..e27a169edd6 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -1654,7 +1654,7 @@ void CGame::AddBuiltInEvents() m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false); m_Events.AddEvent("onPlayerChangesWorldSpecialProperty", "property, enabled", nullptr, false); m_Events.AddEvent("onPlayerTeleport", "previousX, previousY, previousZ, currentX, currentY, currentZ", nullptr, false); - m_Events.AddEvent("onPlayerWeaponGiven", "weaponID", nullptr, false); + m_Events.AddEvent("onPlayerWeaponGiven", "weaponID, weaponAmmo, weaponSlot", nullptr, false); m_Events.AddEvent("onPlayerWeaponTaken", "weaponID, weaponAmmo, weaponSlot", nullptr, false); // Ped events @@ -1664,7 +1664,7 @@ void CGame::AddBuiltInEvents() m_Events.AddEvent("onPedWeaponSwitch", "previous, current", NULL, false); m_Events.AddEvent("onPedWeaponReload", "weapon, clip, ammo", nullptr, false); m_Events.AddEvent("onPedDamage", "loss", NULL, false); - m_Events.AddEvent("onPedWeaponGiven", "weaponID", nullptr, false); + m_Events.AddEvent("onPedWeaponGiven", "weaponID, weaponAmmo, weaponSlot", nullptr, false); m_Events.AddEvent("onPedWeaponTaken", "weaponID, weaponAmmo, weaponSlot", nullptr, false); // Element events diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index b82d5ffed8d..ff74b80b9b4 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4828,12 +4828,8 @@ bool CStaticFunctionDefinitions::GiveWeapon(CElement* pElement, unsigned char uc arguments.PushNumber(ucWeaponID); arguments.PushNumber(usAmmo); arguments.PushNumber(ucWeaponSlot); - if (IS_PLAYER(pElement)) - if (!pPed->CallEvent("onPlayerWeaponGiven", arguments)) - return false; - else - if (!pPed->CallEvent("onPedWeaponGiven", arguments)) - return false; + if (!pPed->CallEvent(IS_PLAYER(pElement) ? "onPlayerWeaponGiven" : "onPedWeaponGiven", arguments)) + return false; pPed->SetWeaponType(ucWeaponID, ucWeaponSlot); if (bSetAsCurrent) @@ -4963,19 +4959,11 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) arguments.PushNumber(ucAmmo); arguments.PushNumber(ucWeaponSlot); - bool bTake = true; - if (IS_PLAYER(pElement)) - { - if (!pPed->CallEvent("onPlayerWeaponTaken", arguments)) - bTake = false; - } - else - { - if (!pPed->CallEvent("onPedWeaponTaken", arguments)) - bTake = false; - } + bool shouldTake = true; + if (!pPed->CallEvent(IS_PLAYER(pElement) ? "onPlayerWeaponTaken" : "onPedWeaponTaken", arguments)) + shouldTake = false; - if (bTake) + if (shouldTake) { CBitStream BitStream; SWeaponTypeSync weaponType; From 95f9b2013867d87b1dc3c76e42102d22590251ee Mon Sep 17 00:00:00 2001 From: Omar Date: Wed, 17 Sep 2025 05:37:06 +0300 Subject: [PATCH 3/8] Fixes --- .../mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index ff74b80b9b4..f01ba48f628 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4890,12 +4890,8 @@ bool CStaticFunctionDefinitions::TakeWeapon(CElement* pElement, unsigned char uc arguments.PushNumber(ucWeaponID); arguments.PushNumber(usAmmo); arguments.PushNumber(ucWeaponSlot); - if (IS_PLAYER(pElement)) - if (!pPed->CallEvent("onPlayerWeaponTaken", arguments)) - return false; - else - if (!pPed->CallEvent("onPedWeaponTaken", arguments)) - return false; + if (!pPed->CallEvent(IS_PLAYER(pElement) ? "onPlayerWeaponTaken" : "onPedWeaponTaken", arguments)) + return false; SWeaponTypeSync weaponType; weaponType.data.ucWeaponType = ucWeaponID; From c8777e16e86ab84650196b045ded10f848f13427 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 22 Sep 2025 16:49:42 +0300 Subject: [PATCH 4/8] fixes --- .../logic/CStaticFunctionDefinitions.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index f01ba48f628..18c767976ca 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4805,6 +4805,15 @@ bool CStaticFunctionDefinitions::GiveWeapon(CElement* pElement, unsigned char uc if (pPed->IsSpawned()) { unsigned char ucCurrentWeapon = pPed->GetWeaponType(); + unsigned char ucWeaponSlot = CWeaponNames::GetSlotFromWeapon(ucWeaponID); + + CLuaArguments arguments; + arguments.PushNumber(ucWeaponID); + arguments.PushNumber(usAmmo); + arguments.PushNumber(ucWeaponSlot); + if (!pPed->CallEvent(IS_PLAYER(pElement) ? "onPlayerWeaponGiven" : "onPedWeaponGiven", arguments)) + return false; + if (ucCurrentWeapon != ucWeaponID && bSetAsCurrent) { // Call our weapon switch command @@ -4821,15 +4830,7 @@ bool CStaticFunctionDefinitions::GiveWeapon(CElement* pElement, unsigned char uc bSetAsCurrent = false; } - unsigned char ucWeaponSlot = CWeaponNames::GetSlotFromWeapon(ucWeaponID); unsigned char ucPreviousWeaponID = pPed->GetWeaponType(ucWeaponSlot); - - CLuaArguments arguments; - arguments.PushNumber(ucWeaponID); - arguments.PushNumber(usAmmo); - arguments.PushNumber(ucWeaponSlot); - if (!pPed->CallEvent(IS_PLAYER(pElement) ? "onPlayerWeaponGiven" : "onPedWeaponGiven", arguments)) - return false; pPed->SetWeaponType(ucWeaponID, ucWeaponSlot); if (bSetAsCurrent) @@ -4884,15 +4885,14 @@ bool CStaticFunctionDefinitions::TakeWeapon(CElement* pElement, unsigned char uc // Just because it's the same slot doesn't mean it's the same weapon -_- - Caz if (pPed->IsSpawned() && pPed->GetWeapon(ucWeaponSlot) && pPed->GetWeaponType(ucWeaponSlot) == ucWeaponID) { - CBitStream BitStream; - CLuaArguments arguments; arguments.PushNumber(ucWeaponID); arguments.PushNumber(usAmmo); arguments.PushNumber(ucWeaponSlot); if (!pPed->CallEvent(IS_PLAYER(pElement) ? "onPlayerWeaponTaken" : "onPedWeaponTaken", arguments)) return false; - + + CBitStream BitStream; SWeaponTypeSync weaponType; weaponType.data.ucWeaponType = ucWeaponID; BitStream.pBitStream->Write(&weaponType); From 3ef6b0b41a57251c9598f6b55ced7956bb87b705 Mon Sep 17 00:00:00 2001 From: Omar Date: Tue, 23 Sep 2025 21:46:08 +0300 Subject: [PATCH 5/8] Fixes --- .../mods/deathmatch/logic/rpc/CWeaponRPCs.cpp | 37 +++++++++++++++++++ .../mods/deathmatch/logic/rpc/CWeaponRPCs.h | 1 + .../logic/CPerfStat.RPCPacketUsage.cpp | 1 + .../logic/CStaticFunctionDefinitions.cpp | 25 ++++++++++--- Shared/sdk/net/rpc_enums.h | 1 + 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp index 3b8f90b1078..525fda101d0 100644 --- a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp @@ -18,6 +18,7 @@ void CWeaponRPCs::LoadFunctions() { AddHandler(GIVE_WEAPON, GiveWeapon, "GiveWeapon"); AddHandler(TAKE_WEAPON, TakeWeapon, "TakeWeapon"); + AddHandler(TAKE_WEAPONS, TakeWeapons, "TakeWeapons"); AddHandler(TAKE_ALL_WEAPONS, TakeAllWeapons, "TakeAllWeapons"); AddHandler(SET_WEAPON_AMMO, SetWeaponAmmo, "SetWeaponAmmo"); AddHandler(SET_WEAPON_SLOT, SetWeaponSlot, "SetWeaponSlot"); @@ -185,6 +186,42 @@ void CWeaponRPCs::TakeWeapon(CClientEntity* pSource, NetBitStreamInterface& bitS } } +void CWeaponRPCs::TakeWeapons(CClientEntity* pSource, NetBitStreamInterface& bitStream) +{ + unsigned char count = 0; + if (!bitStream.Read(count)) + return; + + CClientPed* pPed = m_pPedManager->Get(pSource->GetID(), true); + if (!pPed) + return; + + for (int i = 0; i < count; i++) + { + unsigned char ucWeaponID, ucAmmo, ucSlot; + if (!bitStream.Read(ucWeaponID)) continue; + if (!bitStream.Read(ucAmmo)) continue; + if (!bitStream.Read(ucSlot)) continue; + + if (!CClientPickupManager::IsValidWeaponID(ucWeaponID)) + continue; + + if (pPed->IsLocalPlayer()) + { + pPed->RemoveWeapon(static_cast(ucWeaponID)); + } + else + { + CWeapon* pPlayerWeapon = pPed->GetWeapon((eWeaponType)ucWeaponID); + if (pPlayerWeapon) + { + pPlayerWeapon->SetAmmoInClip(0); + pPlayerWeapon->SetAmmoTotal(0); + } + } + } +} + void CWeaponRPCs::TakeAllWeapons(CClientEntity* pSource, NetBitStreamInterface& bitStream) { CClientPed* pPed = m_pPedManager->Get(pSource->GetID(), true); diff --git a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.h b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.h index 8bc3437fe47..2f63b27b6c6 100644 --- a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.h +++ b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.h @@ -20,6 +20,7 @@ class CWeaponRPCs : public CRPCFunctions DECLARE_ELEMENT_RPC(GiveWeapon); DECLARE_ELEMENT_RPC(TakeWeapon); + DECLARE_ELEMENT_RPC(TakeWeapons); DECLARE_ELEMENT_RPC(TakeAllWeapons); DECLARE_ELEMENT_RPC(GiveWeaponAmmo); DECLARE_ELEMENT_RPC(TakeWeaponAmmo); diff --git a/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp b/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp index cdebcedcc24..1b462a95bc2 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp @@ -92,6 +92,7 @@ ADD_ENUM1(SET_VEHICLE_HEADLIGHT_COLOR) ADD_ENUM1(SET_VEHICLE_DOOR_OPEN_RATIO) ADD_ENUM1(GIVE_WEAPON) ADD_ENUM1(TAKE_WEAPON) +ADD_ENUM1(TAKE_WEAPONS) ADD_ENUM1(TAKE_ALL_WEAPONS) ADD_ENUM1(SET_WEAPON_AMMO) ADD_ENUM1(SET_WEAPON_SLOT) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index cb51693b527..bbd4e0dede6 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4943,11 +4943,13 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) CPed* pPed = static_cast(pElement); if (pPed->IsSpawned()) { + std::vector> weapons; for (unsigned char ucWeaponSlot = 0; ucWeaponSlot < WEAPON_SLOTS; ++ucWeaponSlot) { unsigned char ucWeaponID = pPed->GetWeaponType(ucWeaponSlot); unsigned char ucAmmo = pPed->GetWeaponTotalAmmo(ucWeaponSlot); + if (ucWeaponID > 0) { CLuaArguments arguments; @@ -4961,11 +4963,7 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) if (shouldTake) { - CBitStream BitStream; - SWeaponTypeSync weaponType; - weaponType.data.ucWeaponType = ucWeaponID; - BitStream.pBitStream->Write(&weaponType); - m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_WEAPON, *BitStream.pBitStream)); + weapons.push_back({ucWeaponID, ucAmmo, ucWeaponSlot}); pPed->SetWeaponType(0, ucWeaponSlot); pPed->SetWeaponAmmoInClip(0, ucWeaponSlot); @@ -4974,6 +4972,23 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) } } + if (!weapons.empty()) + { + CBitStream BitStream; + unsigned char weaponsTaken = (unsigned char)weapons.size(); + + BitStream.pBitStream->Write(weaponsTaken); + + for (auto& w : weapons) + { + BitStream.pBitStream->Write(std::get<0>(w)); + BitStream.pBitStream->Write(std::get<1>(w)); + BitStream.pBitStream->Write(std::get<2>(w)); + } + + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_WEAPONS, *BitStream.pBitStream)); + } + return true; } } diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index 84c7518bc45..e659873eee3 100644 --- a/Shared/sdk/net/rpc_enums.h +++ b/Shared/sdk/net/rpc_enums.h @@ -101,6 +101,7 @@ enum eElementRPCFunctions GIVE_WEAPON, TAKE_WEAPON, + TAKE_WEAPONS, TAKE_ALL_WEAPONS, SET_WEAPON_AMMO, SET_WEAPON_SLOT, From d5c0e0ac69bbc789269d6dddd260c4b87f024e7e Mon Sep 17 00:00:00 2001 From: Omar Date: Tue, 23 Sep 2025 22:33:51 +0300 Subject: [PATCH 6/8] Fixes --- .../mods/deathmatch/logic/rpc/CWeaponRPCs.cpp | 18 +++++++++--------- .../logic/CStaticFunctionDefinitions.cpp | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp index 525fda101d0..e18bf1fdc69 100644 --- a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp @@ -188,7 +188,7 @@ void CWeaponRPCs::TakeWeapon(CClientEntity* pSource, NetBitStreamInterface& bitS void CWeaponRPCs::TakeWeapons(CClientEntity* pSource, NetBitStreamInterface& bitStream) { - unsigned char count = 0; + std::uint8_t count = 0; if (!bitStream.Read(count)) return; @@ -196,23 +196,23 @@ void CWeaponRPCs::TakeWeapons(CClientEntity* pSource, NetBitStreamInterface& bit if (!pPed) return; - for (int i = 0; i < count; i++) + for (std::uint8_t i = 0; i < count; i++) { - unsigned char ucWeaponID, ucAmmo, ucSlot; - if (!bitStream.Read(ucWeaponID)) continue; - if (!bitStream.Read(ucAmmo)) continue; - if (!bitStream.Read(ucSlot)) continue; + unsigned char weaponID, ammo, slot; + if (!bitStream.Read(weaponID)) continue; + if (!bitStream.Read(ammo)) continue; + if (!bitStream.Read(slot)) continue; - if (!CClientPickupManager::IsValidWeaponID(ucWeaponID)) + if (!CClientPickupManager::IsValidWeaponID(weaponID)) continue; if (pPed->IsLocalPlayer()) { - pPed->RemoveWeapon(static_cast(ucWeaponID)); + pPed->RemoveWeapon(static_cast(weaponID)); } else { - CWeapon* pPlayerWeapon = pPed->GetWeapon((eWeaponType)ucWeaponID); + CWeapon* pPlayerWeapon = pPed->GetWeapon((eWeaponType)weaponID); if (pPlayerWeapon) { pPlayerWeapon->SetAmmoInClip(0); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index bbd4e0dede6..e2ca9cefe7d 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4975,7 +4975,7 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) if (!weapons.empty()) { CBitStream BitStream; - unsigned char weaponsTaken = (unsigned char)weapons.size(); + std::size_t weaponsTaken = (std::size_t)weapons.size(); BitStream.pBitStream->Write(weaponsTaken); From 3b1a0825c0368167db69252fba8a57946f352e08 Mon Sep 17 00:00:00 2001 From: Omar Date: Wed, 24 Sep 2025 11:26:38 +0300 Subject: [PATCH 7/8] fixes --- Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp | 11 +++++------ .../deathmatch/logic/CStaticFunctionDefinitions.cpp | 12 +++++------- Shared/sdk/net/rpc_enums.h | 3 ++- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp index e18bf1fdc69..cf72660d8b5 100644 --- a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp @@ -188,7 +188,7 @@ void CWeaponRPCs::TakeWeapon(CClientEntity* pSource, NetBitStreamInterface& bitS void CWeaponRPCs::TakeWeapons(CClientEntity* pSource, NetBitStreamInterface& bitStream) { - std::uint8_t count = 0; + std::uint32_t count = 0; if (!bitStream.Read(count)) return; @@ -196,12 +196,11 @@ void CWeaponRPCs::TakeWeapons(CClientEntity* pSource, NetBitStreamInterface& bit if (!pPed) return; - for (std::uint8_t i = 0; i < count; i++) + for (std::uint32_t i = 0; i < count; i++) { - unsigned char weaponID, ammo, slot; - if (!bitStream.Read(weaponID)) continue; - if (!bitStream.Read(ammo)) continue; - if (!bitStream.Read(slot)) continue; + unsigned char weaponID; + if (!bitStream.Read(weaponID)) + return; if (!CClientPickupManager::IsValidWeaponID(weaponID)) continue; diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index e2ca9cefe7d..1cfdacfd028 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4943,7 +4943,7 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) CPed* pPed = static_cast(pElement); if (pPed->IsSpawned()) { - std::vector> weapons; + std::vector weapons; for (unsigned char ucWeaponSlot = 0; ucWeaponSlot < WEAPON_SLOTS; ++ucWeaponSlot) { @@ -4963,7 +4963,7 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) if (shouldTake) { - weapons.push_back({ucWeaponID, ucAmmo, ucWeaponSlot}); + weapons.push_back(ucWeaponID); pPed->SetWeaponType(0, ucWeaponSlot); pPed->SetWeaponAmmoInClip(0, ucWeaponSlot); @@ -4975,15 +4975,13 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) if (!weapons.empty()) { CBitStream BitStream; - std::size_t weaponsTaken = (std::size_t)weapons.size(); + std::uint32_t weaponsTaken = (std::uint32_t)weapons.size(); BitStream.pBitStream->Write(weaponsTaken); - for (auto& w : weapons) + for (auto& weaponID : weapons) { - BitStream.pBitStream->Write(std::get<0>(w)); - BitStream.pBitStream->Write(std::get<1>(w)); - BitStream.pBitStream->Write(std::get<2>(w)); + BitStream.pBitStream->Write(weaponID); } m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_WEAPONS, *BitStream.pBitStream)); diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index e659873eee3..7a779e2ee58 100644 --- a/Shared/sdk/net/rpc_enums.h +++ b/Shared/sdk/net/rpc_enums.h @@ -101,7 +101,6 @@ enum eElementRPCFunctions GIVE_WEAPON, TAKE_WEAPON, - TAKE_WEAPONS, TAKE_ALL_WEAPONS, SET_WEAPON_AMMO, SET_WEAPON_SLOT, @@ -294,5 +293,7 @@ enum eElementRPCFunctions SET_ELEMENT_ON_FIRE, + TAKE_WEAPONS, + NUM_RPC_FUNCS // Add above this line }; From b02628353bbf03474472de3cbe54210982471072 Mon Sep 17 00:00:00 2001 From: Omar Date: Wed, 24 Sep 2025 19:18:26 +0300 Subject: [PATCH 8/8] fixes --- Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp | 16 ++++++++-------- .../logic/CStaticFunctionDefinitions.cpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp index cf72660d8b5..1b0c5f95d6f 100644 --- a/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp @@ -192,8 +192,8 @@ void CWeaponRPCs::TakeWeapons(CClientEntity* pSource, NetBitStreamInterface& bit if (!bitStream.Read(count)) return; - CClientPed* pPed = m_pPedManager->Get(pSource->GetID(), true); - if (!pPed) + CClientPed* ped = m_pPedManager->Get(pSource->GetID(), true); + if (!ped) return; for (std::uint32_t i = 0; i < count; i++) @@ -205,17 +205,17 @@ void CWeaponRPCs::TakeWeapons(CClientEntity* pSource, NetBitStreamInterface& bit if (!CClientPickupManager::IsValidWeaponID(weaponID)) continue; - if (pPed->IsLocalPlayer()) + if (ped->IsLocalPlayer()) { - pPed->RemoveWeapon(static_cast(weaponID)); + ped->RemoveWeapon(static_cast(weaponID)); } else { - CWeapon* pPlayerWeapon = pPed->GetWeapon((eWeaponType)weaponID); - if (pPlayerWeapon) + CWeapon* playerWeapon = ped->GetWeapon(static_cast(weaponID)); + if (playerWeapon) { - pPlayerWeapon->SetAmmoInClip(0); - pPlayerWeapon->SetAmmoTotal(0); + playerWeapon->SetAmmoInClip(0); + playerWeapon->SetAmmoTotal(0); } } } diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 73e005ec72e..bc103da96c4 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4977,7 +4977,7 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement) if (!weapons.empty()) { CBitStream BitStream; - std::uint32_t weaponsTaken = (std::uint32_t)weapons.size(); + std::uint32_t weaponsTaken = static_cast(weapons.size()); BitStream.pBitStream->Write(weaponsTaken);