Skip to content

Commit 141d776

Browse files
committed
Add onPlayerWeaponGiven/onPlayerWeaponTaken events
1 parent 02bc654 commit 141d776

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,8 @@ void CGame::AddBuiltInEvents()
16541654
m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false);
16551655
m_Events.AddEvent("onPlayerChangesWorldSpecialProperty", "property, enabled", nullptr, false);
16561656
m_Events.AddEvent("onPlayerTeleport", "previousX, previousY, previousZ, currentX, currentY, currentZ", nullptr, false);
1657+
m_Events.AddEvent("onPlayerWeaponGiven", "weaponID", nullptr, false);
1658+
m_Events.AddEvent("onPlayerWeaponTaken", "weaponID, weaponAmmo, weaponSlot", nullptr, false);
16571659

16581660
// Ped events
16591661
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
@@ -1662,6 +1664,8 @@ void CGame::AddBuiltInEvents()
16621664
m_Events.AddEvent("onPedWeaponSwitch", "previous, current", NULL, false);
16631665
m_Events.AddEvent("onPedWeaponReload", "weapon, clip, ammo", nullptr, false);
16641666
m_Events.AddEvent("onPedDamage", "loss", NULL, false);
1667+
m_Events.AddEvent("onPedWeaponGiven", "weaponID", nullptr, false);
1668+
m_Events.AddEvent("onPedWeaponTaken", "weaponID, weaponAmmo, weaponSlot", nullptr, false);
16651669

16661670
// Element events
16671671
m_Events.AddEvent("onElementColShapeHit", "colshape, matchingDimension", NULL, false);

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4823,6 +4823,18 @@ bool CStaticFunctionDefinitions::GiveWeapon(CElement* pElement, unsigned char uc
48234823

48244824
unsigned char ucWeaponSlot = CWeaponNames::GetSlotFromWeapon(ucWeaponID);
48254825
unsigned char ucPreviousWeaponID = pPed->GetWeaponType(ucWeaponSlot);
4826+
4827+
CLuaArguments arguments;
4828+
arguments.PushNumber(ucWeaponID);
4829+
arguments.PushNumber(usAmmo);
4830+
arguments.PushNumber(ucWeaponSlot);
4831+
if (IS_PLAYER(pElement))
4832+
if (!pPed->CallEvent("onPlayerWeaponGiven", arguments))
4833+
return false;
4834+
else
4835+
if (!pPed->CallEvent("onPedWeaponGiven", arguments))
4836+
return false;
4837+
48264838
pPed->SetWeaponType(ucWeaponID, ucWeaponSlot);
48274839
if (bSetAsCurrent)
48284840
pPed->SetWeaponSlot(ucWeaponSlot);
@@ -4878,6 +4890,17 @@ bool CStaticFunctionDefinitions::TakeWeapon(CElement* pElement, unsigned char uc
48784890
{
48794891
CBitStream BitStream;
48804892

4893+
CLuaArguments arguments;
4894+
arguments.PushNumber(ucWeaponID);
4895+
arguments.PushNumber(usAmmo);
4896+
arguments.PushNumber(ucWeaponSlot);
4897+
if (IS_PLAYER(pElement))
4898+
if (!pPed->CallEvent("onPlayerWeaponTaken", arguments))
4899+
return false;
4900+
else
4901+
if (!pPed->CallEvent("onPedWeaponTaken", arguments))
4902+
return false;
4903+
48814904
SWeaponTypeSync weaponType;
48824905
weaponType.data.ucWeaponType = ucWeaponID;
48834906
BitStream.pBitStream->Write(&weaponType);
@@ -4928,14 +4951,43 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement)
49284951
CPed* pPed = static_cast<CPed*>(pElement);
49294952
if (pPed->IsSpawned())
49304953
{
4931-
CBitStream BitStream;
4932-
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_ALL_WEAPONS, *BitStream.pBitStream));
49334954

49344955
for (unsigned char ucWeaponSlot = 0; ucWeaponSlot < WEAPON_SLOTS; ++ucWeaponSlot)
49354956
{
4936-
pPed->SetWeaponType(0, ucWeaponSlot);
4937-
pPed->SetWeaponAmmoInClip(0, ucWeaponSlot);
4938-
pPed->SetWeaponTotalAmmo(0, ucWeaponSlot);
4957+
unsigned char ucWeaponID = pPed->GetWeaponType(ucWeaponSlot);
4958+
unsigned char ucAmmo = pPed->GetWeaponTotalAmmo(ucWeaponSlot);
4959+
if (ucWeaponID > 0)
4960+
{
4961+
CLuaArguments arguments;
4962+
arguments.PushNumber(ucWeaponID);
4963+
arguments.PushNumber(ucAmmo);
4964+
arguments.PushNumber(ucWeaponSlot);
4965+
4966+
bool bTake = true;
4967+
if (IS_PLAYER(pElement))
4968+
{
4969+
if (!pPed->CallEvent("onPlayerWeaponTaken", arguments))
4970+
bTake = false;
4971+
}
4972+
else
4973+
{
4974+
if (!pPed->CallEvent("onPedWeaponTaken", arguments))
4975+
bTake = false;
4976+
}
4977+
4978+
if (bTake)
4979+
{
4980+
CBitStream BitStream;
4981+
SWeaponTypeSync weaponType;
4982+
weaponType.data.ucWeaponType = ucWeaponID;
4983+
BitStream.pBitStream->Write(&weaponType);
4984+
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, TAKE_WEAPON, *BitStream.pBitStream));
4985+
4986+
pPed->SetWeaponType(0, ucWeaponSlot);
4987+
pPed->SetWeaponAmmoInClip(0, ucWeaponSlot);
4988+
pPed->SetWeaponTotalAmmo(0, ucWeaponSlot);
4989+
}
4990+
}
49394991
}
49404992

49414993
return true;

0 commit comments

Comments
 (0)