Timer -
Micko123 - 29.04.2016
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
Re: Timer -
oMa37 - 29.04.2016
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);
Re: Timer -
Micko123 - 29.04.2016
Okay i will try it now
Re: Timer -
NaS - 29.04.2016
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.
Re: Timer -
MBilal - 29.04.2016
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.
}
Re: Timer -
TorresxD - 29.04.2016
PHP код:
CMD:ask(playerid,params[]) {
new question[128];
new asker[MAX_PLAYER_NAME], str[128];
if (sscanf(params, "s", question)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /ask <ID>");
GetPlayerName(playerid, asker, sizeof(asker));
format(str, sizeof(str), "||Question|| %s(%d) asks: %s",asker, question);
MessageToAdmins(COLOR_WHITE,str);
return SendClientMessage(playerid,yellow, "Your question has been sent to online administrators.");
}
Re: Timer -
TorresxD - 29.04.2016
if((GetTickCount()-WaitTimeForCMD[playerid])>120000)return SendClientMessage(playerid,RED,"ERROR: Wait 2 Minutes to use this CMD again!");
Re: Timer -
Runn3R - 29.04.2016
Jesus...
Just use gettime() + 120 as it is more reliable.