Low Health 20% > Injured.
#10

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 )
Reply


Messages In This Thread
Low Health 20% > Injured. - by Uberanwar - 10.10.2013, 00:42
Re: Low Health 20% > Injured. - by xVIP3Rx - 10.10.2013, 00:46
Re: Low Health 20% > Injured. - by EiresJason - 10.10.2013, 00:51
Re: Low Health 20% > Injured. - by Uberanwar - 10.10.2013, 00:53
Re: Low Health 20% > Injured. - by EiresJason - 10.10.2013, 00:56
Re: Low Health 20% > Injured. - by xVIP3Rx - 10.10.2013, 00:56
Re: Low Health 20% > Injured. - by Sublime - 10.10.2013, 00:57
Re: Low Health 20% > Injured. - by EiresJason - 10.10.2013, 01:04
Re: Low Health 20% > Injured. - by Uberanwar - 10.10.2013, 01:07
Re: Low Health 20% > Injured. - by Pottus - 10.10.2013, 01:21

Forum Jump:


Users browsing this thread: 6 Guest(s)