ID:169931
 
I was wondering how to implement spell lag, as..say..a precast. The code for my spells are as follow:

    proc/FireBolT()
if (MP < 1+(fireboltlevel*2))
usr << "Not enough MP"
else // if you have enough MP
//find the closest enemy
var/list/J[1]
var/C = 1
var/mob/enemies/M
for(M as mob in oview(3))
if (istype(M,/mob/enemies))
J[C] = M
C++
J.len++
if(J[1]!=null) // if you found one
MP -= 1+(fireboltlevel*2) // decrement MP by cost
M = J[1] // reference to the enemy
missile(/obj/spells/firebolt,usr,M) // visuals
sleep(get_dist(usr,M)) // wait until the spell reaches the enemy
var/damage = round(((rand(2+(fireboltlevel*2),4+(fireboltlevel*3)))*((Intelligence/100)+1)),1) // calculate dmg
if(M) // exception catching, have to make sure that the enemy is still there
if (M.firewk>0) // if it is weak against fire
damage = round(damage*(1+(M.firewk/100)),1) // do more damage
if (M.fireres>0) // if it has resistance to fire
damage -= round(damage*(M.fireres/100),1) // do less damage
M.HP -= damage // actually deal the damage
s_damage(M, damage, "red") // and show it
//usr << "You cast FireBolt for \blue[damage] damage"
DeadEnemy(M) // checks to see if the enemy is dead
sleep(attackspeed)


And before :
wizspells 
verb
FireBolt()
set category = "Spells"
FireBolT()


I was hoping sleep(something) would work, but i'm not quite sure on where to put it. Help?

I'm at school right now, so send me a page.
You could use either sleep or spawn.
wizspells 
verb
FireBolt()
set category = "Spells"
spawn(10) FireBolT()

or
wizspells 
verb
FireBolt()
set category = "Spells"
sleep(10)
FireBolT()


Both of theese will wait 1 second before casting the spell.
For more information on the two procs go here:
http://www.byond.com/docs/ref/info.html#/proc/spawn
http://www.byond.com/docs/ref/info.html#/proc/sleep

That should help :)