timer on commands
#1

Код:
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
Reply
#2

someone?
Reply
#3

Try this:

PHP код:
CMD:jetpack(playeridparams[])
{
    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;

Reply
#4

Quote:
Originally Posted by Deny1
Посмотреть сообщение
someone?
You use settimerex https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#5

Quote:
Originally Posted by d3ll
Посмотреть сообщение
Try this:

PHP код:
CMD:jetpack(playeridparams[])
{
    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)
Reply
#6

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(playeridparams[])
{
    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).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)