01.03.2013, 23:20
I'm using gettime() sometimes in /pay command for example.
Checks if the current time minus the var with the old time is less than 2.
After the player pays:
Or just use a timerex?
So what's better timerex or gettime?!
Checks if the current time minus the var with the old time is less than 2.
pawn Код:
if(gettime() - GetIntVar(playerid, "JustPaid") < 2) return SCM(playerid, COLOR_LIGHTRED, "[SERVER]: Please wait 2 seconds before paying again. (Security Reasons)");
pawn Код:
SetIntVar(playerid, "JustPaid", gettime());
pawn Код:
CMD:pay(playerid, params[])
{
new pid, amount, string[256];
if(sscanf(params,"dd",pid,amount)) return SyntaxMSG(playerid, "/pay [playerid] [amount]");
if(pid == playerid) return SCM(playerid, -1, "You cannot pay to yourself.");
if(gettime() - GetIntVar(playerid, "JustPaid") < 2) return SCM(playerid, COLOR_LIGHTRED, "[SERVER]: Please wait 2 seconds before paying again. (Security Reasons)");
if(!PlayerIsOn(pid)) return NotConnectedMSG(playerid);
if(amount > GetCash(playerid) || amount <= 0) return SCM(playerid, -1, "You don't have enough money.");
if(amount > 1000 && GetLevel(playerid) <= 3) return SCM(playerid, -1, "Players under level '3' aren't able to pay more than 1000.");
if(!PlayerNearPlayer(5.0, playerid,pid)) return NotNearPlayerMSG(playerid);
SetIntVar(playerid, "JustPaid", gettime());
GiveCash(playerid, -amount);
GiveCash(pid, amount);
format(string, sizeof(string), "You have sent %s[ID:%d], $%d.", GetNameWithMask(pid),pid, amount);
SCM(playerid, COLOR_GRAD1, string);
format(string, sizeof(string), "You have recieved $%d from %s[ID:%d].", amount, GetNameWithMask(playerid), playerid);
SCM(pid, COLOR_GRAD1, string);
format(string, sizeof(string), "* %s takes out some cash, and hands it to %s.", GetNameWithMask(playerid) ,GetNameWithMask(pid));
ProxDetector(30.0, playerid, string, COLOR_PURPLE);
return 1;
}