Timer issue
#1

Hey Guys,
I have created a timer to basicly count to 25 seconds before it respawns the player.
The issue is that when this happens, the timer seems to decrease each time the player dies.
At top of the script I have:
pawn Код:
#define DEATH_TIME 25
new SecsToGo[MAX_PLAYERS];
new Death[MAX_PLAYERS char] = 0;
So OnPlayerDeath here is the code.

pawn Код:
SecsToGo[playerid] = DEATH_TIME;
DeathTimer{playerid} = SetTimerEx("Death", 1000, true, "i", playerid);
And then I have the timer.

pawn Код:
public Death(playerid)
{
    SecsToGo[playerid]--;
    if(SecsToGo[playerid] < 0)
    {
        SetAlive(playerid);
        return 1;
    }
    return 1;
}
Then I have the timer which sets the player alive.

pawn Код:
stock SetAlive(playerid)
{
    KillTimer(Death{playerid});
    return 1;
}
I have removed the variables, functions which are having no affect to the timer. Can someone please help me on this? And possibly shed some light to why its decreasing the time each time the player dies? If players die enough, they end up dying for like 1 second then respawning.
Reply
#2

There's a lot of error in your code for example you created a variable called Death and a callback called Death that will give you an error error 021: symbol already defined: "Death" and error 010: invalid function or declaration

This code should work.

pawn Код:
//macro
#define function:%0(%1) \
    forward%0(%1); public%0(%1)

#define DEATH_TIME \
    25

//variable
new
    SecsToGo[ MAX_PLAYERS ] , DeathTimer[ MAX_PLAYERS char ];

public OnPlayerDeath( playerid, killerid, reason )
{
    SecsToGo[ playerid ] = DEATH_TIME;
    DeathTimer{ playerid } = SetTimerEx( "Death", 1000, true, "i", playerid ); //timer
    return true;
}

function: Death( playerid )
{
    if(0 < SecsToGo[playerid]) //Yoda Conditions
        SecsToGo[playerid]--; // decrease the timer per second if it's more than 0 .

    if(0 > SecsToGo[playerid]) //Yoda Conditions
        KillTimer( DeathTimer{playerid} ), SpawnPlayer(playerid); //stops the timer and spawns the player
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)