Little question about yTimers.
#1

Hey there,

I got a /report CMD that when a player uses it he must wait 15 minutes to use it again, heres what I got so far.

pawn Код:
CMD:report(playerid,o[])
{
new msg[80],str[128],pname[MAX_PLAYER_NAME];
if(sscanf(o,"s[80]",msg)) return SCM(playerid,COLOR_LIGHTBLUE,"USAGE:/report [text]");
if(rcd[playerid] == 1) return SCM(playerid,COLOR_LIGHTBLUE,"You must wait 15 seconds in order to send another report!");
else
{
GetPlayerName(playerid,pname,sizeof(pname));
format(str,sizeof(str),"Report from %s(%i): %s",pname,playerid,msg);
SAM(COLOR_AQUA,str);
SCM(playerid,COLOR_YELLOW,"Your report has been sent to the administrators online.");
rcd[playerid] = 1;
delay:rtimer(playerid);
}
return 1;
}
And heres the timer
pawn Код:
timer rtimer[10000](playerid)
{
rcd[playerid] = 0;
SCM(playerid,COLOR_GREEN,"You may send another report now!");
}
Now my problem is, if I simply do such thing as
pawn Код:
rtimer(playerid);
under the report CMD it'll call the timer without delay, directly, and if I repeat the time:

pawn Код:
repeat rtimer(playerid);
It will be called after the certain time I used above but it keeps on repeating and it's like impossible to kill it,
if theres a way to kill it or a better way to use a delay timer i'd be thankful if you post it here..

Thanks.
Reply
#2

Timers aren't needed you could just use GetTime() and compare the current time with the one you stored in a variable when the user first reported, if 15 seconds or above allow the user to report again.
Reply
#3

Quote:
Originally Posted by Norn
Посмотреть сообщение
Timers aren't needed you could just use GetTime() and compare the current time with the one you stored in a variable when the user first reported, if 15 seconds or above allow the user to report again.
Could you show me a littttttle example please, I have never used that function before, only if possible
Reply
#4

Quote:
Originally Posted by moadi
Посмотреть сообщение
Could you show me a littttttle example please, I have never used that function before, only if possible
pawn Код:
new ReportCheck[MAX_PLAYERS]; // Global
// Inside report command:
new current_time =  gettime();
if(!ReportCheck[playerid] || ReportCheck[playerid] >= current_time + 15) {
ReportCheck[playerid] = current_time;
// The report code in here
}
else {
// Send message telling the user that he has to wait 15 seconds.
}
Reply
#5

Quote:
Originally Posted by Norn
Посмотреть сообщение
pawn Код:
new ReportCheck[MAX_PLAYERS]; // Global
// Inside report command:
new current_time =  gettime();
if(!ReportCheck[playerid] || ReportCheck[playerid] >= current_time + 15) {
ReportCheck[playerid] = current_time;
// The report code in here
}
else {
// Send message telling the user that he has to wait 15 seconds.
}

Thank you that helped me alot ++ rep.
Reply
#6

Sorry but that didn't work the way I expected, I've done everything the way I should and heres what I got.
pawn Код:
CMD:report(playerid,o[])
{
new rcd[MAX_PLAYERS];
new ctime = gettime();
new msg[80],str[128],pname[MAX_PLAYER_NAME];

if(sscanf(o,"s[80]",msg)) return SCM(playerid,COLOR_LIGHTBLUE,"USAGE:/report [text]");
if(!rcd[playerid] || rcd[playerid] >= ctime + 15)
{
rcd[playerid] = ctime;
GetPlayerName(playerid,pname,sizeof(pname));
format(str,sizeof(str),"Report from %s(%i): %s",pname,playerid,msg);
SAM(COLOR_AQUA,str);
SCM(playerid,COLOR_YELLOW,"Your report has been sent to the online administrators.");
}

else
{
SCM(playerid,COLOR_LIGHTBLUE,"You must wait 15 seconds in order to send another report!");
}
I still can spam the command, any solution?
Reply
#7

rcd is a global variable meaning you create it outside of any functions/commands.
Reply
#8

Quote:
Originally Posted by Norn
Посмотреть сообщение
rcd is a global variable meaning you create it outside of any functions/commands.
Yeah I just noticed this after posting it lol... thanks again .
Reply
#9

I've just noticed a flaw in my code, wasn't thinking when I coded it:

pawn Код:
new rcd[MAX_PLAYERS];
CMD:report(playerid,o[])
{
    new msg[80],str[128],pname[MAX_PLAYER_NAME];

    if(sscanf(o,"s[80]",msg)) return SCM(playerid,COLOR_LIGHTBLUE,"USAGE:/report [text]");
    if(!rcd[playerid] || gettime() >= rcd[playerid] + 15)
    {
        rcd[playerid] = gettime();
        GetPlayerName(playerid,pname,sizeof(pname));
        format(str,sizeof(str),"Report from %s(%i): %s",pname,playerid,msg);
        SAM(COLOR_AQUA,str);
        SCM(playerid,COLOR_YELLOW,"Your report has been sent to the online administrators.");
    }
    else
    {
        SCM(playerid,COLOR_LIGHTBLUE,"You must wait 15 seconds in order to send another report!");
    }
    return true;
}
Reply
#10

EDIT:nevermind
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)