[Help] Unix timestamps with gettime
#1

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;
}
Reply
#2

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

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);
}
Reply
#4

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;
}
Reply
#5

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
Reply
#6

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)