diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 0b3fae16e9..f387de9451 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1068,6 +1068,13 @@ bool CStaticFunctionDefinitions::SetElementPosition(CClientEntity& Entity, const { RUN_CHILDREN(SetElementPosition(**iter, vecPosition)) + if (Entity.GetType() == CCLIENTVEHICLE) + { + CClientPed* driver = static_cast(Entity).GetOccupant(0); + if (!Entity.IsLocalEntity() && !static_cast(Entity).IsSyncing() && (!driver || !driver->IsLocalPlayer())) + return false; + } + if (bWarp) Entity.Teleport(vecPosition); else @@ -1479,9 +1486,9 @@ bool CStaticFunctionDefinitions::SetElementAlpha(CClientEntity& Entity, unsigned return true; } -bool CStaticFunctionDefinitions::SetElementHealth(CClientEntity& Entity, float fHealth) +bool CStaticFunctionDefinitions::SetElementHealth(lua_State* luaState, CClientEntity& Entity, float fHealth) { - RUN_CHILDREN(SetElementHealth(**iter, fHealth)) + RUN_CHILDREN(SetElementHealth(luaState, **iter, fHealth)) switch (Entity.GetType()) { @@ -1490,6 +1497,11 @@ bool CStaticFunctionDefinitions::SetElementHealth(CClientEntity& Entity, float f { // Grab the model CClientPed& Ped = static_cast(Entity); + if (Ped.IsLocalPlayer()) + { + g_pClientGame->GetScriptDebugging()->LogWarning(luaState, "The client-side setElementHealth function for localPlayer is deprecated. Use the corresponding server-side function instead"); + return false; + } // If setting health to 0 for local player, clear stale damage data // and set proper scripted death parameters for DoWastedCheck @@ -2905,7 +2917,6 @@ bool CStaticFunctionDefinitions::BlowVehicle(CClientEntity& Entity, std::optiona CClientVehicle& vehicle = static_cast(Entity); VehicleBlowFlags blow; - blow.withExplosion = withExplosion.value_or(true); if (vehicle.IsLocalEntity()) @@ -2914,11 +2925,15 @@ bool CStaticFunctionDefinitions::BlowVehicle(CClientEntity& Entity, std::optiona } else { + CClientPed* driver = vehicle.GetOccupant(0); + if (!static_cast(vehicle).IsSyncing() && (!driver || !driver->IsLocalPlayer())) + return false; + CVector position; vehicle.GetPosition(position); - const auto type = vehicle.GetType(); - const auto state = (blow.withExplosion ? VehicleBlowState::AWAITING_EXPLOSION_SYNC : VehicleBlowState::BLOWN); + const auto type = vehicle.GetType(); + const auto state = (blow.withExplosion ? VehicleBlowState::AWAITING_EXPLOSION_SYNC : VehicleBlowState::BLOWN); eExplosionType explosion; switch (type) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index e1f05f1d10..5ef3845cb3 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -99,7 +99,7 @@ class CStaticFunctionDefinitions static bool DetachElements(CClientEntity& Entity, CClientEntity* pAttachedToEntity = NULL); static bool SetElementAttachedOffsets(CClientEntity& Entity, CVector& vecPosition, CVector& vecRotation); static bool SetElementAlpha(CClientEntity& Entity, unsigned char ucAlpha); - static bool SetElementHealth(CClientEntity& Entity, float fHealth); + static bool SetElementHealth(lua_State* luaState, CClientEntity& Entity, float fHealth); static bool SetElementModel(CClientEntity& Entity, unsigned short usModel); static bool SetElementCollisionsEnabled(CClientEntity& Entity, bool bEnabled); static bool SetElementCollidableWith(CClientEntity& Entity, CClientEntity& ThisEntity, bool bCanCollide); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index c763e1d3f4..cb0f12ce3f 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -2401,7 +2401,7 @@ int CLuaElementDefs::SetElementHealth(lua_State* luaVM) // Verify the arguments if (!argStream.HasErrors()) { - if (CStaticFunctionDefinitions::SetElementHealth(*pEntity, fHealth)) + if (CStaticFunctionDefinitions::SetElementHealth(luaVM, *pEntity, fHealth)) { lua_pushboolean(luaVM, true); return 1; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 68b707d14b..16d96118d0 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -2433,6 +2433,9 @@ bool CLuaPedDefs::SetPedArmor(CClientPed* const ped, const float armor) if (armor > 100.0f) throw std::invalid_argument("Armor must be less than or equal to 100"); + if (ped->IsLocalPlayer()) + throw LuaFunctionError("The client-side setPedArmor function for localPlayer is deprecated. Use the corresponding server-side function instead", true); + ped->SetArmor(armor); return true; }