Help (TimerEx bug) [Rep+]
#1

pawn Код:
forward hptimer(playerid);
public hptimer(playerid)
{
    new Float:health;
    health = GetPlayerHealth(playerid, health);
    SetPlayerHealthAC(playerid, health+1);
    PlayerInfo[playerid][pHP] = SetPlayerHealth(playerid, health+1);
    GameTextForPlayer(playerid, "~g~+1 HP", 500, 3);
    PlayerPlaySound(playerid, 1083, 0.0,0.0,0.0);
    SetTimerEx("hptimer", 7000, 0, "d", playerid);
    return 1;
}
Please help. I want to make a system which gives +1 HP to the existing health. But it sets the HP to 1 (Dunno why).
Reply
#2

Use this:

pawn Код:
forward hptimer(playerid);
public hptimer(playerid)
{
    new Float:health;
    GetPlayerHealth(playerid, health);
        SetPlayerHealthAC(playerid, health+1);
    PlayerInfo[playerid][pHP] = SetPlayerHealth(playerid, health+1);
    GameTextForPlayer(playerid, "~g~+1 HP", 500, 3);
    PlayerPlaySound(playerid, 1083, 0.0,0.0,0.0);
    SetTimerEx("hptimer", 7000, 0, "d", playerid);
    return 1;
}
Reply
#3

The above code will work, what you did was this.

You create a float value called health.

You call the function GetPlayerHealth, and let it store the health value in health. Now when that function finishes you let it store the value it returned in health. This means the actuall health will be deleted and it will probally contain 00000.1 or just 0000000 or something among those lines.
Reply
#4

EDIT: Too late
Reply
#5

Checking...
Reply
#6

Jeez, just change
pawn Код:
health = GetPlayerHealth(playerid, health);
to
pawn Код:
GetPlayerHealth(playerid, health);
Reply
#7

Woah thanks works!
Another question:

How to make if a player has 100 HP the timer will stop?
Reply
#8

pawn Код:
forward hptimer(playerid);
public hptimer(playerid)
{
    SetPlayerHealthAC(playerid, GetPlayerHealth(playerid)+1);
    PlayerInfo[playerid][pHP] = SetPlayerHealth(playerid, GetPlayerHealth(playerid)+1);
    GameTextForPlayer(playerid, "~g~+1 HP", 500, 3);
    PlayerPlaySound(playerid, 1083, 0.0,0.0,0.0);
    SetTimerEx("hptimer", 7000, 0, "d", playerid);
    return 1;
}
Somethink like this...

But how do you call "hptimer" function? because i see SetTimerEx in function...
Reply
#9

No, I'm asking how to make if a player has 100 HP the timer will stop?
What callback to use?
Reply
#10

Quote:
Originally Posted by GangsTa_
Посмотреть сообщение
Woah thanks works!
Another question:

How to make if a player has 100 HP the timer will stop?
Just use this:
pawn Код:
forward hptimer(playerid); public hptimer(playerid) {
    new
        Float: fHealth
    ;
    GetPlayerHealth(playerid, fHealth);
    fHealth += 1.0;
    SetPlayerHealthAC(playerid, fHealth);
    PlayerInfo[playerid][pHP] = fHealth;
    GameTextForPlayer(playerid, "~g~+1 HP", 500, 3);
    PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
   
    if(fHealth < 100.0) {
        SetTimerEx("hptimer", 7000, 0, "i", playerid);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)