25.01.2011, 18:30
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:
That's it! Thanks a lot, and sorry for my bad english!
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);
}
}
}
}
}

