SetPlayerHealth problems
#1

The code:
pawn Код:
CMD:use(playerid, params[])
{
    new string[128];
    if(sscanf(params, "s[8]", params))
    {
        SendClientMessage(playerid, COLOR_WHITE, "[Usage]: /use [type]");
        SendClientMessage(playerid, COLOR_GREY, "TYPES: Cigar | cocaine");
        return 1;
    }
    if(IsPlayerCuffed(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You can't do this right now.");
    if(!strcmp(params, "cigar", true))
    {
        if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You can't do this right now.");
        if(!PlayerInfo[playerid][pCigar]) return SendClientMessage(playerid, COLOR_GREY, "You don't have any cigarettes on you.");
        new Float:H;
        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_SMOKE_CIGGY);
        SetPlayerHealth(playerid, H+5);
        GetPlayerHealth(playerid, H);
        if(H > 100) SetPlayerHealth(playerid, 100);
        PlayerInfo[playerid][pCigar] --;
        format(string, sizeof(string), "* %s takes out a cigarette and lights it up.", RPN(playerid));
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        SetTimerEx("Regenation",10000,false,"dd",playerid,1);
    }
The forward:
pawn Код:
forward Regernation(playerid,times);
public Regernation(playerid,times)
{
    if(times)
    {
        new Float:Health;
        GetPlayerHealth(playerid, Health);
        if(Health > 100) SetPlayerHealth(playerid, 98.0);
        else SetPlayerHealth(playerid, Health - 2.0);
        SetTimerEx("Regenation",2000,false,"dd",playerid,1);
    }
    return 1;
}
First of all, how can I make it give a player +5 HP when /use cigar instead of setting the players health to 5?

And the second problem is how to make the timer minus a players health by 1 each minute after smoking the cigarette?
Reply
#2

Switch these two lines around.

SetPlayerHealth(playerid, H+5);
GetPlayerHealth(playerid, H);

Get first, then set it.
Reply
#3

pawn Код:
SetPlayerHealth(playerid, H+5);
GetPlayerHealth(playerid, H);
You set and the get the health. It should be the opposite.
Reply
#4

Thanks a lot for the quick responses!

How can I make the timer that sets -1 health each minute when the cmd has been typed?
Reply
#5

Make a timer that repeats every minute and check if they have used the command. If they have then do:

new Float: HP
GetPlayerHealth(playerid, HP);
SetPlayerHealth(playerid, HP-1);

... To take one HP away...
Reply
#6

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Make a timer that repeats every minute and check if they have used the command. If they have then do:

new Float: HP
GetPlayerHealth(playerid, HP);
SetPlayerHealth(playerid, HP-1);

... To take one HP away...
Thanks a lot for the help, everything is working now.

Is it possible to stop the timer on a command?
Reply
#7

If you are using something like SmokeCommand[playerid] = 1 it would be...

CMDtopsmoking(playerid, params[])
{
if(SmokeCommand[playerid] == 0) return SendClientMessage(playerid, -1, "You're not even smoking...");
SmokeCommand[playerid] = 0;
SendClientMessage(playerid, -1, "You have stopped smoking.");
return 1;
}

Then stop the timer.
Reply
#8

Quote:
Originally Posted by Abagail
Посмотреть сообщение
If you are using something like SmokeCommand[playerid] = 1 it would be...

CMDtopsmoking(playerid, params[])
{
if(SmokeCommand[playerid] == 0) return SendClientMessage(playerid, -1, "You're not even smoking...");
SmokeCommand[playerid] = 0;
SendClientMessage(playerid, -1, "You have stopped smoking.");
return 1;
}

Then stop the timer.
I was thinking about adding some anti nicotine gum with a command like /eatgum and it would have a chance of working..
The timer:
pawn Код:
SetTimerEx("Timer",60000,1,"i",playerid);
The forward n stuff:
pawn Код:
forward Timer(playerid); // Tell the server that "Timer" is a public function
public Timer(playerid)
{
    new Float:hp; // Create a float value where we will store the players HP
    GetPlayerHealth(playerid,hp); // Get players health and store it inside "hp"
    SetPlayerHealth(playerid,hp-1); // Set Players health to their current health (hp) minus 1
}
Would it work if I placed this under the eatgum cmd KillTimer(Timer);?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)