Skip to content

Commit

Permalink
setPedStat for client side peds (#109)
Browse files Browse the repository at this point in the history
* setPedStat for client side peds

* setPedStat client support propagation

* Optimized setPedStat
  • Loading branch information
ArranTuna authored and Jusonex committed May 14, 2017
1 parent 6343316 commit b7f1468
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -2341,6 +2341,22 @@ bool CStaticFunctionDefinitions::SetPedAimTarget ( CClientEntity & Entity, CVect
return false;
}

bool CStaticFunctionDefinitions::SetPedStat ( CClientEntity & Entity, ushort usStat, float fValue )
{
RUN_CHILDREN ( SetPedStat ( **iter, usStat, fValue ) )
if ( IS_PED ( &Entity ) && Entity.IsLocalEntity ( ) )
{
CClientPed& Ped = static_cast < CClientPed& > ( Entity );
// Dont let them set visual stats if they don't have the CJ model
if ( ( usStat == 21 /* FAT */ || usStat == 23 /* BODY_MUSCLE */ ) && Ped.GetModel ( ) != 0 )
return false;

Ped.SetStat ( usStat, fValue );
return true;
}
return false;
}


bool CStaticFunctionDefinitions::SetPedOnFire ( CClientEntity & Entity, bool bOnFire )
{
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -188,6 +188,7 @@ class CStaticFunctionDefinitions
static bool SetPedFootBloodEnabled ( CClientEntity& Entity, bool bHasFootBlood );
static bool SetPedCameraRotation ( CClientEntity& Entity, float fRotation );
static bool SetPedAimTarget ( CClientEntity& Entity, CVector & vecTarget );
static bool SetPedStat ( CClientEntity& Entity, ushort usStat, float fValue );
static bool SetPedOnFire ( CClientEntity& Entity, bool bOnFire );
static bool RemovePedFromVehicle ( CClientPed* pPed );
static bool WarpPedIntoVehicle ( CClientPed* pPed, CClientVehicle* pVehicle, unsigned int uiSeat );
Expand Down
34 changes: 34 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Expand Up @@ -77,6 +77,7 @@ void CLuaPedDefs::LoadFunctions ( void ) {
CLuaCFunctions::AddFunction ( "setPedFootBloodEnabled", SetPedFootBloodEnabled );
CLuaCFunctions::AddFunction ( "setPedCameraRotation", SetPedCameraRotation );
CLuaCFunctions::AddFunction ( "setPedAimTarget", SetPedAimTarget );
CLuaCFunctions::AddFunction ( "setPedStat", SetPedStat );
CLuaCFunctions::AddFunction ( "warpPedIntoVehicle", WarpPedIntoVehicle );
CLuaCFunctions::AddFunction ( "removePedFromVehicle", RemovePedFromVehicle );
CLuaCFunctions::AddFunction ( "setPedOxygenLevel", SetPedOxygenLevel );
Expand Down Expand Up @@ -159,6 +160,7 @@ void CLuaPedDefs::AddClass ( lua_State* luaVM )
lua_classfunction ( luaVM, "setAimTarget", "setPedAimTarget" );
lua_classfunction ( luaVM, "setLookAt", "setPedLookAt" );
lua_classfunction ( luaVM, "setWalkingStyle", "setPedWalkingStyle" );
lua_classfunction ( luaVM, "setStat", "setPedStat" );
lua_classfunction ( luaVM, "giveWeapon", "givePedWeapon" );

lua_classvariable ( luaVM, "vehicle", OOP_WarpPedIntoVehicle, GetPedOccupiedVehicle );
Expand Down Expand Up @@ -1807,6 +1809,38 @@ int CLuaPedDefs::SetPedAimTarget ( lua_State* luaVM )
}


int CLuaPedDefs::SetPedStat ( lua_State* luaVM )
{
// Verify the argument
CClientEntity* pEntity = NULL;
unsigned short usStat = 0;
float fValue = 0;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pEntity );
argStream.ReadNumber ( usStat );
argStream.ReadNumber ( fValue );

if ( !argStream.HasErrors ( ) )
{
// Check the stat and value
if ( usStat > NUM_PLAYER_STATS - 1 || fValue < 0.0f || fValue > 1000.0f )
argStream.SetCustomError ( "Stat must be 0 to 342 and value must be 0 to 1000." );
else if ( CStaticFunctionDefinitions::SetPedStat ( *pEntity, usStat, fValue ) )
{
lua_pushboolean ( luaVM, true );
return 1;
}
}

if ( argStream.HasErrors ( ) )
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage ( ) );

// Failed
lua_pushboolean ( luaVM, false );
return 1;
}


int CLuaPedDefs::KillPed ( lua_State* luaVM )
{
CClientEntity* pEntity = NULL;
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h
Expand Up @@ -88,4 +88,5 @@ class CLuaPedDefs : public CLuaDefs
LUA_DECLARE_OOP ( WarpPedIntoVehicle );
LUA_DECLARE ( RemovePedFromVehicle );
LUA_DECLARE ( SetPedOxygenLevel );
LUA_DECLARE ( SetPedStat );
};

0 comments on commit b7f1468

Please sign in to comment.