Skip to content
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,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, weaponAmmo, weaponSlot", nullptr, false);
m_Events.AddEvent("onPlayerWeaponTaken", "weaponID, weaponAmmo, weaponSlot", nullptr, false);

// Ped events
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
Expand All @@ -1663,6 +1665,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, weaponAmmo, weaponSlot", nullptr, false);
m_Events.AddEvent("onPedWeaponTaken", "weaponID, weaponAmmo, weaponSlot", nullptr, false);

// Element events
m_Events.AddEvent("onElementColShapeHit", "colshape, matchingDimension", NULL, false);
Expand Down
50 changes: 43 additions & 7 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -4821,8 +4830,8 @@ bool CStaticFunctionDefinitions::GiveWeapon(CElement* pElement, unsigned char uc
bSetAsCurrent = false;
}

unsigned char ucWeaponSlot = CWeaponNames::GetSlotFromWeapon(ucWeaponID);
unsigned char ucPreviousWeaponID = pPed->GetWeaponType(ucWeaponSlot);

pPed->SetWeaponType(ucWeaponID, ucWeaponSlot);
if (bSetAsCurrent)
pPed->SetWeaponSlot(ucWeaponSlot);
Expand Down Expand Up @@ -4876,8 +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)
{
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);
Expand Down Expand Up @@ -4928,14 +4943,35 @@ bool CStaticFunctionDefinitions::TakeAllWeapons(CElement* pElement)
CPed* pPed = static_cast<CPed*>(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 shouldTake = true;
if (!pPed->CallEvent(IS_PLAYER(pElement) ? "onPlayerWeaponTaken" : "onPedWeaponTaken", arguments))
shouldTake = false;

if (shouldTake)
{
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;
Expand Down
Loading