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


Messages In This Thread
Health Problem - by [BR]Michael - 22.09.2011, 18:33
Re: Health Problem - by TheLazySloth - 22.09.2011, 18:59
Re: Health Problem - by [BR]Michael - 22.09.2011, 19:49
Re: Health Problem - by [BR]Michael - 25.09.2011, 18:29

Forum Jump:


Users browsing this thread: 2 Guest(s)