ID:140016
 
Code:
    usr.freezem = 1 //keeps user from moving,
var/obj/Earth_Dragon/Head/H = new()
H.loc = get_step(usr,usr.dir) //putting it where I want,
H.dir = usr.dir //face same direction.
spawn(8) //wait for the animation to finish
usr.freezem = 0 //allow user to move while the attack finishes.
spawn()
var/C = 5 //fire 5 times
while(C)
sleep(rand(2,9))
var/obj/jutsu/Earth/Earth_Dragon/Spikes/S = new() //Creating the spikes to fire,
S.caster = usr
C --
S.loc = get_step(H,H.dir)
world <<"boom"
if(!C)
del(H)


Problem description:
I'ce come to the forums in order to ask for a favor. As it seems, the code above is not working. What it is supposed to do, is create a sort of Dragon made of earth, that appears infront of the user. Then it's supposed to shoot 5 spikes in that direction. After the dragon is created, and placed, the user is allowed to move around. How ever, there seems to be a problem, as when I test the code, the game crashes, and refuses to respond. From what I could tell, the dragon is created, and placed in the correct location. How ever, what seems to be killing the game is the spikes. I would like advise from the community to assist me in this code.
Please help, and Thank you in advance.
Seeing what you do in the New() proc for the spikes would be helpful.
In response to Garthor
Yes, of course, sorry about that.
Spikes
icon_state = "spike"
New()
pixel_y = rand(-25,25)
pixel_x = rand(-25,25)
while(src)
spawn(2) walk(src,dir)
Bump(T)
if(T == typesof(/mob))
for(var/mob/M in world)
if(M == src.caster)
M << "Your Spikes hit [T]"
else continue
del(src)
else
del(src)
for(var/mob/M in world)
if(M == src.caster)
M << "Your Spikes hit [T]"

As you can see, the spikes are in an icon state named "spike". When created the displacement of the pixels are random, and while it exists, it continues to move in the direction it faces. When it colides with a dense atom it deletes itself, and says what or who it hit.
Ah, as it turns out, I've fixed my problem. The crashing was do to the procedure trying to redo the same thing so many times over at the same time, due to me useing spawn() instead of sleep(), during the while() proc. I would also not of seen the problem if I had not looked at the New() proc for the spikes. Thank you anyways.
In response to RageFury33
Note that there's no reason to repeatedly do walk(src,dir), as walk() automatically continues walking (unlike step(), which only takes one step).