Giving player health up to 99
#1

I want to create function that would give player health up to 99. For example if player has 80 health and I use GivePlayerHealth(playerid, 40) it would set player health to 99 and not to 120.

I tried something like this :

Код:
stock GivePlayerHealth(playerid,Float:Health)
{
new Float:health; GetPlayerHealth(playerid,health);
SetPlayerHealth(playerid,health+Health+1);
SetTimerEx("MinusHp", 50, false, "i", playerid); // It doesnt work if you take -1 health right away
}

forward MinusHp(playerid);
public MinusHp(playerid)
{
new Float:health;
GetPlayerHealth(playerid,health);
if(health>99)
{
SetPlayerHealth(playerid, 99);
}
return 1;
}
Well it works, but is there a way to do it without timer?
Reply
#2

I don't understand why you would use a timer. Is there a reason for the function to be delayed?

PHP код:
GivePlayerHealth(playeridFloat:health) {
    new 
Float:loc_health;
    
GetPlayerHealth(playeridloc_health);
    if((
loc_health health) > 99.0) {
        return 
SetPlayerHealth(playerid99);
    }
    return 
SetPlayerHealth(playeridloc_health health);

Reply
#3

Or use OnPlayerUpdate
PHP код:
if(GetPlayerHealth(playerid) > 99)
{
   
SetPlayerHealth(playerid99);

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)