Skip to content

Commit

Permalink
Add server side projectile events (#3241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zangomangu authored Nov 14, 2023
1 parent ce85d25 commit bc40402
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
30 changes: 30 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,8 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerNetworkStatus", "type, ticks", NULL, false);
m_Events.AddEvent("onPlayerScreenShot", "resource, status, file_data, timestamp, tag", NULL, false);
m_Events.AddEvent("onPlayerResourceStart", "resource", NULL, false);
m_Events.AddEvent("onPlayerProjectileCreation", "weaponType, posX, posY, posZ, force, target, rotX, rotY, rotZ, velX, velY, velZ", nullptr, false);
m_Events.AddEvent("onPlayerDetonateSatchels", "", nullptr, false);

// Ped events
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
Expand Down Expand Up @@ -2624,6 +2626,11 @@ void CGame::Packet_DetonateSatchels(CDetonateSatchelsPacket& Packet)
CPlayer* pPlayer = Packet.GetSourcePlayer();
if (pPlayer && pPlayer->IsJoined())
{
// Trigger Lua event and see if we are allowed to continue
CLuaArguments arguments;
if (!pPlayer->CallEvent("onPlayerDetonateSatchels", arguments))
return;

// Tell everyone to blow up this guy's satchels
m_pPlayerManager->BroadcastOnlyJoined(Packet);
// Take away their detonator
Expand Down Expand Up @@ -2777,6 +2784,29 @@ void CGame::Packet_ProjectileSync(CProjectileSyncPacket& Packet)
vecPosition += pOriginSource->GetPosition();
}

CLuaArguments arguments;
arguments.PushNumber(Packet.m_ucWeaponType); // "weaponType"
arguments.PushNumber(vecPosition.fX); // "posX"
arguments.PushNumber(vecPosition.fY); // "posY"
arguments.PushNumber(vecPosition.fZ); // "posZ"
arguments.PushNumber(Packet.m_fForce); // "force"

CElement* pTarget = nullptr;
if (Packet.m_bHasTarget && Packet.m_TargetID != INVALID_ELEMENT_ID)
pTarget = CElementIDs::GetElement(Packet.m_TargetID);

arguments.PushElement(pTarget); // "target"
arguments.PushNumber(Packet.m_vecRotation.fX); // "rotX"
arguments.PushNumber(Packet.m_vecRotation.fY); // "rotY"
arguments.PushNumber(Packet.m_vecRotation.fZ); // "rotZ"
arguments.PushNumber(Packet.m_vecMoveSpeed.fX); // "velX"
arguments.PushNumber(Packet.m_vecMoveSpeed.fY); // "velY"
arguments.PushNumber(Packet.m_vecMoveSpeed.fZ); // "velZ"

// Trigger Lua event and see if we are allowed to continue
if (!pPlayer->CallEvent("onPlayerProjectileCreation", arguments))
return;

// Make a list of players to send this packet to
CSendList sendList;

Expand Down
5 changes: 5 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,11 @@ bool CStaticFunctionDefinitions::DetonateSatchels(CElement* pElement)
CPlayer* pPlayer = static_cast<CPlayer*>(pElement);
if (pPlayer->IsJoined())
{
// Trigger Lua event and see if we are allowed to continue
CLuaArguments arguments;
if (!pPlayer->CallEvent("onPlayerDetonateSatchels", arguments))
return false;

CDetonateSatchelsPacket Packet;
Packet.SetSourceElement(pPlayer);
m_pPlayerManager->BroadcastOnlyJoined(Packet);
Expand Down
17 changes: 5 additions & 12 deletions Server/mods/deathmatch/logic/packets/CProjectileSyncPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ bool CProjectileSyncPacket::Read(NetBitStreamInterface& BitStream)
return false;
m_ucWeaponType = weaponType.data.ucWeaponType;

if (BitStream.Version() >= 0x4F)
{
if (!BitStream.Read(m_usModel))
return false;
}
if (!BitStream.Read(m_usModel))
return false;

switch (m_ucWeaponType)
{
Expand All @@ -67,12 +64,11 @@ bool CProjectileSyncPacket::Read(NetBitStreamInterface& BitStream)
case 19: // WEAPONTYPE_ROCKET
case 20: // WEAPONTYPE_ROCKET_HS
{
bool bHasTarget;
if (!BitStream.ReadBit(bHasTarget))
if (!BitStream.ReadBit(m_bHasTarget))
return false;

m_TargetID = INVALID_ELEMENT_ID;
if (bHasTarget && !BitStream.Read(m_TargetID))
if (m_bHasTarget && !BitStream.Read(m_TargetID))
return false;

SVelocitySync velocity;
Expand Down Expand Up @@ -127,10 +123,7 @@ bool CProjectileSyncPacket::Write(NetBitStreamInterface& BitStream) const
weaponType.data.ucWeaponType = m_ucWeaponType;
BitStream.Write(&weaponType);

if (BitStream.Version() >= 0x4F)
{
BitStream.Write(m_usModel);
}
BitStream.Write(m_usModel);

switch (m_ucWeaponType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CProjectileSyncPacket final : public CPacket
ElementID m_OriginID;
CVector m_vecOrigin;
float m_fForce;
unsigned char m_ucHasTarget;
bool m_bHasTarget;
ElementID m_TargetID;
CVector m_vecTarget;
CVector m_vecRotation;
Expand Down

0 comments on commit bc40402

Please sign in to comment.