Quote:
Originally Posted by EiresJason
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid) { new Float:hp; GetPlayerHealth(playerid,hp); if(hp <= 20) { TogglePlayerControllable (playerid,0); ApplyAnimation(playerid,"CRACK","crckdeth2",4.1,0,1,1,1,1,1); SetTimerEx("MoreThan20HP",1000,true,"i",playerid); } return 1; }
forward MoreThan20HP(playerid); public MoreThan20HP(playerid) { new Float:hp; GetPlayerHealth(playerid,hp);
if(hp >= 21) TogglePlayerControllable (playerid,1);
}
|
That needs a slight modification since GetPlayerHealth() will return the HP before the player was damaged.
pawn Код:
new Float:hp;
GetPlayerHealth(playerid,hp);
hp -= amount;
There is also problems with the new code you provided, for instance the time is not killed from subsequent OnPlayerTakeDamage() which will cause multiple times to run.
I wouldn't use timers like you are instead I would create a timer which loops through all players instead of making a bunch of individual timers that is very sloppy and messy so you would get something like this.
pawn Код:
new Injured[MAX_PLAYERS];
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
if(!Injured[playerid])
{
new Float:hp;
GetPlayerHealth(playerid,hp);
hp -= amount;
if(hp <= 20)
{
TogglePlayerControllable (playerid,0);
ApplyAnimation(playerid,"CRACK","crckdeth2",4.1,0,1,1,1,1,1);
Injured[playerid] = 1;
}
}
return 1;
}
pawn Код:
public OnGameModeInit()
{
SetTimer("InjuredTimer", 4000, true);
return 1;
}
pawn Код:
forward InjuredTimer();
public InjuredTimer()
{
foreach(new i : Player)
{
if(Injured[i])
{
new Float:hp;
GetPlayerHealth(i, hp);
if(hp <= 20.0) SetPlayerHealth(i, hp-1.0);
else
{
TogglePlayerControllable(i,1);
Injured[i] = 0;
}
}
}
}
That is how I would do it (Untested but should work
)