ID:271891
 
I'm trying to make a verb that will subtract a set variable (e.x hpdecrease = 2)from the users stats every second. I've tried making a messy version of it using sleep but there were many things that couldn't be done using that approach. If anyone could hint me on what to do or throw something together for me it would be greatly appreciated.




This is a system I wrote as an example of buffing:

mob
var/strength = 0
var/list/buffs

buff
parent_type = /obj
var/tmp/duration = 0
var/tmp/fadetime = 0
var/mob/target
proc
apply(var/mob/M)
target = M
if(!M.buffs)
M.buffs = list(src)
else
M.buffs += src
spawn() start()
start()
fadetime = world.time + duration
spawn(duration) end()
end()
target.buffs -= src
if(target.buffs.len == 0)
target.buffs = null //null out the list when it's empty
del(src)

Write(var/savefile/F)
..()
var/timeleft = fadetime - world.time
F["timeleft"] << timeleft

Read(var/savefile/F)
..()
var/timeleft
F["timeleft"] >> timeleft
fadetime = world.time + timeleft
spawn(timeleft) end()


strength
var/potency = 10
start()
..()
target.strength += potency
end()
target.strength -= potency
..()


So, what you'll have to do is, using the buff/strength as an example, change start() so that it calls a new proc (we'll call it tick()) that will do a loop (<code>while(fadetime > world.time) target.hp -= something; sleep(10)</code>).

Now, here's something you're going to have to be careful about: because you've got a loop, the loop will have to be started again when the buff is loaded. Therefore, you will need to change Read(), like so:

buff/healthdrain
Read()
..()
spawn() tick()


If you wish to make further buffs or debuffs, keep this in mind with relation to Read() and Write(): you have to know whether the effect of the buff is saved (such as a modification to a variable such as strength) or not saved (such as a damaging loop).