From 272a1d844c66d191814b6d5a4f10147fc6d64acc Mon Sep 17 00:00:00 2001 From: Nikita Obrekht Date: Fri, 19 Jun 2020 22:46:13 +0200 Subject: [PATCH 1/2] Add isPedReloadingWeapon function to server --- Client/mods/deathmatch/logic/CNetAPI.cpp | 1 + Server/mods/deathmatch/logic/CPed.h | 4 ++++ Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp | 9 +++++++++ Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h | 2 ++ .../deathmatch/logic/packets/CPlayerPuresyncPacket.cpp | 2 ++ Shared/sdk/net/SyncStructures.h | 3 ++- 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CNetAPI.cpp b/Client/mods/deathmatch/logic/CNetAPI.cpp index 1ecc70cd88..c9038e176e 100644 --- a/Client/mods/deathmatch/logic/CNetAPI.cpp +++ b/Client/mods/deathmatch/logic/CNetAPI.cpp @@ -1104,6 +1104,7 @@ void CNetAPI::WritePlayerPuresync(CClientPlayer* pPlayerModel, NetBitStreamInter flags.data.bHasAWeapon = (pPlayerWeapon != NULL); flags.data.bSyncingVelocity = (!flags.data.bIsOnGround || (pPlayerModel->GetPlayerSyncCount() % 4) == 0); flags.data.bStealthAiming = (pPlayerModel->IsStealthAiming() == true); + flags.data.bReloadingWeapon = (pPlayerModel->IsReloadingWeapon() == true); if (pPlayerWeapon->GetSlot() > 15) flags.data.bHasAWeapon = false; diff --git a/Server/mods/deathmatch/logic/CPed.h b/Server/mods/deathmatch/logic/CPed.h index 0a1e0bbe35..55d38b2919 100644 --- a/Server/mods/deathmatch/logic/CPed.h +++ b/Server/mods/deathmatch/logic/CPed.h @@ -169,6 +169,9 @@ class CPed : public CElement unsigned short GetWeaponTotalAmmo(unsigned char ucSlot = 0xFF); void SetWeaponTotalAmmo(unsigned short usTotalAmmo, unsigned char ucSlot = 0xFF); + bool IsReloadingWeapon() { return m_bReloadingWeapon; }; + void SetReloadingWeapon(bool bReloadingWeapon) { m_bReloadingWeapon = bReloadingWeapon; }; + float GetMaxHealth(); float GetHealth() { return m_fHealth; } void SetHealth(float fHealth) { m_fHealth = fHealth; } @@ -302,6 +305,7 @@ class CPed : public CElement bool m_bHeadless; bool m_bFrozen; bool m_bStealthAiming; + bool m_bReloadingWeapon; CVehicle* m_pVehicle; unsigned int m_uiVehicleSeat; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 47f1f0a73b..5cd0f25c35 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -10,6 +10,7 @@ *****************************************************************************/ #include "StdInc.h" +#include "lua/CLuaFunctionParser.h" void CLuaPedDefs::LoadFunctions() { @@ -75,6 +76,7 @@ void CLuaPedDefs::LoadFunctions() {"takeAllWeapons", TakeAllWeapons}, {"giveWeaponAmmo", GiveWeapon}, {"takeWeaponAmmo", TakeWeapon}, + {"isPedReloadingWeapon", ArgumentParser}, }; // Add functions @@ -114,6 +116,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"); @@ -165,6 +168,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"); @@ -1613,3 +1617,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 04f0912d66..fb7af43123 100644 --- a/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp @@ -51,6 +51,7 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream) pSourcePlayer->SetAkimboArmUp(flags.data.bAkimboTargetUp); pSourcePlayer->SetOnFire(flags.data.bIsOnFire); pSourcePlayer->SetStealthAiming(flags.data.bStealthAiming); + pSourcePlayer->SetReloadingWeapon(flags.data.bReloadingWeapon); // Contact element CElement* pContactElement = NULL; @@ -298,6 +299,7 @@ bool CPlayerPuresyncPacket::Write(NetBitStreamInterface& BitStream) const flags.data.bHasAWeapon = (ucWeaponSlot != 0); flags.data.bSyncingVelocity = (!flags.data.bIsOnGround || pSourcePlayer->IsSyncingVelocity()); flags.data.bStealthAiming = (pSourcePlayer->IsStealthAiming() == true); + flags.data.bReloadingWeapon = (pSourcePlayer->IsReloadingWeapon() == true); CVector vecPosition = pSourcePlayer->GetPosition(); if (pContactElement) diff --git a/Shared/sdk/net/SyncStructures.h b/Shared/sdk/net/SyncStructures.h index ec4ea35385..a5150793cf 100644 --- a/Shared/sdk/net/SyncStructures.h +++ b/Shared/sdk/net/SyncStructures.h @@ -535,7 +535,7 @@ struct SPlayerPuresyncFlags : public ISyncStructure { enum { - BITCOUNT = 12 + BITCOUNT = 13 }; bool Read(NetBitStreamInterface& bitStream) { return bitStream.ReadBits((char*)&data, BITCOUNT); } @@ -555,6 +555,7 @@ struct SPlayerPuresyncFlags : public ISyncStructure bool bHasAWeapon : 1; bool bSyncingVelocity : 1; bool bStealthAiming : 1; + bool bReloadingWeapon : 1; } data; }; From fd2a51c4c2d2c9cd09f36f901334c2420682664c Mon Sep 17 00:00:00 2001 From: Nikita Obrekht Date: Fri, 19 Jun 2020 23:23:21 +0200 Subject: [PATCH 2/2] Set reloading weapon state when using reloadPedWeapon --- Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 5d12cd3439..5a99a7c963 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4382,8 +4382,10 @@ bool CStaticFunctionDefinitions::reloadPedWeapon(CElement* pElement) if (IS_PED(pElement)) { - CPed* pPed = static_cast(pElement); CBitStream BitStream; + CPed* pPed = static_cast(pElement); + pPed->SetReloadingWeapon(true); + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, RELOAD_PED_WEAPON, *BitStream.pBitStream)); return true; }