Health Problem
#1

Hello all!

I'm having a problem with health in my server, I did a system that uses a variable (pHealth) to store a player's health and calculate his damage, but when I set his health higher, the "Update" function sets it back to the previous value.
OBS: sometimes it works normally.

Код:
#define UPDATE_HEALTH                   4

new pUpdate[MAX_PLAYERS];
new Float:pHealth[MAX_PLAYERS];

stock SetPlayerSysHealth(playerid, Float:health)
{
    pHealth[playerid] = health;
    SetPlayerHealth(playerid, pHealth[playerid]);
    return pUpdate[playerid] |= UPDATE_HEALTH;
}

stock AddPlayerSysHealth(playerid, Float:health)
{
    pHealth[playerid] += health;
    SetPlayerHealth(playerid, pHealth[playerid]);
    return pUpdate[playerid] |= UPDATE_HEALTH;
}

stock GetPlayerSysHealth(playerid, &Float:health)
    health = pHealth[playerid];

public OnGameModeInit()
{
    SetTimer("Update", 50, true);
}

public Update()
{
    for(new n = 0; n < MAX_PLAYERS; n++)
    {
        if(IsPlayerConnected(n) && IsPlayerLogged(n))
        {
            if(pUpdate[n] & UPDATE_HEALTH)
            {
                if(pHealth[n] < 1.0)
                    pHealth[n] = 1.0;
                    
                if(pHealth[n] > 100.0)
                    pHealth[n] = 100.0;
                    
                SetPlayerHealth(n, pHealth[n]);
                pUpdate[n] &= ~UPDATE_HEALTH;
            }
            
            else
            {
            	new Float:H;

	        GetPlayerHealth(n, H);

     	       	if(H < pHealth[n])
        	{
            	    new Float:D;
                
                    D = pHealth[n] - H;
                    SetPlayerSysHealth(n, H);
                    OnPlayerDamage(n, D);
            	}
	    }
        }
    }
}
That's it! Thanks a lot, and sorry for my bad english!
Reply
#2

If you are trying to set his health above 100.0,
this
Код:
                if(pHealth[n] > 100.0)
                    pHealth[n] = 100.0;
is stopping you.

You can delete it or change the 100.0 to whatever you want the player's max health to be.
Reply
#3

did not work :/
Reply
#4

heeelp =x!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)