timer on commands - 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: timer on commands (
/showthread.php?tid=601970)
timer on commands -
Deny1 - 29.02.2016
Код:
CMD:jetpack(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1) return SCM(playerid, -1, "error!");
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USEJETPACK);
return 1;
}
How to make to use this command every 10 minutes only
Re: timer on commands -
Deny1 - 29.02.2016
someone?
Re: timer on commands -
d3ll - 29.02.2016
Try this:
PHP код:
CMD:jetpack(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1) return SCM(playerid, -1, "error!");
if(GetTickCount() - GetPVarInt(playerid, "LastJetpackCMD") < 100000) return SCM(playerid, -1, "Error, you can only use this command every 10 minutes.");
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USEJETPACK);
SetPVarInt(playerid, "LastJetpackCMD", GetTickCount());
return 1;
}
Re: timer on commands -
Joron - 29.02.2016
Quote:
Originally Posted by Deny1
someone?
|
You use settimerex
https://sampwiki.blast.hk/wiki/SetTimerEx
Re: timer on commands -
AbyssMorgan - 29.02.2016
Quote:
Originally Posted by d3ll
Try this:
PHP код:
CMD:jetpack(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1) return SCM(playerid, -1, "error!");
if(GetTickCount() - GetPVarInt(playerid, "LastJetpackCMD") < 100000) return SCM(playerid, -1, "Error, you can only use this command every 10 minutes.");
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USEJETPACK);
SetPVarInt(playerid, "LastJetpackCMD", GetTickCount());
return 1;
}
|
600000 not 100000 millisecond lol (10*60*1000)
Re: timer on commands -
Crayder - 29.02.2016
Quote:
Originally Posted by Joron
|
NEVER USE TIMERS FOR THINGS LIKE THIS!
This is just a simple cool down.
Quote:
Originally Posted by d3ll
Try this:
PHP код:
CMD:jetpack(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1) return SCM(playerid, -1, "error!");
if(GetTickCount() - GetPVarInt(playerid, "LastJetpackCMD") < 100000) return SCM(playerid, -1, "Error, you can only use this command every 10 minutes.");
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USEJETPACK);
SetPVarInt(playerid, "LastJetpackCMD", GetTickCount());
return 1;
}
|
NEVER USE PVARS FOR THINGS LIKE THIS!
PVar's should only be used when accessing variables across multiple scripts (ex. gamemode to filterscript).
Better:
pawn Код:
new LastJetpackCMD[MAX_PLAYERS];
CMD:jetpack(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1)
return SCM(playerid, -1, "error!");
if(GetTickCount() - LastJetpackCMD[playerid] < 600000)
return SCM(playerid, -1, "Error, you can only use this command every 10 minutes.");
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USEJETPACK);
LastJetpackCMD[playerid] = GetTickCount();
return 1;
}
You could also replace GetTickCount with the new NetStats_GetConnectedTime(playerid).