SA-MP Forums Archive
Count always stay 0 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Count always stay 0 (/showthread.php?tid=572292)



Count always stay 0 - Lirbo - 26.04.2015

why 'Count' always stay 0?

pawn Код:
// Chicken Attack
    if(Chicken[playerid]){
    MSG(playerid,C_GREEN,"[Chicken] ъчу бдцмзд");
    new Count;
    PetAttacked[playerid] = true;
    SetTimerEx("PetAtkDealy", 6000, false, "i", playerid);
    for(new i=0; i<MAX_PLAYERS; i++){
    GetPlayerPos(playerid,pX,pY,pZ);
    if(IsPlayerInRangeOfPoint(i,7,pX,pY,pZ) && i != playerid){
    GivePlayerHealth(i,-70);
    new Float:iHealth;
    GetPlayerHealth(i,iHealth);
    if(iHealth <=0){Count++; DOF2_SetInt(pFile(i),"Deaths",DOF2_GetInt(pFile(i),"Deaths")+1);}
    MSG(i,C_RED,"[Chicken] -70 Health");}}
    DOF2_SetInt(pFile(playerid),"Kills",DOF2_GetInt(pFile(playerid),"Kills")+Count);
    DOF2_SetInt(pFile(playerid),"TotalKills",DOF2_GetInt(pFile(playerid),"TotalKills")+Count);
    format(String,sizeof(String),"Count: %i",Count);
    MSG(playerid,C_RED,String);}



Re: Count always stay 0 - Konstantinos - 26.04.2015

GetPlayerHealth will return the previous health the player had as it hasn't updated it yet. So get the health, subtract and check:
pawn Код:
new Float:iHealth;
GetPlayerHealth(i,iHealth);
GivePlayerHealth(i,-70.0);
if(iHealth - 70.0 <= 0.0)
{
    Count++;
    DOF2_SetInt(pFile(i),"Deaths",DOF2_GetInt(pFile(i),"Deaths")+1);
}



Re: Count always stay 0 - Lirbo - 26.04.2015

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
GetPlayerHealth will return the previous health the player had as it hasn't updated it yet. So get the health, subtract and check:
pawn Код:
new Float:iHealth;
GetPlayerHealth(i,iHealth);
GivePlayerHealth(i,-70.0);
if(iHealth - 70.0 <= 0.0)
{
    Count++;
    DOF2_SetInt(pFile(i),"Deaths",DOF2_GetInt(pFile(i),"Deaths")+1);
}
:* <3