SA-MP Forums Archive
Little question about yTimers. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Little question about yTimers. (/showthread.php?tid=296309)



Little question about yTimers. - moadi - 10.11.2011

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.


Re: Little question about yTimers. - Norn - 10.11.2011

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.


Re: Little question about yTimers. - moadi - 10.11.2011

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


Re: Little question about yTimers. - Norn - 10.11.2011

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.
}



Re: Little question about yTimers. - moadi - 10.11.2011

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.


Re: Little question about yTimers. - moadi - 10.11.2011

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?


Re: Little question about yTimers. - Norn - 10.11.2011

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


Re: Little question about yTimers. - moadi - 10.11.2011

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 .


Re: Little question about yTimers. - Norn - 10.11.2011

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;
}



Re: Little question about yTimers. - moadi - 10.11.2011

EDIT:nevermind