ID:568246
 
(See the best response by Robertbanks2.)
I want to set a variable when a potion is consumed then after an amount of time has passed, unset the variable. Here is what I have right now. Don't mind the indention.
                    usr.hp+=src.restorehp
usr << "The potion has restored [src.restorehp]HP!"
usr.hppotionused=1
usr << output(null, "inventory.freehand")
usr.UpdateInv()
usr.UpdateFreehandLabel()
del(src)
spawn(50)
usr.hppotionused=0


Only problem is that the src seems to be deleted before the countdown starts. I have to get rid of the item when it's used... Is there a way to do this? Thanks.
Do the spawn() before the del(). Unlike sleep(), spawn() doesn't stop everything else. It just sets an internal timer that executes what is indented beneath the spawn() when it is up. Everything else executes as normal.
Best response
Make a simple countdown proc that handles different cooldown delays, then call that proc before deleting the object.

A good way of handling this would be to make a list of cooldowns, then pass the cooldown type(as a text string) and duration as arguments when calling the proc. Doing things this way will allow you to very easily implement more cooldowns without repeating code, adding new variables, or running into any other problems like what you're having now.
Albro, I tried that and it didn't seem to work.

Robert, thanks for the suggestion. I was thinking about something like that.
As Albro said, simply place the spawning before the deletion. Since the src is deleted, the spawn will never happen. However, if you make it start the countdown before deleting it, the var will still unset after the src is deleted.

                    usr.hp+=src.restorehp
usr << "The potion has restored [src.restorehp]HP!"
usr.hppotionused=1
usr << output(null, "inventory.freehand")
usr.UpdateInv()
usr.UpdateFreehandLabel()
spawn(50)
usr.hppotionused=0
del(src)