Help with cool down timer
#1

Hello guys, could you please help me with a little cooldown timer, i was woundering if someone could help me put a cool down timer in this code
Код:
PCMD:pclass(playerid, params[])
{
    if(pInfo[playerid][PremiumLevel] < 1) return SCM(playerid, red, "You are not premium, read /premium to see information");
	GivePlayerWeapon(playerid, 24, 120);//Deagle
	GivePlayerWeapon(playerid, 9, 1);//chainsaw
	GivePlayerWeapon(playerid, 31, 500);//M4
	GivePlayerWeapon(playerid, 28, 800);//Micro
	GivePlayerWeapon(playerid, 26, 500);//sawnoff
	GivePlayerWeapon(playerid, 34, 120);//Sniper
	SetPlayerHealth(playerid, 100);
	SetPlayerArmour(playerid, 100);
	SCM(playerid, -1, "[Premium]: You have chosen premium class");
	return 1;
}
If you can thank you!
Reply
#2

You learn the most things from creating things yourself, so I'll just tell you what you should do, then I expect you're gonna try that and then we'll see futher.

* Create a player-based boolean variable (don't use PVars), called something like "HasPlayerUsedPClassCommand" (something like that, not literally, just make sure you know what the variable is for). Use the standard value 'false' (that's done by default so yeah).

* In the command, check the value of this variable. If it's true, they won't be able to use the command because the cooldown isn't over yet (Use it after the PremiumLevel thing, same way).

* If they do succeed to use the command (so if the value was false), run the command (that's just the GivePlayerWeapon stuff). After that, set the value to true.

* Now the important thing: Use a timer to reset the variable back to false. Check it out here: https://sampwiki.blast.hk/wiki/SetTimerEx

* In the callback you called with SetTimerEx(), just put the value back to false and eventually send a message to the player.

It's really simple if you know what you're doing.
Reply
#3

Another hint:
In terms of cooldown/spams/abuse/etc use the GetTickCount() instead of timers
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)