SA-MP Forums Archive
[Help] Unix timestamps with gettime - 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: [Help] Unix timestamps with gettime (/showthread.php?tid=423775)



[Help] Unix timestamps with gettime - David (Sabljak) - 19.03.2013

Hello, can someone make me exmaple of Command for unix timestamp, i want to use less timer's in script...

this is expamle of /report command i want to remove timer and put timestamp....

Код:
new bool:ReportTime[MAX_PLAYERS] = false;
Код:
public Report(playerid)
{
    ReportTime[playerid] = false;
    return 1;
}
Код:
CMD:report(playerid, params[])
{
	new string[128];
	if(PlayerInfo[playerid][pMuted] == 1) return SCM(playerid,Crvena,"{FFFFFF}[{F81414}CHFR{FFFFFF}!] Utisani ste!");
	if(ReportTime[playerid] == true) return SCM(playerid,0xFFFFFFFF,  "{B3B3B3}({FF0000}Odbijeno!{B3B3B3}){FFFFFF} Report mozes koristit nakon 1 minute!");
	if(isnull(params)) return SCM(playerid, Narandasta,"Koristi:{FFFFFF} /report [razlog?]");
	format(string,sizeof(string)," |R| %s[%d]: %s", PlayerName(playerid),playerid, params);
	PorukaAdminu(Narandasta,string);
	format(string,sizeof(string),"*Vas report glasi: {FFFFFF}%s",params);
	SCM(playerid,Zuta3,string);
	SCM(playerid,Zuta3,"*Online Administratori ce odgovoriti u sto kracem vremenu.");
	ReportTime[playerid] = true; //This
        SetTimerEx("Report", 60000, false, "d", playerid); //This
	return 1;
}



AW: [Help] Unix timestamps with gettime - Mellnik - 19.03.2013

You can also use GetTickCount for that. There are plenty tutorials around on how to make a cmd cooldown.


Re: [Help] Unix timestamps with gettime - David (Sabljak) - 19.03.2013

Well they told me to use gettime for that command....

hmm lets see i have this global timer, example for timestamp? XD

Код:
SetTimer("SaveAccounts",Min(10),true);
Код:
forward SaveAccounts();
public SaveAccounts()
{
foreach (Player, i)
{
SaveAccount(i);
}



AW: [Help] Unix timestamps with gettime - Mellnik - 19.03.2013

Yes or do it like that:

Код:
#define COOLDOW_CMD 60000

new LastTick[MAX_PLAYERS];

COMMAND:test(playerid, params[])
{
	new tick = GetTickCount();
	if((LastTick[playerid] + COOLDOWN_CMD) >= tick)
	{
    	return SCM(playerid, -1, "Please wait a bit before using this cmd again!");
	}

 // end of the cmd:
  LastTick[playerid] = tick;
}



Re: [Help] Unix timestamps with gettime - David (Sabljak) - 19.03.2013

nono, it's just for backup, he is saving on Disconnect :P

can you explain me more about that unix time stamp or not :P


Re: [Help] Unix timestamps with gettime - Vince - 19.03.2013

Basically, it's this:

pawn Код:
CMD:report(playerid, params[])
{
    static reportTime[MAX_PLAYERS];

    if((gettime() - reportTime[playerid]) < 60)
    {
        // Less than 60 seconds have passed
        return 1;
    }

    reportTime[playerid] = gettime();

    // Your actual command goes here.
    return 1;
}



Re: [Help] Unix timestamps with gettime - David (Sabljak) - 19.03.2013

Thanks all, i understand now for Command, for global timers there is way or not?


Re: [Help] Unix timestamps with gettime - Misiur - 19.03.2013

pawn Код:
new ReportTime[MAX_PLAYERS] = { -1, ... };
pawn Код:
if(gettime() - ReportTime[playerid] < 60) return SCM(playerid,0xFFFFFFFF,  "{B3B3B3}({FF0000}Odbijeno!{B3B3B3}){FFFFFF} Report mozes koristit nakon 1 minute!");
pawn Код:
ReportTime[playerid] = gettime();
#e: Vince Y U faster than me >:C