ID:162673
 
Well, I was thinking about this recently, and I wasnt sure about how I should do this. The first thing that came to mind was .. a variable for each buff (boolean) , a variable to hold the buff timer, and a proc to take away from the timers. The only thing that comes to mind is a lot of variables being made in the future, which I dont particularly mind. Although, I was wondering if theres an easier way?
Well, provided that there is no interuption for a buff affect to statr and end, you can call the spell then use spawn() as a timer. If it is interupted, like logging out, remove the buff affect. As for the rest, just make 1 var for each buff effect. One for attack, def, or whatever you call it, instead of naming one for each spell.
In response to Pyro_dragons
Thats the thing, I wanted to make it so they could be kept when you logout and log back in. Then just restart the timers. So Im going to assume variables is the way to go? ..
In response to DivineTraveller
No.

Well, obviously variables have to be used in some way, but what you should really be doing is creating a buff datum (or obj, if you want it to have an icon you can show to the player) that will handle all the buffing / unbuffing you need.

mob
var/strength = 0
var/list/buffs

verb/test()
for(var/v = 0, v < 3, v++)
var/buff/B = new()
B.duration = 100
B.apply(src)
sleep(10)
var/savefile/F = new("test.save")
F << src
world << F.ExportText()


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

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
..()


You'll need to fiddle around with Read() and Write() some more if you want a buff that periodically ticks something, like a heal over time.
In response to Garthor
Wow. I never thought of it that way. As for the ticking, I will probably just make a seperate proc for it. One question .. if I were to assign an icon to a buff, then make a grid or something to export them to, by doing a loop through buffs, it would show it right?