ID:261747
 
I've had an annoying problem with my code for sometime now. Whenever I delete the turrent at runtime, the missle it fires stop moving and just stays in one spot untill I turn the game off.I used Malvers war_demo for this proc, and I commented everything to make sure I understood it. Well anyways here's the code...
        proc/Turret_Loop()   // the loop begins
while(src)//while the mobs in range
src << sound('rocket1i.wav')
for(var/mob/M in range(src, 5))//detect how far away it is
M.overlays -= /turf/Explosions/one // if M somehow still has overlay delete it
var/obj/Weapon/O = new src.gun//define a var named o for the weapon the turret is using
O.dir = src.dir//face the direction of the turret
O.loc = src.loc//start at the turrets location
var/turf/D = M.loc//the turf the mob its attacking is on
while(O)//while the missle exists
step_towards(O, D)//go one tile towards the turf the mob was on
var/turf/Y = get_step_towards(O, D)//the turf the missle is on
if(!Y)//if their is no turf
del(O)//delete the missle
var/turf/X = O.loc//the turf the missle on again
if(X.density && X.type != /turf/Water)//if the turf isnt water and its density is 1
del(O)//blow the missle to smithereans
for(var/mob/N as mob in X)//detect if theirs a mob on the turf the missles on
M<< sound('r_exp3.wav')
M.Damage(N, O.damage)//give damage to the mob for how much damage the missle had
M.overlays += /turf/Explosions/one//make an overlay for the mob
spawn(4)//wait .4 seconds
M.overlays -= /turf/Explosions/one//delete the overlay
del(O)//delete the missle
if(O)//if the missles still there
if(O.loc == D)//the missle gets to the turf the mob was on
del(O)//delete the missle

if(O)//if the missle is still there
sleep(O.speed)//wait the number of time the missle takes to move
if(!src)//If the turret is destroyed delete the missle
del(O)
sleep(src.rate)

Whenever the turrent which is calling this proc is deleted the proc stops running.

[Edited this post to fix the closing DM tag; you forgot the slash. - Lummox JR]
The proc stops becuase its src is the turret, and if the turret isnt there the proc terminates. You should change the missile delete code over to a proc for the missile object itself, that should help your problem.
Emperor Beld wrote:
I've had an annoying problem with my code for sometime now. Whenever I delete the turrent at runtime, the missle it fires stop moving and just stays in one spot untill I turn the game off.I used Malvers war_demo for this proc, and I commented everything to make sure I understood it. Well anyways here's the code...

Okay, the main problem you're having is that the turret has been made responsible for moving the missiles; it shouldn't be done that way. (BTW, when you use // comments, you should put some space between them and the code so people can tell where the code ends and the comment begins.)

The correct way to handle the missiles is to give them their target, tell them who fired them, and set them loose. Ideally the missile's guidance should look like this:
obj/missile
var/mob/owner

New(newloc, firedby)
owner = firedby
spawn(-1) Go()

proc/Go()
/*
This should be a loop that runs until the missile hits a
target or runs out of range. Don't forget to sleep().
*/
Another thing I'd change in your code is that the Damage proc belongs to the mob doing the damage. Why? It makes infinitely more sense to do it the other way around, where src is the mob taking damage.
mob
proc/TakeDamage(dmg, mob/attacker)
...

Lummox JR