SA-MP Forums Archive
Trying to make a cooldown timer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Server (https://sampforum.blast.hk/forumdisplay.php?fid=6)
+--- Forum: Server Support (https://sampforum.blast.hk/forumdisplay.php?fid=19)
+--- Thread: Trying to make a cooldown timer (/showthread.php?tid=366481)



Trying to make a cooldown timer - A7X_CEEJAY - 06.08.2012

Trying to make a cooldown timer for an engine.

What people do at the moment is they can spam start/stop engine.


How would I do so?


Re: Trying to make a cooldown timer - Universal - 06.08.2012

First of all its a wrong section.

Secondly you should use gettime() and assign it to players variable (can be SetPVarInt), then when he tries to turn/shut the engine check if the specified time has passed.

pawn Код:
SetPVarInt(playerid, "Time", gettime() + 5); // <--- 5 seconds

//---

if(gettime() > GetPVarInt(playerid, "Time"))
//do the code



Re: Trying to make a cooldown timer - Dubya - 06.08.2012

Or you can do this:

pawn Код:
// At the top of script
new EngineTimer[MAX_PLAYERS];
// Add this where it will stop them.
if(EngineTimer[playerid] > 0)  return 0;
// Add this to whenever the engine starts.
EngineTimer[playerid] = 1;
SetTimerEx("ResetEngine", 3000, false, "i", playerid);
Now the function.
pawn Код:
foward ResetEngine(playerid);
public ResetEngine(playerid)
{
    EngineTimer[playerid] = 0;
    return 1;
}