ASK CMD
#1

hey i wanna ask , how to make cmd just can use only 1x ?
if player already use cmd and he can't use it again and must wait 20 minutes for use it again.
thanks
rep ++
Reply
#2

Make some kind of variable that is either true or false: for example commandCooldown. This will track if the user can use the command or still has to wait.

When the user uses the command, the command will check if the cooldown variable is 0. If it is, do whatever the command needs to do, set the cooldown variable to 1 and start a 20 minute timer. When the timer runs out, simply let it change the players cooldown variable back to 0, so the command doesn't give an error anymore.

That clear enough for you?
Reply
#3

still make me confused . can give a little bit example ?
thanks before
Reply
#4

Something like this, on top of script:
Код:
new commandcd[MAX_PLAYERS];
when player use command:
Код:
if(commandcd[playerid] == 1) return SendClientMessage(playerid, -1, "Wait 20 mins.");
commandcd[playerid] = 1;
SetTimerEx("command", 1000*60*20, false, "i", playerid);
on the last line:
Код:
forward command(playerid);
public command(playerid)
{
commandcd[playerid] = 0;
return 1;
}
Reply
#5

Allright, here's some pseudo-code:

Код:
new commandCooldown[MAX_PLAYERS]; // The variable that tells us if the cooldown is active.

OnPlayerConnect(playerid)
{
	commandCooldown[playerid] = 0; // Disable the cooldown when the player joins the game.
}

CMD:myCooldownCommand(params[], playerid)
{
	if(commandCooldown[playerid] == 0)
	{
		// Do what the command needs to do.

		// Start a timer here for how long it needs to cool down.

		// Also, set the cooldown to 1.
		commandCooldown[playerid] = 1;
	}
	else
	{
		// Display an error, eg. "You must wait blah blah".
	}
}

myTimerFunction(playerid)
{
	// Stop the timer and disable the cooldown.
	commandCooldown[playerid] = 0;
}
This should give you a rough idea of what i mean.
Reply
#6

Using timers is a bad idea. It's better using unix timestamp:
pawn Код:
// global
new Cmd_Timer[MAX_PLAYERS];

// OnPlayerConnect:
Cmd_Timer[playerid] = 0;

// in command:
if (Cmd_Timer[playerid] && gettime() < Cmd_Timer[playerid]) return // error message about waiting
// code from the command and in last line:
Cmd_Timer[playerid] = gettime() + 1200;
Reply
#7

rep given thanks all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)