/count [seconds]
#1

I tried alot to make a cmd of count but failed ...

However , i request you guys to make a count cmd for me ..

Thanks in advance -
Reply
#2

Here you go
pawn Код:
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;
}
Reply
#3

Thanks mate ..
That was quick ..
Gonna check it now
Reply
#4

Next time request it here: https://sampforum.blast.hk/showthread.php?tid=447813
Reply
#5

This is a countdown from 10 to 0:

Код:
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;
}
Reply
#6

Dunno, why you guys are using Timer if you could simply use OnPlayerUpdate since it's not a huge chunk of code

pawn Код:
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;
}
Make sure you have #include <sscanf> and #include <zcmd>

Quote:
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.
Reply
#7

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
Dunno, why you guys are using Timer if you could simply use OnPlayerUpdate since it's not a huge chunk of code

pawn Код:
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;
}
Make sure you have #include <sscanf> and #include <zcmd>
The author wants that in seconds, not in 1/3 of a second.
OnPlayerUpdate gets called ~3 times a second.
Reply
#8

Quote:
Originally Posted by Loot
Посмотреть сообщение
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
Reply
#9

Quote:
Originally Posted by arakuta
Посмотреть сообщение
Wrong. OnPlayerUpdate gets called every 40ms (by default). See your server.cfg and read the rates.

https://sampwiki.blast.hk/wiki/Server.cfg
You are correct, thank you for pointing that out.
However, the code will run too fast which result the countdown to be shown in less than a second which is not ideal for the purpose of the request.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)