Skip to content

Commit 3ef6b0b

Browse files
committed
Fixes
1 parent 00ff440 commit 3ef6b0b

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void CWeaponRPCs::LoadFunctions()
1818
{
1919
AddHandler(GIVE_WEAPON, GiveWeapon, "GiveWeapon");
2020
AddHandler(TAKE_WEAPON, TakeWeapon, "TakeWeapon");
21+
AddHandler(TAKE_WEAPONS, TakeWeapons, "TakeWeapons");
2122
AddHandler(TAKE_ALL_WEAPONS, TakeAllWeapons, "TakeAllWeapons");
2223
AddHandler(SET_WEAPON_AMMO, SetWeaponAmmo, "SetWeaponAmmo");
2324
AddHandler(SET_WEAPON_SLOT, SetWeaponSlot, "SetWeaponSlot");
@@ -185,6 +186,42 @@ void CWeaponRPCs::TakeWeapon(CClientEntity* pSource, NetBitStreamInterface& bitS
185186
}
186187
}
187188

189+
void CWeaponRPCs::TakeWeapons(CClientEntity* pSource, NetBitStreamInterface& bitStream)
190+
{
191+
unsigned char count = 0;
192+
if (!bitStream.Read(count))
193+
return;
194+
195+
CClientPed* pPed = m_pPedManager->Get(pSource->GetID(), true);
196+
if (!pPed)
197+
return;
198+
199+
for (int i = 0; i < count; i++)
200+
{
201+
unsigned char ucWeaponID, ucAmmo, ucSlot;
202+
if (!bitStream.Read(ucWeaponID)) continue;
203+
if (!bitStream.Read(ucAmmo)) continue;
204+
if (!bitStream.Read(ucSlot)) continue;
205+
206+
if (!CClientPickupManager::IsValidWeaponID(ucWeaponID))
207+
continue;
208+
209+
if (pPed->IsLocalPlayer())
210+
{
211+
pPed->RemoveWeapon(static_cast<eWeaponType>(ucWeaponID));
212+
}
213+
else
214+
{
215+
CWeapon* pPlayerWeapon = pPed->GetWeapon((eWeaponType)ucWeaponID);
216+
if (pPlayerWeapon)
217+
{
218+
pPlayerWeapon->SetAmmoInClip(0);
219+
pPlayerWeapon->SetAmmoTotal(0);
220+
}
221+
}
222+
}
223+
}
224+
188225
void CWeaponRPCs::TakeAllWeapons(CClientEntity* pSource, NetBitStreamInterface& bitStream)
189226
{
190227
CClientPed* pPed = m_pPedManager->Get(pSource->GetID(), true);

Client/mods/deathmatch/logic/rpc/CWeaponRPCs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CWeaponRPCs : public CRPCFunctions
2020

2121
DECLARE_ELEMENT_RPC(GiveWeapon);
2222
DECLARE_ELEMENT_RPC(TakeWeapon);
23+
DECLARE_ELEMENT_RPC(TakeWeapons);
2324
DECLARE_ELEMENT_RPC(TakeAllWeapons);
2425
DECLARE_ELEMENT_RPC(GiveWeaponAmmo);
2526
DECLARE_ELEMENT_RPC(TakeWeaponAmmo);

Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ ADD_ENUM1(SET_VEHICLE_HEADLIGHT_COLOR)
9292
ADD_ENUM1(SET_VEHICLE_DOOR_OPEN_RATIO)
9393
ADD_ENUM1(GIVE_WEAPON)
9494
ADD_ENUM1(TAKE_WEAPON)
95+
ADD_ENUM1(TAKE_WEAPONS)
9596
ADD_ENUM1(TAKE_ALL_WEAPONS)
9697
ADD_ENUM1(SET_WEAPON_AMMO)
9798
ADD_ENUM1(SET_WEAPON_SLOT)

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4943,11 +4943,13 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement)
49434943
CPed* pPed = static_cast<CPed*>(pElement);
49444944
if (pPed->IsSpawned())
49454945
{
4946+
std::vector<std::tuple<unsigned char, unsigned char, unsigned char>> weapons;
49464947

49474948
for (unsigned char ucWeaponSlot = 0; ucWeaponSlot < WEAPON_SLOTS; ++ucWeaponSlot)
49484949
{
49494950
unsigned char ucWeaponID = pPed->GetWeaponType(ucWeaponSlot);
49504951
unsigned char ucAmmo = pPed->GetWeaponTotalAmmo(ucWeaponSlot);
4952+
49514953
if (ucWeaponID > 0)
49524954
{
49534955
CLuaArguments arguments;
@@ -4961,11 +4963,7 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement)
49614963

49624964
if (shouldTake)
49634965
{
4964-
CBitStream BitStream;
4965-
SWeaponTypeSync weaponType;
4966-
weaponType.data.ucWeaponType = ucWeaponID;
4967-
BitStream.pBitStream->Write(&weaponType);
4968-
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_WEAPON, *BitStream.pBitStream));
4966+
weapons.push_back({ucWeaponID, ucAmmo, ucWeaponSlot});
49694967

49704968
pPed->SetWeaponType(0, ucWeaponSlot);
49714969
pPed->SetWeaponAmmoInClip(0, ucWeaponSlot);
@@ -4974,6 +4972,23 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement)
49744972
}
49754973
}
49764974

4975+
if (!weapons.empty())
4976+
{
4977+
CBitStream BitStream;
4978+
unsigned char weaponsTaken = (unsigned char)weapons.size();
4979+
4980+
BitStream.pBitStream->Write(weaponsTaken);
4981+
4982+
for (auto& w : weapons)
4983+
{
4984+
BitStream.pBitStream->Write(std::get<0>(w));
4985+
BitStream.pBitStream->Write(std::get<1>(w));
4986+
BitStream.pBitStream->Write(std::get<2>(w));
4987+
}
4988+
4989+
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_WEAPONS, *BitStream.pBitStream));
4990+
}
4991+
49774992
return true;
49784993
}
49794994
}

Shared/sdk/net/rpc_enums.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ enum eElementRPCFunctions
101101

102102
GIVE_WEAPON,
103103
TAKE_WEAPON,
104+
TAKE_WEAPONS,
104105
TAKE_ALL_WEAPONS,
105106
SET_WEAPON_AMMO,
106107
SET_WEAPON_SLOT,

0 commit comments

Comments
 (0)