ID:148944
 
My turret will not fire on enemies. It will follow them around (changing dir to aim at it) but it wont fire, heres the code can anyone tell me whats wrong?

turret
icon = 'Blue Tank.dmi'
icon_state = "btank"
name = "turret"
HP = 40
var/think_delay = 15
New()
..()
spawn(rand(1,think_delay)) AILoop()
proc/AILoop(mob/M)
for(M in oview(src)) break
if(!M)

spawn(think_delay) AILoop()
return

if(get_dist(src,M) > 5)
spawn(think_delay) AILoop()
else
var/D = get_dir(src.loc,M.loc)
if(istype(M,/mob/red))
src.dir = D
new/obj/blaser(src.loc)
for(var/obj/blaser/L in src.loc)
walk(L,src.loc,2)
spawn(think_delay) AILoop()
else
spawn(think_delay) AILoop()
I did this in Warzone's Turret code.
obj
missles
missle
icon = 'bullet.dmi'
mob/turret
team = "blue"
icon = 'turret.dmi'
New()
.=..()
spawn(1)
src.Fire()
proc/Fire()
while(src)
for(var/mob/M in oview(4))
if(src.team == M.team) ..()
else
missile(/obj/missles/missle,src.loc,M.loc)
view(5) << sound('SOUND2.WAV')
break
sleep(10)
spawn(20)
src.Fire()
src.Fire()


Alatar
In response to Alatar
Thats good, but i dont want to use the missile proc. I want the person to be able to dodge the laser thingy. I really want to know why my code wont work.
Jotdaniel wrote:
new/obj/blaser(src.loc)
for(var/obj/blaser/L in src.loc)
walk(L,src.loc,2)

The first two lines are completely screwed up. The only possible reason to loop through every laser at that spot--which is incorrect behavior--is because you didn't assign the new laser to L in the first place, as you should have. The correct code has been shown in enough places--even recently--that you should have no trouble finding it. Do a search on "projectile".

Beyond that, the reason your laser isn't moving is because you're telling it to walk toward the spot it's already at (src.loc), so it won't ever move.

Lummox JR
In response to Lummox JR
OOPS. Thank you for pointing that out, I meant src.dir. Gee i feel stupid now. Ohwell, thanks man.