Hello, can anyone optimize this code ? cause server get laggy after 10~ rounds.
PHP Code:
new g_topEnt[ 33 ];
new MODEL_1[ ] = "models/1.mdl";
new MODEL_2[ ] = "models/2.mdl";
public CheckPlayerRank( id )
{
new stats[ 8 ], bodyhits[ 8 ];
new iRank;
iRank = get_user_stats( id, stats, bodyhits );
if ( iRank && 5 <= iRank <= 10 )
GiveHat( id, MODEL_1 );
else if ( iRank && 11 <= iRank <= 20 )
GiveHat( id, MODEL_2 );
return PLUGIN_CONTINUE;
}
public GiveHat( id, const s_Model[ ] )
{
if ( is_user_alive( id ) )
{
new iEnt = g_topEnt[ id ];
if ( !pev_valid( iEnt ) )
{
iEnt = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
set_pev( iEnt, pev_movetype, MOVETYPE_FOLLOW );
set_pev( iEnt, pev_aiment, id );
engfunc( EngFunc_SetModel, iEnt, s_Model );
}
else
engfunc( EngFunc_RemoveEntity, iEnt );
}
}
public client_infochanged( id )
{
new player_name[ 32 ], newName[ 32 ];
get_user_name( id, player_name, 31 );
get_user_info( id, "name", newName, 31 );
if ( !equali( newName, player_name ) )
set_task( 1.0, "CheckPlayerRank", id );
}
__________________