Skip to content
Open
25 changes: 20 additions & 5 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,13 @@ bool CStaticFunctionDefinitions::SetElementPosition(CClientEntity& Entity, const
{
RUN_CHILDREN(SetElementPosition(**iter, vecPosition))

if (Entity.GetType() == CCLIENTVEHICLE)
{
CClientPed* driver = static_cast<CClientVehicle&>(Entity).GetOccupant(0);
if (!Entity.IsLocalEntity() && !static_cast<CDeathmatchVehicle&>(Entity).IsSyncing() && (!driver || !driver->IsLocalPlayer()))
return false;
}

if (bWarp)
Entity.Teleport(vecPosition);
else
Expand Down Expand Up @@ -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())
{
Expand All @@ -1490,6 +1497,11 @@ bool CStaticFunctionDefinitions::SetElementHealth(CClientEntity& Entity, float f
{
// Grab the model
CClientPed& Ped = static_cast<CClientPed&>(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
Expand Down Expand Up @@ -2905,7 +2917,6 @@ bool CStaticFunctionDefinitions::BlowVehicle(CClientEntity& Entity, std::optiona

CClientVehicle& vehicle = static_cast<CClientVehicle&>(Entity);
VehicleBlowFlags blow;

blow.withExplosion = withExplosion.value_or(true);

if (vehicle.IsLocalEntity())
Expand All @@ -2914,11 +2925,15 @@ bool CStaticFunctionDefinitions::BlowVehicle(CClientEntity& Entity, std::optiona
}
else
{
CClientPed* driver = vehicle.GetOccupant(0);
if (!static_cast<CDeathmatchVehicle&>(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)
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading