Need help with /heal
#1

Hello Guys,
I've made ​​a command, which allows users to heal. It works nearly properly, but he does not recognize when the player has his live over 99. He Continue with the healing.

Exactly, I mean that he does not recognize when the player has his live over 99. How can I fix it? In the appendix you find my code.

pawn Код:
public HealStep1(playerid)
{
    if(GetDistanceBetweenPlayers(playerid,HealOffer[playerid]) < 5.0)
    {
        new Float:health;
        GetPlayerHealth(playerid,health);
        if (health > 99.0)
        {
            SendClientMessage(playerid,COLOR_LIGHTBLUE,"* You were fully healed");
            KillTimer(HealStep1(playerid));
            KillTimer(HealStep2(playerid));
            return 1;
        }
        if (health < 100.0)
        {
            GivePlayerHealth(playerid, 10.0);
            SetTimerEx("HealStep2",1999,0,"d",playerid);
        }
    }
    else
    {
        SendClientMessage(playerid,COLOR_GREY,"The cure was canceled because you are too far away from the ambulance.");
        KillTimer(HealStep1(playerid));
        KillTimer(HealStep2(playerid));
        return 1;
    }
    return 1;
}

public HealStep2(playerid)
{
    if(GetDistanceBetweenPlayers(playerid,HealOffer[playerid]) < 5.0)
    {
        new Float:health;
        GetPlayerHealth(playerid,health);
        if (health > 99.0)
        {
            SendClientMessage(playerid,COLOR_LIGHTBLUE,"* You were fully healed");
            KillTimer(HealStep1(playerid));
            KillTimer(HealStep2(playerid));
            return 1;
        }
        if (health < 100.0)
        {
            GivePlayerHealth(playerid, 10.0);
            SetTimerEx("HealStep1",1999,0,"d",playerid);
        }
    }
    else
    {
        SendClientMessage(playerid,COLOR_GREY,"The cure was canceled because you are too far away from the ambulance.");
        KillTimer(HealStep1(playerid));
        KillTimer(HealStep2(playerid));
        return 1;
    }
    return 1;
}
Thanks for your help.

regards,
nescha
Reply
#2

If I have read correctly you don't have checker is player health over 99 during healing. You only have check before healing starts so if his health is lower than 99 before healing he will heal him forever. You can use Timer to check player's health every few seconds and if his health go over 99 it stops with healing. BUT too often times uses too much CPU and will cause massive lag. My suggestion for you is to use public OnPlayerUpdate(playerid)
Reply
#3

However, the /heal command checks the players life. If he had more than 99 HP, you cant heal him as a medic.

The command then triggers the timer "HealStep1" from which in turn triggers "HealStep2" from, as in a loop. But he heals continues indefinitely.

These are the lines that are not raised any:

pawn Код:
if (health > 99.0)
        {
            SendClientMessage(playerid,COLOR_LIGHTBLUE,"* You were fully healed");
            KillTimer(HealStep1(playerid));
            KillTimer(HealStep2(playerid));
            return 1;
        }
He don't check, whether the player has more life than 99, only if he has less than 100.(it's in a timer)
You know what i mean now?
Reply
#4

Eh sorry I can't understand what you mean.
Did the timer still repeating even their health.is more than 99?
Or
Did the command still works even their health is more than 99?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)