#1

Hey guys. I made command /askq (to ask question to online admins). Now, how can i make timer so one player can send /askq command every 2 minutes not every second. Thank you
Reply
#2

in your command:
PHP код:
    if(GetPVarInt(playerid,"CMDABUSE")>GetTickCount()) return SendClientMessage(playerid,0xFF0000FF,"You must wait before using a command");
    
SetPVarInt(playerid,"CMDABUSE",GetTickCount()+5000); 
Reply
#3

Okay i will try it now
Reply
#4

You can use GetTickCount() for it, it gets the current timestamp in milliseconds. In the command you then have to check the current timetamp and the saved timestamp

You have to create an array and a define like:

Код:
#define QUESTION_DELAY   120000 // 120000 = 2 minutes in ms
new PlayerLastQuestion[MAX_PLAYERS];
or similar.

In OnPlayerConnect you have to set it so new players can ask immediately:

Код:
PlayerLastQuestion[playerid] = GetTickCount() - QUESTION_DELAY; // Set the last tick to now minus DELAY
And in your command:

Код:
if(GetTickCount() - PlayerLastQuestion[playerid] < QUESTION_DELAY) return SendClientMessage(playerid, 0xFF0000FF, "Sorry, you can only ask a question every 2 minutes!");

PlayerLastQuestion[playerid] = GetTickCount();

// Do ask stuff
Or do it with PVars like oMa suggested, the outcome is the same however I prefer vars for this simple thing.
Reply
#5

new AskQuestionTime[MAX_PLAYERS];

CMD:askq(playerid)
{
if(AskQuestionTime[playerid] > gettime())return SendClientMessage(playerid,-1,"Please wait some minute to use this cmd again.");
//your string code here about question

AskQuestionTime[playerid] = gettime() + 60; // he can use cmd once in 60 seconds.
}
Reply
#6

PHP код:
CMD:ask(playerid,params[]) {
    new 
question[128];
    new 
asker[MAX_PLAYER_NAME], str[128];
    if (
sscanf(params"s"question)) return SendClientMessage(playeridCOLOR_LIGHTBLUE"USAGE: /ask <ID>");
    
GetPlayerName(playeridaskersizeof(asker));
    
format(strsizeof(str), "||Question||  %s(%d) asks: %s",askerquestion);
    
MessageToAdmins(COLOR_WHITE,str);
    return 
SendClientMessage(playerid,yellow"Your question has been sent to online administrators.");

Reply
#7

if((GetTickCount()-WaitTimeForCMD[playerid])>120000)return SendClientMessage(playerid,RED,"ERROR: Wait 2 Minutes to use this CMD again!");
Reply
#8

Jesus...

Just use gettime() + 120 as it is more reliable.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)