The Death Timer!!
#1

I need a timer, So it decreases like 5 or less hp each second, I'm confused with it. So after a few seconds the hp should finally reach 0 and the player dies. Please help me with this
Reply
#2

Set a timer for 1 second that repeats.
Then in the function decrease the players health.
pawn Код:
// Your function
forward Death(playerid);
public Death(playerid)
{
       new Float:Health;
       GetPlayerHealth(playerid, Health);
       SetPlayerHealth(playerid, Health-5);
}
i'm not the with timers but i hope this helps!
Reply
#3

Hello!

Okay, that ^ is a start, but not all.


on top under includes and stuff :
pawn Код:
new KillTimer;
OnGameModeInit
pawn Код:
KillTimer = SetTimer("KillTimer", 5000, 0);
This comes anywhere outside other publics.
pawn Код:
forward KillTimer();
public KillTimer()
{
new Float:HP;
GetPlayerHealth(playerid, HP);
SetPlayerHealth(playerid, HP -5);
}

//Other stuff..
OnGameModeExit..

pawn Код:
KillTimer(KillTimer);
Should work just fine. :P
Reply
#4

Hobod provided a better solution than you did.

Working from his solution:
pawn Код:
forward Death(playerid);
public Death(playerid)
{
       new Float:Health;
       GetPlayerHealth(playerid, Health);
       SetPlayerHealth(playerid, Health-5)
       if(Health-5 <= 0) KillTimer(GetPVarInt(playerid, "timerDeath"));
}
Then to set the timer in action:
pawn Код:
SetTimerEx("Death", 1000, true, "i", playerid);
Reply
#5

Whole command.

Not Tested
pawn Код:
new InfectedTimer[MAX_PLAYERS];

COMMAND:infect(playerid, params[])
{
    new targetid;
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /infect [playeris | name]");
    else if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "That player is not connected");
    {
        InfectedTimer[playerid] = SetTimerEx("Infected", 1000, true, "d", targetid);
        SendClientMessage(playerid, 0xFFFFFFAA, "You infected someone");
        SendClientMessage(targetid, 0xFFFFFFAA, "Someone infected you");
    }
    return 1;
}

forward Infected(playerid);
public Infected(playerid)
{
    new Float:Health;
    GetPlayerHealth(playerid, Health);
    if(Health >= 5)
    {
        SetPlayerHealth(playerid, Health - 5);
    }
    else
    {
        SetPlayerHealth(playerid, 0.0);
        KillTimer(InfectedTimer[playerid]);
        SendClientMessageToAll(0xFFFFFFAA, "Someone died of a infection");
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by CyberGhost
Посмотреть сообщение
Whole command.

Not Tested
pawn Код:
new InfectedTimer[MAX_PLAYERS];

COMMAND:infect(playerid, params[])
{
    new targetid;
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /infect [playeris | name]");
    else if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "That player is not connected");
    {
        InfectedTimer[playerid] = SetTimerEx("Infected", 1000, true, "u", targetid);
        SendClientMessage(playerid, 0xFFFFFFAA, "You infected someone");
        SendClientMessage(targetid, 0xFFFFFFAA, "Someone infected you");
    }
    return 1;
}

forward Infected(playerid);
public Infected(playerid)
{
    new Float:Health;
    GetPlayerHealth(playerid, Health);
    if(Health >= 5)
    {
        SetPlayerHealth(playerid, Health - 5);
    }
    else
    {
        SetPlayerHealth(playerid, 0.0);
        KillTimer(InfectedTimer[playerid]);
        SendClientMessageToAll(0xFFFFFFAA, "Someone died of a infection");
    }
    return 1;
}
"u" is a parameter in sscanf, not SetTimerEx.
Reply
#7

Quote:
Originally Posted by __
Посмотреть сообщение
"u" is a parameter in sscanf, not SetTimerEx.
Yeah i forgot, edited.

Код:
This forum requires that you wait 120 seconds between posts. Please try again in 30 seconds.
Reply
#8

Quote:

if(Health-2 <= 0) KillTimer(GetPVarInt(playerid, "timerDeath"));

On this line i get some errors like "Expected token ; but found if...."
Reply
#9

Quote:
Originally Posted by Swiftz
Посмотреть сообщение
On this line i get some errors like "Expected token ; but found if...."
pawn Код:
if(Health <= 0) KillTimer(GetPVarInt(playerid, "timerDeath"));
Reply
#10

No i still get that error please help
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)