How to restrict commands with time?
#1

Lets say i have a command /kill , which i want to restrict with time (30 mins) that means the player will be only be able to use the command once in 30 minutes.? I tried something with SetTimerEx but failed? Lack of ideas.

Share your thoughts , code me if you can. Will rep you for sure.

Please reply ASAP!.
Thanks

BMiaa
Reply
#2

No time to code it, but create a variable for all players. When player types the command, set the variable to 1 and start a timer that starts in 30 minutes and doesn't loop. In the timer set the variable to 0. And in the command, check if the variable is 0, then allow the player to use the command.
Reply
#3

Quote:
Originally Posted by spedico
Посмотреть сообщение
No time to code it, but create a variable for all players. When player types the command, set the variable to 1 and start a timer that starts in 30 minutes and doesn't loop. In the timer set the variable to 0. And in the command, check if the variable is 0, then allow the player to use the command.
E.G:

pawn Код:
new usedKill[MAX_PLAYERS];

forward killTimer(playerid);

public killTimer(playerid)
{
    usedKill[playerid] = 0;
    SendClientMessage(playerid, YOUR_COLOUR, "You can now use /kill again!");
}


//In your /kill Command
if(usedKill[playerid] == 1)
    return SendClientMessage(playerid, YOUR_COLOUR, "You can only use this command every 30 minutes!");
usedKill[playerid]= 1;
SetTimerEx("killTimer", 1800000, false, "i", playerid);
However, if you have 30 players on your server and all of them have used /kill, that means you going to have 30 timers which are all set for 30 minutes - That no good : (

I'd personally use TimeStamps.

You could have one timer which repeats it self every 30 minutes. When the timer is called, it could check if the player's timestamp is equal to or small than the current timestamp.

I would show you an example, but (for me anyway)learning it can be complicated.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)