countdown error
#1

hy my countdown timer not work then i write countdown it shows 3 2 1 1 1 go! go! a lot of times

Quote:

forward CountingDown(playerid, time);


if(strcmp(cmdtext,"/countdown",true) == 0)
{
SetTimerEx("CountingDown", 1000, true, "ii", playerid, 3);
}

public CountingDown(playerid, time)
{
if(time != 0)
{
new string[5];
format(string, sizeof(string), "%d", time);
GameTextForPlayer(playerid, string, 1200, 4);
SetTimerEx("CountingDown", 1000, true, "ii", playerid, time-1);
}
else
{
GameTextForPlayer(playerid, "~g~Go!", 2500, 3);
TogglePlayerControllable(playerid, 1);
SendClientMessage(playerid, -1, "Go!");
SetTimer("CountingDown", 1000, false);
}
return true;
}

Reply
#2

pawn Код:
{
GameTextForPlayer(playerid, "~g~Go!", 2500, 3);
TogglePlayerControllable(playerid, 1);
SendClientMessage(playerid, -1, "Go!");
SetTimer("CountingDown", 1000, false);
}
Instead of SetTimer("CountingDown", 1000, false); you need to use KillTimer();
https://sampwiki.blast.hk/wiki/KillTimer
Reply
#3

Add something like KillTimer("CountingDown", playerid) Not sure...
Reply
#4

Quote:
Originally Posted by Gooday
Посмотреть сообщение
Add something like KillTimer("CountingDown", playerid) Not sure...
D:\trucking\gamemodes\Trucking.pwn(5511) : error 035: argument type mismatch (argument 1)
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#5

Quote:
Originally Posted by Gooday
Посмотреть сообщение
Add something like KillTimer("CountingDown", playerid) Not sure...
See wiki.
KillTimer

Also, I suggest you SetTimerEx, not SetTimer.
Reply
#6

i already try

new timer;
public CountingDown(playerid, time)
{
if(time != 0)
{
new string[5];
format(string, sizeof(string), "%d", time);
GameTextForPlayer(playerid, string, 1200, 4);
timer = SetTimerEx("CountingDown", 1000, true, "ii", playerid, time-1);
}
else
{
GameTextForPlayer(playerid, "~g~Go!", 2500, 3);
TogglePlayerControllable(playerid, 1);
SendClientMessage(playerid, -1, "Go!");
KillTimer(timer);

}
return true;
}

and
SetTimerEx("CountingDown", 1000, false, "ii", playerid, time-1);
SetTimerEx("CountingDown", false);
Reply
#7

We dont need to store the timer if its not repeating
There are two ways to write countdowns,
first with an repeating timer and an player array
or just with delayed recursion, like that
pawn Код:
forward CountingDown(playerid, time);
public CountingDown(playerid, time) {
    if(0 < time) {
        new number[8];
        valstr(number, time--, false);
        GameTextForPlayer(playerid, number, 1200, 4);
        SetTimerEx("CountingDown", 1000, false, "ii", playerid, time);
    } else {
        GameTextForPlayer(playerid, "~g~Go!", 2500, 3);
        TogglePlayerControllable(playerid, true);
        SendClientMessage(playerid, -1, "Go!");
    }
}
pawn Код:
if(strcmp(cmdtext, "/countdown", true) == 0) {
    CountingDown(playerid, 3);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)