ID:1244162
 
(See the best response by Albro1.)
Code:
mob
proc
Kaitendps()
loop
if(src.inKaiten)
for(var/mob/Z in oview(2))
var/damage = src.Tai*2.12
Z.health -= damage
view(Z)<< "<b><font size=1 face=verdana color=red>[Z] was hit by [src]'s Hakkesho Kaiten for [damage] damage!"
sleep(15)
Z.Death(src)

if(Z == null)
return

if(!usr.inKaiten)
usr<<"<font size=1><font face=verdana><font color=white>Your rotation has stopped."
return
goto loop


Problem description:
Sigh* How do I make it so that when the target is no longer in oview(2) the loop stops? it goes infinite loop whenever the target goes out of range or if there is no target.
Best response
Step one: Don't use goto. Ever.

Step two: I would recommend using a while() loop to keep it going while inKaiten is true.

As for the target, just do a check at the beginning of the for() loop - if(!Z) break. So something like this could be done:

mob
var/kaiten=FALSE, kaiten_time=10
proc/kaiten()
kaiten = TRUE
spawn(kaiten_time) kaiten = FALSE
while(kaiten)
for(var/mob/m in oview(2,src))
if(!m) break


One key thing in there to note: oview(2,src).
Take special care in just doing oview(2), because the default argument for the Center is usr, and depending on where this procedure is being called from, using usr could cause some funky output or even make it not work.

EDIT: You should also add a sleep delay in that while() loop so it isn't doing damage every tick. That would be devastating.
I tried something like this. But then it doesnt call mob in oview(2). src just spins but never does the damage

mob
proc/Kaitendps()
if(src.inKaiten)

sleep(Kaiten_time)
src.inKaiten = 0
src<<"<font size=1><font face=verdana><font color=white>Your rotation has stopped."
return

while(src.inKaiten)

for(var/mob/Z in oview(2))
var/damage = src.Tai*2.12
Z.health -= damage
view(Z)<< "<b><font size=1 face=verdana color=red>[Z] was hit by [src]'s Hakkesho Kaiten for [damage] damage!"
Z.Death(src)
sleep(15)

if(!Z)
break
In response to Mitz001
You should probably move that sleep out of the for() loop but still in the while() loop.

You need to use spawn(Kaiten_time), not sleep(Kaiten_time). Press F1 in Dream Maker to read the differences.

Did you read what I said about oview()?

You also don't need that return statement.

Put the if(!Z) check at the beginning of the loop, or you're going to get runtime errors.