I'm looking to add a delay to certain actions within my code so it doesn't repeat.
So my death check method appends experience to the player... If you spam click the command in the panel it will appear as many times as you can click it in 3 seconds (Since I'm using sleep(3) for all obs so I can append death animations) It also still deals damage when the npc is dead
TLDR; Need to figure out a way to have a delay in this proc so players can only receive xp once & disallow damage to keep being dealt.
http://prntscr.com/bpo0jm
Code:
proc
DeathCheck()
if (src.HP <= 0)
usr << "You killed [src] and gained [src.expAmount] experience!"
src.icon_state = "death"
sleep(30)
experience += expAmount
del(src)
verb
Attack(mob/M as mob in oview(1))
usr << "You attack [M]!"
var/damage = usr.strength - M.defence
if(damage <= 0)
usr << "[M] easily dodges your attack!"
else
M.HP -= damage
usr << "You deal [damage] damage!"
M:DeathCheck()
All you really need here is a simple var that says whether the mob is dead or not.
When you call DeathCheck(), be sure to send the killer as an argument.
Eventually, you may find you've expanded the possible states beyond just death, to include unconsciousness, swimming, flying, etc. If so, you may want to look into using a single state var that has different states as bitflags. But that's for later consideration.