diff --git a/Client/mods/deathmatch/logic/CNetAPI.cpp b/Client/mods/deathmatch/logic/CNetAPI.cpp index ecb16fd1ac..7d029765e2 100644 --- a/Client/mods/deathmatch/logic/CNetAPI.cpp +++ b/Client/mods/deathmatch/logic/CNetAPI.cpp @@ -1118,6 +1118,8 @@ void CNetAPI::WritePlayerPuresync(CClientPlayer* pPlayerModel, NetBitStreamInter flags.data.bSyncingVelocity = (!flags.data.bIsOnGround || (pPlayerModel->GetPlayerSyncCount() % 4) == 0); flags.data.bStealthAiming = (pPlayerModel->IsStealthAiming() == true); + flags.data2.bIsReloadingWeapon = (pPlayerModel->IsReloadingWeapon() == true); + if (pPlayerWeapon->GetSlot() > 15) flags.data.bHasAWeapon = false; diff --git a/Server/mods/deathmatch/logic/CPed.cpp b/Server/mods/deathmatch/logic/CPed.cpp index e3b7e0128c..69a7f6bf9b 100644 --- a/Server/mods/deathmatch/logic/CPed.cpp +++ b/Server/mods/deathmatch/logic/CPed.cpp @@ -68,6 +68,7 @@ CPed::CPed(CPedManager* pPedManager, CElement* pParent, unsigned short usModel) m_fGravity = 0.008f; m_bDoingGangDriveby = false; m_bStealthAiming = false; + m_bReloadingWeapon = false; m_pVehicle = NULL; m_uiVehicleSeat = INVALID_VEHICLE_SEAT; diff --git a/Server/mods/deathmatch/logic/CPed.h b/Server/mods/deathmatch/logic/CPed.h index 47e70e7189..8eef599f72 100644 --- a/Server/mods/deathmatch/logic/CPed.h +++ b/Server/mods/deathmatch/logic/CPed.h @@ -269,6 +269,9 @@ class CPed : public CElement bool GetCollisionEnabled() { return m_bCollisionsEnabled; } void SetCollisionEnabled(bool bCollisionEnabled) { m_bCollisionsEnabled = bCollisionEnabled; } + bool IsReloadingWeapon() const { return m_bReloadingWeapon; } + void SetReloadingWeapon(bool bState) { m_bReloadingWeapon = bState; } + long long GetLastFarSyncTick() { return m_llLastFarSyncTick; } void SetLastFarSyncTick(long long llLastSyncTick) { m_llLastFarSyncTick = llLastSyncTick; } @@ -316,6 +319,7 @@ class CPed : public CElement bool m_bFrozen; bool m_bStealthAiming; CVehicle* m_pJackingVehicle; + bool m_bReloadingWeapon; CVehicle* m_pVehicle; unsigned int m_uiVehicleSeat; diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 0542dce5fd..b6ffea2702 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4473,6 +4473,9 @@ bool CStaticFunctionDefinitions::reloadPedWeapon(CElement* pElement) { CPed* pPed = static_cast(pElement); CBitStream BitStream; + + pPed->SetReloadingWeapon(true); + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, RELOAD_PED_WEAPON, *BitStream.pBitStream)); return true; } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 281f81f307..a5bf94077c 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -78,6 +78,7 @@ void CLuaPedDefs::LoadFunctions() {"takeAllWeapons", TakeAllWeapons}, {"giveWeaponAmmo", GiveWeapon}, {"takeWeaponAmmo", TakeWeapon}, + {"isPedReloadingWeapon", ArgumentParser}, }; // Add functions @@ -117,6 +118,7 @@ void CLuaPedDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "isFrozen", "isPedFrozen"); lua_classfunction(luaVM, "isHeadless", "isPedHeadless"); lua_classfunction(luaVM, "isWearingJetpack", "isPedWearingJetpack"); // introduced in 1.5.5-9.13846 + lua_classfunction(luaVM, "isReloadingWeapon", "isPedReloadingWeapon"); lua_classfunction(luaVM, "getArmor", "getPedArmor"); lua_classfunction(luaVM, "getFightingStyle", "getPedFightingStyle"); @@ -168,6 +170,7 @@ void CLuaPedDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "vehicle", "warpPedIntoVehicle", "getPedOccupiedVehicle", OOP_WarpPedIntoVehicle, GetPedOccupiedVehicle); lua_classvariable(luaVM, "walkingStyle", "setPedWalkingStyle", "getPedWalkingStyle"); lua_classvariable(luaVM, "jetpack", "setPedWearingJetpack", "isPedWearingJetpack"); // introduced in 1.5.5-9.13846 + lua_classvariable(luaVM, "reloadingWeapon", nullptr, "isPedReloadingWeapon"); // TODO(qaisjp): setting this to any value will kill the ped. add OOP_KillPed that only allows `true`. lua_classvariable(luaVM, "dead", "killPed", "isPedDead"); @@ -1617,3 +1620,8 @@ int CLuaPedDefs::TakeAllWeapons(lua_State* luaVM) lua_pushboolean(luaVM, false); return 1; } + +bool CLuaPedDefs::IsPedReloadingWeapon(CPed* const ped) +{ + return ped->IsReloadingWeapon(); +} diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index d458b7a344..e9f361c6ce 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -79,4 +79,6 @@ class CLuaPedDefs : public CLuaDefs LUA_DECLARE(SetPedHeadless); LUA_DECLARE(SetPedFrozen); LUA_DECLARE(reloadPedWeapon); + + static bool IsPedReloadingWeapon(CPed* const ped); }; diff --git a/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp index 54c63e49ff..a2c00a6825 100644 --- a/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp @@ -61,6 +61,8 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream) pSourcePlayer->SetOnFire(flags.data.bIsOnFire); pSourcePlayer->SetStealthAiming(flags.data.bStealthAiming); + pSourcePlayer->SetReloadingWeapon(flags.data2.bIsReloadingWeapon); + // Contact element CElement* pContactElement = NULL; if (flags.data.bHasContact) @@ -314,6 +316,8 @@ bool CPlayerPuresyncPacket::Write(NetBitStreamInterface& BitStream) const flags.data.bSyncingVelocity = (!flags.data.bIsOnGround || pSourcePlayer->IsSyncingVelocity()); flags.data.bStealthAiming = (pSourcePlayer->IsStealthAiming() == true); + flags.data2.bIsReloadingWeapon = (pSourcePlayer->IsReloadingWeapon() == true); + CVector vecPosition = pSourcePlayer->GetPosition(); if (pContactElement) pSourcePlayer->GetContactPosition(vecPosition); diff --git a/Shared/sdk/net/SyncStructures.h b/Shared/sdk/net/SyncStructures.h index 28c8770fc7..0267b4a672 100644 --- a/Shared/sdk/net/SyncStructures.h +++ b/Shared/sdk/net/SyncStructures.h @@ -547,8 +547,29 @@ struct SPlayerPuresyncFlags : public ISyncStructure BITCOUNT = 12 }; - bool Read(NetBitStreamInterface& bitStream) { return bitStream.ReadBits((char*)&data, BITCOUNT); } - void Write(NetBitStreamInterface& bitStream) const { bitStream.WriteBits((const char*)&data, BITCOUNT); } + enum + { + BITCOUNT2 = 1 + }; + + bool Read(NetBitStreamInterface& bitStream) + { + bool bOk = bitStream.ReadBits((char*)&data, BITCOUNT); + + if (bitStream.Can(eBitStreamVersion::CPed_isReloadingWeapon)) + bOk &= bitStream.ReadBits((char*)&data2, BITCOUNT2); + else + data2.bIsReloadingWeapon = 0; + + return bOk; + } + void Write(NetBitStreamInterface& bitStream) const + { + bitStream.WriteBits((const char*)&data, BITCOUNT); + + if (bitStream.Can(eBitStreamVersion::CPed_isReloadingWeapon)) + bitStream.WriteBits((const char*)&data2, BITCOUNT2); + } struct { @@ -565,6 +586,12 @@ struct SPlayerPuresyncFlags : public ISyncStructure bool bSyncingVelocity : 1; bool bStealthAiming : 1; } data; + + // Add new ones in separate structs + struct + { + bool bIsReloadingWeapon : 1; + } data2; }; struct SPedRotationSync : public ISyncStructure diff --git a/Shared/sdk/net/bitstream.h b/Shared/sdk/net/bitstream.h index 3924ebbf16..d6a7c38cdb 100644 --- a/Shared/sdk/net/bitstream.h +++ b/Shared/sdk/net/bitstream.h @@ -540,6 +540,10 @@ enum class eBitStreamVersion : unsigned short // 2023-10-12 CPlayerJoinCompletePacket_ServerName, + // Add serverside isPedReloadingWeapon + // 2024-01-16 + CPed_isReloadingWeapon, + // This allows us to automatically increment the BitStreamVersion when things are added to this enum. // Make sure you only add things above this comment. Next,