Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setPedStat for client side peds #106

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 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 @@ -2077,6 +2079,50 @@ int CLuaPedDefs::SetPedAimTarget ( lua_State* luaVM )
}


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

if ( !argStream.HasErrors () )
{
// Only allow on local peds
if ( !pPed->IsLocalEntity ( ) )
argStream.SetCustomError ( "This client side function will only work with client created peds." );

// Check the stat and value
if ( !argStream.HasErrors ( ) )
if ( usStat > NUM_PLAYER_STATS || usStat < 0 || fValue < 0.0f || fValue > 1000.0f )
argStream.SetCustomError ( "Stat must be 0 to 343 and value must be 0 to 1000." );

// Dont let them set visual stats if they don't have the CJ model
if ( !argStream.HasErrors ( ) )
if ( ( usStat == 21 /* FAT */ || usStat == 23 /* BODY_MUSCLE */ ) && pPed->GetModel () != 0 )
argStream.SetCustomError( "Fat and muscle stat can only be set on CJ skin." );

if ( !argStream.HasErrors ( ) )
{
pPed->SetStat ( 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 );
};