YOU ARE HURT,GO TO COVER!
#1

Hi all,i wanna make something:

If player has < 20 HP,a gametext will appear saying "YOU ARE HURT,GO TO COVER" and player will lose 5 hp every minute.

I need to do this with GetPlayerHealth?

For now i maked this:

pawn Код:
public OnPlayerUpdate(playerid)
{
    new Float:hp;
    GetPlayerHealth(playerid,hp);
    if (hp < 20.0)
    {
       GameTextForPlayer(playerid, "~g~You are ~r~hurt,go to ~y~cover~n~~h~", 6000, 6);
    }
    return 1;
}
I need only timer to lose hp every minute
Reply
#2

Like this?

pawn Код:
// Somewhere in your script, not in a callback
new
    losehealth;

forward HealthCheck ( );

// OnPlayerConnect
SetTimer ( HealthCheck, 1, true );

// Behind the forward HealthCheck
public HealthCheck ( )
{
    for ( new i; i < MAX_PLAYERS; i ++ ) // You better use foreach
    {
        new
            Float: iHealth;
 
        GetPlayerHealth ( i, iHealth );
        if ( iHealth < 30.0 )
        {
            GameTextForPlayer ( i, "YOU ARE HURT,GO TO COVER", 3000, 3 );
            losehealth = SetTimer ( LoseHP, 60000, true );
        }
    }
    return 1;
}

forward LoseHP ( );
public LoseHP ( )
{
    for ( new i; i < MAX_PLAYERS; i ++ ) // You better use foreach
    {
        new
            Float: zHealth;

       GetPlayerHealth ( i, zHealth );

       if ( zHealth > 0 )
       {
           SetPlayerHealth ( i, zHealth - 5.0 );
       }
       else
       {
           KillTimer ( losehealth );
       }
   }
   return 1;
}
Like that?

* Basicz thinks that code will not work.
Reply
#3

Thanks,i tested it and dont work...
Reply
#4

Sorry, that code I gave also doesn't work for me.
It keeps killing me.
Reply
#5

I'll do it.

pawn Код:
// Top of script:
new LoseHealth[MAX_PLAYERS];

// OnPlayerConnect:
LoseHealth[playerid] = SetTimerEx("healthloss", 60000, 1, "%d", playerid);

// Bottom of script:
forward healthloss(playerid);
public healthloss(playerid)
{
    new Float:hp;
    GetPlayerHealth(playerid, hp);
    if(hp < 30.0 && hp > 0.0)
    {
        GameTextForPlayer(playerid, "~w~You are ~r~hurt~w~, go to ~y~cover", 5000, 5);
        SetPlayerHealth(playerid, hp-5.0);
    }
    return 1;
}
If you ever need to kill the timer, just KillTimer(LoseHealth[playerid]);

This should work.
Reply
#6

I did it :

pawn Код:
//Put in the top of your gamemode:

new checking[MAX_PLAYERS];
new TimerHP;
forward HealthLose();
forward HealthCheck();



//In the OnGameModeInit:

SetTimer("HealthCheck",2000,1);



//In the End of your gamemode:


public HealthCheck()
{
    new Float:hp;
    for(new x=0; x<MAX_PLAYERS; x++)
    {
        if(IsPlayerConnected(x))
        {
            GetPlayerHealth(x,hp);
            if(hp < 20.0)
            {
                GameTextForPlayer(x, "~g~You are ~r~hurt,go to ~y~cover~n~~h~", 6000, 6);
                TimerHP = SetTimerEx("HealthLose", 300000, 0, "i", x);
                checking[x] = 1;
        }   }
    }
}


public HealthLose()
{
    for(new x=0; x<MAX_PLAYERS; x++)
    {
        new Float:Health;
        if(IsPlayerConnected(x))
        {
            if(checking[x] == 1)
            {
                GetPlayerHealth(x,Health);
                SetPlayerHealth(x, Health - 5.0);
                KillTimer(TimerHP);
                checking[x] = 0;
        }   }
    }
}

I hope that i have helped
Reply
#7

Quote:
Originally Posted by rjjj
Посмотреть сообщение
I did it :

pawn Код:
//Put in the top of your gamemode:

new checking[MAX_PLAYERS];
new TimerHP;
forward HealthLose();
forward HealthCheck();



//In the OnGameModeInit:

SetTimer("HealthCheck",2000,1);



//In the End of your gamemode:


public HealthCheck()
{
    new Float:hp;
    for(new x=0; x<MAX_PLAYERS; x++)
    {
        if(IsPlayerConnected(x))
        {
            GetPlayerHealth(x,hp);
            if(hp < 20.0)
            {
                GameTextForPlayer(x, "~g~You are ~r~hurt,go to ~y~cover~n~~h~", 6000, 6);
                TimerHP = SetTimerEx("HealthLose", 300000, 0, "i", x);
                checking[x] = 1;
        }   }
    }
}


public HealthLose()
{
    for(new x=0; x<MAX_PLAYERS; x++)
    {
        new Float:Health;
        if(IsPlayerConnected(x))
        {
            if(checking[x] == 1)
            {
                GetPlayerHealth(x,Health);
                SetPlayerHealth(x, Health - 5.0);
                KillTimer(TimerHP);
                checking[x] = 0;
        }   }
    }
}

I hope that i have helped
For one, none of your timers returns a value(I'm pretty sure they should).

Also, I don't see why you'd have two timers running, when all you need is one. True, with my script the player may wait a minute before the notification showing up, but meh.
Reply
#8

The code of CrucixTM work,thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)