18.02.2011, 19:37
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.
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);
}
}
}
}
}
public OnPlayerDamage(playerid, Float:damage)
{
if(Limp[playerid] != 0)
return 0;
new Float:health;
GetPlayerHealth(playerid, health);
if(health < 25.0)
{
if(Limp[playerid] != 2)
{
HideTextRed(playerid);
Rob[playerid] = 0;
Limp[playerid] = 2;
ShowTextGray(playerid);
SetPlayerDrunkLevel(playerid, 40000);
SetTimerEx("Limping", 3000, false, "d", playerid);
}
}
else
{
ShowTextRed(playerid);
if(damage < 10.0)
SetTimerEx("HideTextRed", 400, false, "d", playerid);
else
{
Rob[playerid] = 0;
if(!IsPlayerInAnyVehicle(playerid))
{
Limp[playerid] = 1;
SetTimerEx("StopAnimation", 200, false, "d", playerid);
SetTimerEx("DamageAnimation", 500, false, "df", playerid, damage);
}
else
SetTimerEx("HideTextRed", 3000, false, "d", playerid);
}
}
return 1;
}
public DamageAnimation(playerid, Float:damage)
{
new anim;
if(damage >= 22.0)
{
new getupid;
anim = random(4);
if(anim == 0)
{
getupid = 1;
ApplyAnimation(playerid, "PED", "KO_shot_face", 4.1, 0, 1, 1, 1, -1, 1);
}
else if(anim == 1)
{
getupid = 0;
ApplyAnimation(playerid, "PED", "KO_shot_stom", 4.1, 0, 1, 1, 1, -1, 1);
}
else if(anim == 2)
{
getupid = 0;
ApplyAnimation(playerid, "KNIFE", "KILL_Knife_Ped_Die", 4.1, 0, 1, 1, 1, -1, 1);
}
else
{
getupid = 1;
ApplyAnimation(playerid, "KNIFE", "knife_hit_3", 4.1, 0, 1, 1, 1, -1, 1);
}
SetTimerEx("DamageAnimationGetUp", 7000, false, "dd", playerid, getupid);
}
else
{
anim = random(3);
if(anim == 0)
ApplyAnimation(playerid, "MD_END", "END_SC1_PLY", 4.1, 0, 1, 1, 1, -1, 1);
else if(anim == 1)
ApplyAnimation(playerid, "MD_END", "END_SC1_RYD", 4.1, 0, 1, 1, 1, -1, 1);
else
ApplyAnimation(playerid, "MD_END", "END_SC1_SWE", 4.1, 0, 1, 1, 1, -1, 1);
SetTimerEx("DamageEnd", 5000, false, "d", playerid);
}
SetPlayerDrunkLevel(playerid, 50000);
}
public DamageAnimationGetUp(playerid, getupid)
{
if(getupid == 0)
ApplyAnimation(playerid, "PED", "getup_front", 4.1, 0, 1, 1, 1, -1, 1);
else
ApplyAnimation(playerid, "PED", "getup", 4.1, 0, 1, 1, 1, -1, 1);
SetTimerEx("DamageEnd", 1500, false, "d", playerid);
}
public DamageEnd(playerid)
{
Limp[playerid] = 0;
SetPlayerDrunkLevel(playerid, pDrunk[playerid]);
HideTextRed(playerid);
ClearAnimations(playerid);
}
public Limping(playerid)
{
if(Limp[playerid] == 2)
{
new Float:health;
GetPlayerHealth(playerid, health);
if(health < 25.0)
{
if(!IsPlayerInAnyVehicle(playerid))
ApplyAnimation(playerid, "RYDER", "RYD_Die_PT1", 4.1, 1, 1, 1, 1, 1, 1);
SetTimerEx("Limping", 5000, false, "d", playerid);
return;
}
}
SetPlayerDrunkLevel(playerid, pDrunk[playerid]);
Limp[playerid] = 0;
HideTextGray(playerid);
}

