20.03.2012, 21:00
Would looping through all players checking if they are in a car and getting their car id, then ejecting them from the car if the health is lower then 450 cause lag? would it be better to set a 1 s timer?
public OnGameModeInit()
{
SetTimer("PlayersCheck", 1000, true);
return 1;
}
forward PlayersCheck();
public PlayersCheck()
{
for(new i = 0; i <= GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i))
{
if(isPlayerInAnyVehicle(i))
{
new vid, FLoat:vhealth;
vid = GetPlayerVehicleID(i);
GetVehicleHealth(vid, vhealth);
if(vhealth < 450)
{
RemovePlayerFromVehicle(i);
}
}
}
}
}
Can't believe I didn't think of this, lol. Why don't you just use OnPlayerStateChange and use
pawn Код:
|
public PlayersCheck()
{
for(new i = 0, j = GetPlayerPoolSize(), Float:vhealth; i <= j; i++)
{
if(GetVehicleHealth(GetPlayerVehicleID(i), vhealth))
{
if(vhealth < 450)
{
RemovePlayerFromVehicle(i);
}
}
}
}
Much more optimized version without all the redundant checks:
PHP код:
|