Health Problem (little help, please)
#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.

Codes:
Код:
#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

Help, please...
Reply
#3

I'm sorry, but just can't understand what you are trying to accomplish here (it's currently 2:44 AM, so I am tired). If you could give me a list, step by step, of what you are trying to do, I would appreciate it.
Reply
#4

@Grim_ i think you need a rest
@topic are you trying to say that if you set someone health then after it update's it go back to default
Reply
#5

When I 'increase' the health, it go back to default
Reply
#6

Help :S
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)