ID:149968
 
Alright, this is really getting old. I have worked for days straight trying to get spell effects in order. I will explain the spells system...
First, a player chooses a class, which gets certain spells and skills that other classes don't get. This part is already fully debugged and working. After this, they practice the spell in target, say haste, which switches a var on to allow an extra attack in battle. Now, this spell is not availible in battle, as it requires too much concentration to cast, so outside of battle, they use the cast verb, cast "haste". Now the cast verb checks each spell, with very repetitive code, checking such things as whether or not they are the proper level, are they in battle, etc. Finally, it gets to the casting portion, now, how would I add this effect, and remove it after say 5 minutes? I checked out the effect demo of ... well, I forgot, but it's like the only effect demo :P. This allowed a person to use an effect anytime, and I couldn't figure out how to work it in conjunction with my cast code. Somebody please help!

Polatrite Solus - Assassini Coronae (What does THAT mean??)
Polatrite wrote:
Alright, this is really getting old. I have worked for days straight trying to get spell effects in order. I will explain the spells system...
First, a player chooses a class, which gets certain spells and skills that other classes don't get. This part is already fully debugged and working. After this, they practice the spell in target, say haste, which switches a var on to allow an extra attack in battle. Now, this spell is not availible in battle, as it requires too much concentration to cast, so outside of battle, they use the cast verb, cast "haste". Now the cast verb checks each spell, with very repetitive code, checking such things as whether or not they are the proper level, are they in battle, etc. Finally, it gets to the casting portion, now, how would I add this effect, and remove it after say 5 minutes? I checked out the effect demo of ... well, I forgot, but it's like the only effect demo :P. This allowed a person to use an effect anytime, and I couldn't figure out how to work it in conjunction with my cast code. Somebody please help!

Polatrite Solus - Assassini Coronae (What does THAT mean??)

If you are refering to mine, all im doing is attaching an associative value* to each spell which holds its duration, and sleep()ing a proc for that long.

* Check out Lummox Jr's Associative Lists article at BYONDscape

Alathon
Polatrite wrote:

Now the cast verb checks each spell, with very repetitive code

If you have very repetitive code, you can almost always write it in a much more compact form. That's not related to your question though, so I'll carry on.

how would I add this effect, and remove it after say 5 minutes?

The easiest way is to use sleep() or spawn() to create the delay, then remove the effect.

// haste effects
target.speed *= 2 // double speed

spawn(3000) // wait 5 minutes
target.speed /= 2 // divide by two to return to normal speed

If you have save files, this could cause real problems though. The save file will save your increased speed, but not the spawned proc to return it to normal.

In Darke Dungeon, I use an assosciated list to store spell effect names and durations. During the player's lifecycle (something like Deadron's eventcycle demo) I check the effects list to see if any of them have expired.

// haste effects
if("haste" in target.effects) // in it's most basic form, this method won't allow you to double up on spells.
src << "[target] is already hasted."
return
target.speed *= 2 // double speed
target.effects["haste"] = world.time + 3000 // set the timer for 5 minutes from now


// somewhere in the player's lifecycle
for(var/Effect in effects)
if(world.time > effects[Effect]) RemoveEffect(Effect)


mob/proc/RemoveEffect(Effect as text)
effects -= Effect // remove it from the effects list
switch(Effect)
if("haste")
speed /= 2
src << "You feel much slower."
// other effects here


To preserve relative times for saved characters, you should subtract world.time from each effect duration before saving and add world.time to the duration when you load. Otherwise, if a player saves when a server has been running for a while then loads the character right after a server reboot, the player would have the effect for a much longer time. world.time resets to 0 when the server starts.