new CountDownSecs[MAX_PLAYERS],
CountDownTimer[MAX_PLAYERS];
CMD:count(playerid, params[])
{
new Secs;
if(sscanf(params, "i", Secs); return SendClientMessage(playerid, -1, "Usage: /count <Secs>");
CountDownSecs[playerid] = Secs;
CountDownTimer[playerid] = SetTimerEx("Counter", 1000, true, "i", playerid);
return 1;
}
forward Counter(playerid);
public Counter(playerid)
{
if(CountDownSecs[playerid] >= 1)
{
new str[5]; format(str, sizeof(str), "%i", CountDownSecs[playerid]);
GameTextForPlayer(playerid, s, 1000, 3);
PlayerPlaySound(i, 1057, 0, 0, 0);
}
else
{
GameTextForPlayer(playerid, "~R~Go!" ,1000, 3);
PlayerPlaySound(i, 1058, 0, 0, 0);
KillTimer(CountDownTimer[playerid]);
}
CountDownSecs[playerid]--;
return 1;
}
new Var_CountDown= 11; new Timer_CountDown; public OnPlayerCommandText(playerid, cmdtext[]) { if(!strcmp(cmdtext, "/countdown", true)) { Timer_CountDown = SetTimer("CountDown", 1000, false); return 1; } return 1; } forward CountDown(); public CountDown() { new string[128]; Var_CountDown--; if(Var_CountDown == 0) { KillTimer(Timer_CountDown); Var_CountDown = 11; } else { format(string, sizeof(string), "Count Down: ~n~%d", Timer_CountDown); GameTextForAll(string, 1000, 3); } return 1; }
new
_countvar[MAX_PLAYERS] = 0
;
CMD:count(playerid, params[]) {
new _countvar_;
if(sscanf(params, "i", _countvar_))
return SendClientMessage(playerid, -1, "Syntax: /count [Seconds]");
_countvar[playerid] = _countvar_;
return true;
}
public OnPlayerUpdate(playerid)
{
new
string [ 10 ]
;
if(1 <= _countvar[playerid]) { //if _countvar[playerid] is more than 1 or equals 1
format(string, sizeof(string), "%i", _countvar[playerid]), GameTextForAll(string, 1000, 3);
}
else {
GameTextForAll("GO!", 3000, 3), _countvar[playerid] = 0; // reset the variable and show the GO! message
}
return true;
}
Originally Posted by SA-MP Wiki
Important Note: This callback is called very frequently per second per player, only use it when you know what it's meant for.
|
Dunno, why you guys are using Timer if you could simply use OnPlayerUpdate since it's not a huge chunk of code
pawn Код:
|
The author wants that in seconds, not in 1/3 of a second.
OnPlayerUpdate gets called ~3 times a second. |
Wrong. OnPlayerUpdate gets called every 40ms (by default). See your server.cfg and read the rates.
https://sampwiki.blast.hk/wiki/Server.cfg |