Skip to content

Commit b7f1468

Browse files
ArranTunaJusonex
authored andcommitted
setPedStat for client side peds (#109)
* setPedStat for client side peds * setPedStat client support propagation * Optimized setPedStat
1 parent 6343316 commit b7f1468

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,22 @@ bool CStaticFunctionDefinitions::SetPedAimTarget ( CClientEntity & Entity, CVect
23412341
return false;
23422342
}
23432343

2344+
bool CStaticFunctionDefinitions::SetPedStat ( CClientEntity & Entity, ushort usStat, float fValue )
2345+
{
2346+
RUN_CHILDREN ( SetPedStat ( **iter, usStat, fValue ) )
2347+
if ( IS_PED ( &Entity ) && Entity.IsLocalEntity ( ) )
2348+
{
2349+
CClientPed& Ped = static_cast < CClientPed& > ( Entity );
2350+
// Dont let them set visual stats if they don't have the CJ model
2351+
if ( ( usStat == 21 /* FAT */ || usStat == 23 /* BODY_MUSCLE */ ) && Ped.GetModel ( ) != 0 )
2352+
return false;
2353+
2354+
Ped.SetStat ( usStat, fValue );
2355+
return true;
2356+
}
2357+
return false;
2358+
}
2359+
23442360

23452361
bool CStaticFunctionDefinitions::SetPedOnFire ( CClientEntity & Entity, bool bOnFire )
23462362
{

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class CStaticFunctionDefinitions
188188
static bool SetPedFootBloodEnabled ( CClientEntity& Entity, bool bHasFootBlood );
189189
static bool SetPedCameraRotation ( CClientEntity& Entity, float fRotation );
190190
static bool SetPedAimTarget ( CClientEntity& Entity, CVector & vecTarget );
191+
static bool SetPedStat ( CClientEntity& Entity, ushort usStat, float fValue );
191192
static bool SetPedOnFire ( CClientEntity& Entity, bool bOnFire );
192193
static bool RemovePedFromVehicle ( CClientPed* pPed );
193194
static bool WarpPedIntoVehicle ( CClientPed* pPed, CClientVehicle* pVehicle, unsigned int uiSeat );

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void CLuaPedDefs::LoadFunctions ( void ) {
7777
CLuaCFunctions::AddFunction ( "setPedFootBloodEnabled", SetPedFootBloodEnabled );
7878
CLuaCFunctions::AddFunction ( "setPedCameraRotation", SetPedCameraRotation );
7979
CLuaCFunctions::AddFunction ( "setPedAimTarget", SetPedAimTarget );
80+
CLuaCFunctions::AddFunction ( "setPedStat", SetPedStat );
8081
CLuaCFunctions::AddFunction ( "warpPedIntoVehicle", WarpPedIntoVehicle );
8182
CLuaCFunctions::AddFunction ( "removePedFromVehicle", RemovePedFromVehicle );
8283
CLuaCFunctions::AddFunction ( "setPedOxygenLevel", SetPedOxygenLevel );
@@ -159,6 +160,7 @@ void CLuaPedDefs::AddClass ( lua_State* luaVM )
159160
lua_classfunction ( luaVM, "setAimTarget", "setPedAimTarget" );
160161
lua_classfunction ( luaVM, "setLookAt", "setPedLookAt" );
161162
lua_classfunction ( luaVM, "setWalkingStyle", "setPedWalkingStyle" );
163+
lua_classfunction ( luaVM, "setStat", "setPedStat" );
162164
lua_classfunction ( luaVM, "giveWeapon", "givePedWeapon" );
163165

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

18091811

1812+
int CLuaPedDefs::SetPedStat ( lua_State* luaVM )
1813+
{
1814+
// Verify the argument
1815+
CClientEntity* pEntity = NULL;
1816+
unsigned short usStat = 0;
1817+
float fValue = 0;
1818+
CScriptArgReader argStream ( luaVM );
1819+
argStream.ReadUserData ( pEntity );
1820+
argStream.ReadNumber ( usStat );
1821+
argStream.ReadNumber ( fValue );
1822+
1823+
if ( !argStream.HasErrors ( ) )
1824+
{
1825+
// Check the stat and value
1826+
if ( usStat > NUM_PLAYER_STATS - 1 || fValue < 0.0f || fValue > 1000.0f )
1827+
argStream.SetCustomError ( "Stat must be 0 to 342 and value must be 0 to 1000." );
1828+
else if ( CStaticFunctionDefinitions::SetPedStat ( *pEntity, usStat, fValue ) )
1829+
{
1830+
lua_pushboolean ( luaVM, true );
1831+
return 1;
1832+
}
1833+
}
1834+
1835+
if ( argStream.HasErrors ( ) )
1836+
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage ( ) );
1837+
1838+
// Failed
1839+
lua_pushboolean ( luaVM, false );
1840+
return 1;
1841+
}
1842+
1843+
18101844
int CLuaPedDefs::KillPed ( lua_State* luaVM )
18111845
{
18121846
CClientEntity* pEntity = NULL;

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ class CLuaPedDefs : public CLuaDefs
8888
LUA_DECLARE_OOP ( WarpPedIntoVehicle );
8989
LUA_DECLARE ( RemovePedFromVehicle );
9090
LUA_DECLARE ( SetPedOxygenLevel );
91+
LUA_DECLARE ( SetPedStat );
9192
};

0 commit comments

Comments
 (0)