How to make a player slowly loose health?
#1

This is my current code. But it just kills the player instead of removes 10hp per 30 seconds. And if you manage to give me a fix, please state what I did wrong.

Much appreciated.

pawn Код:
forward HungerTimer(playerid);
public HungerTimer(playerid)
{
    format(hungerstring,sizeof(hungerstring), "Hunger: %d", hunger[playerid]);
    TextDrawSetString(Textdraw3, hungerstring);
    hunger[playerid]--;
    if(hunger[playerid] < 20)
    {
        SetTimerEx("LooseHealth", 15000, true, "i", playerid);
    }
    return 1;
}
Reply
#2

[code]
function LooseHealth()
{
new hp = GetPlayerHealth(playerid, hp);
Player[playerid][Health] = hp-1;
SetPlayerHealth(playerid, hp-1);
}
Something like this?
Reply
#3

Tag mismatch for new hp = GetPlayerHealth. Would I need to make it a float? If so, It'd be pretty much the same code i have.
Reply
#4

REMOVED
Reply
#5

The problem is probably here:
pawn Код:
SetTimerEx("LooseHealth", 15000, true, "i", playerid);
Notice how this timer is repeating (ie. labelled 'true')?
If 'HungerTimer' is a repeating timer, then you have created a repeating timer inside a repeating timer, which can give very incorrect results... especially on small-delay timers.

For example,
The blue blocks represent 'HungerTimer'. The red blocks represent the 'LooseHealth' timer. If you have a repeating timer inside a repeating timer, this is what happens:


So show us where you set the 'HungerTimer' timer. Then we can make the appropriate adjustments for you and tell you how you could of corrected it.
Reply
#6

Well, it's technically 3 timers thrown together. I'm not sure how to do a alternative.

pawn Код:
forward RoundStartTimer(playerid);
public RoundStartTimer(playerid)
{
    if(LobbyCount > 1)
    {
        for(new i; i != GetMaxPlayers(); i++)
        {
            if(IsPlayerReady[i])
            {
                SetTimerEx("HungerTimer", 10000, true, "i", i);
                SetPlayerTeam(i, NO_TEAM);
                new rand = random(sizeof(rSpawns));
                SetPlayerPos(i, rSpawns[rand][0], rSpawns[rand][1], rSpawns[rand][2]);
                SetCameraBehindPlayer(i);
                GameProgress = true;
                LobbyCount = 0;
                TogglePlayerControllable(i, 1);
                hunger[i] = 100;
                TextDrawSetString(Textdraw3, hungerstring);
                TextDrawShowForPlayer(i, Textdraw3);
            }
        }
        new string[128];
        format(string,sizeof(string), "Total players: %d.", players);
        SendClientMessageToAll(COLOR_GREY, string);
        ShowNameTags(0);
        SendClientMessage(playerid, COLOR_GREEN, "The Hunger games is prepairing to start, please be patient... (Name tags disabled)");
    }
    return 1;
}
Reply
#7

Yeah, I'd need to see your whole script to be able to fix this issue and make sure everything is working properly.
Reply
#8

I managed to reduce it to 2 timers, and created a stock for the health loss. All is working. Thanks for trying to assist.

EDIT: If you have a timer being called every 30 seconds, removing one variable per call, how do you stop the variable from being called at 1?

pawn Код:
if(hunger == 1)
{
      KillTimer // ?
}
Reply
#9

You would need to assign the timer to a variable in order to kill it.

Example:
pawn Код:
new MyTimer; //At the top of your script.

public OnGameModeInit()
{
    MyTimer = SetTimerEx("LooseHealth", 3000, true, "i", playerid);
    //OTher stuff...
    return 1;
}

//Where you want to kill the timer...
KillTimer(MyTimer);
//Other stuff...
Reply
#10

Ah, that's right. Thank you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)