ID:2023355
 
/*
The elements of a cooldown are simple. You do not want a certain action
to be completed within a certain time bound. As such, it boils down to
two things:
1. A binary value
2. A timer

The way I often see this done is through a series of ifs and spawns and
it can get messy. So I present this intuitive cooldown timer
*/


value = 0 // 0 means allowed action
valueCD = 0 // Default

mob/verb/DoThing(var/time)
// Do the thing
if(value != 1)
value = 1
spawn() Cooldown()
valueCD = world.timeofday + time

mob/proc/Cooldown()
while(valueCD > world.timeofday)
sleep(1)
value = 0


The main reason I put this up was because I didn't see a cooldown in the snippet directory.