22.04.2011, 15:09
PHP код:
public OnPlayerUpdate(playerid)
{
new Float:H;
GetPlayerHealth(playerid,H);
if(H<99)
{
SetPlayerHealth(playerid,100);
return 1;
}
if(IsPlayerConnected(playerid))
{
GetVehicleHealth(GetPlayerVehicleID(playerid), H);
if(H < 1000)
{
SetVehicleHealth(GetPlayerVehicleID(playerid),1000);
}
}
return 1;
}
I should notice though, this is some very bad scripting for the following reasons:
1. You use OnPlayerUpdate to fix cars and heal players, and at 99% health
![Huh?](images/smilies/confused.gif)
2. You do a loop through all players in OPU? Why? Its already checking for all players seperate.
You should read up on pawno a little more, this snippet was awfully inefficient, it would work but your server would lagg if you ever got a little more people on.
EDIT: Here's a more efficient code that works just as good but doesn't require nearly as much CPU.
PHP код:
new healtimer[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
healtimer[playerid] = SetTimerEx("HealTimer", 1000/* Time in milliseconds*/, 1/*repeating*/, "%d", playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(healtimer[playerid]);
return 1;
}
forward HealTimer(playerid);
public HealTimer(playerid);
{
if(IsPlayerConnected(playerid))
{
new Float:H;
GetPlayerHealth(playerid,H);
if(H<90) SetPlayerHealth(playerid,100);
GetVehicleHealth(GetPlayerVehicleID(playerid), H);
if(H<900) SetVehicleHealth(GetPlayerVehicleID(playerid),1000);
}
return 1;
}