ID:148552
 
Theres just a couple problems, when you get 3 or 4 mobs within range, the missile goes crazy, is there a way to select one mob within range and only track that mob? A way that will work with what I have here that is, if it wont work ill have to make it work.

    hsmissile
icon_state = "hsmissile"
New()
spawn(55)
del(src)
spawn(5)
Seek()
proc/Seek()
var/mob/M
var/N=NORTH ; var/NE=NORTHEAST ; var/E=EAST ; var/SE=SOUTHEAST ; var/S=SOUTH ; var/SW=SOUTHWEST ; var/W=WEST ; var/NW=NORTHWEST
var/one = turn(src.dir, 45) ; var/two = turn(src.dir, -45)
for(M in oview(6))
var/D = get_dir(src,M)
if(D == N) {if(src.dir == N) ..();if(src.dir == NE) src.dir = one ;if(src.dir == E) src.dir = one ;if(src.dir == SE) src.dir = one ;if(src.dir == S) src.dir = one ;if(src.dir == SW) src.dir = two ;if(src.dir == W) src.dir = two ;if(src.dir == NW)src.dir = two }
if(D == NE) {if(src.dir == N) src.dir = two ;if(src.dir == NE) ..();if(src.dir == E) src.dir = one ;if(src.dir == SE) src.dir = one ;if(src.dir == S) src.dir = one ;if(src.dir == SW) src.dir = one ;if(src.dir == W) src.dir = two ;if(src.dir == NW)src.dir = two }
if(D == E) {if(src.dir == N) src.dir = two ;if(src.dir == NE) src.dir = two ;if(src.dir == E) ..();if(src.dir == SE) src.dir = one ;if(src.dir == S) src.dir = one ;if(src.dir == SW) src.dir = one ;if(src.dir == W) src.dir = one ;if(src.dir == NW)src.dir = two }
if(D == SE) {if(src.dir == N) src.dir = two ;if(src.dir == NE) src.dir = two ;if(src.dir == E) src.dir = two ;if(src.dir == SE) ..();if(src.dir == S) src.dir = one ;if(src.dir == SW) src.dir = one ;if(src.dir == W) src.dir = one ;if(src.dir == NW)src.dir = two }
if(D == S) {if(src.dir == N) src.dir = two ;if(src.dir == NE) src.dir = two ;if(src.dir == E) src.dir = two ;if(src.dir == SE) src.dir = two ;if(src.dir == S) ..();if(src.dir == SW) src.dir = one ;if(src.dir == W) src.dir = one ;if(src.dir == NW)src.dir = one }
if(D == SW) {if(src.dir == N) src.dir = one ;if(src.dir == NE) src.dir = two ;if(src.dir == E) src.dir = two ;if(src.dir == SE) src.dir = two ;if(src.dir == S) src.dir = two ;if(src.dir == SW) ..();if(src.dir == W) src.dir = one ;if(src.dir == NW)src.dir = one }
if(D == W) {if(src.dir == N) src.dir = one ;if(src.dir == NE) src.dir = one ;if(src.dir == E) src.dir = two ;if(src.dir == SE) src.dir = two ;if(src.dir == S) src.dir = two ;if(src.dir == SW) src.dir = two ;if(src.dir == W) ..();if(src.dir == NW)src.dir = one }
if(D == NW) {if(src.dir == N) src.dir = one ;if(src.dir == NE) src.dir = one ;if(src.dir == E) src.dir = one ;if(src.dir == SE) src.dir = two ;if(src.dir == S) src.dir = two ;if(src.dir == SW) src.dir = two ;if(src.dir == W) src.dir = two ;if(src.dir == NW) ..()}
walk(src,src.dir,2)
spawn(5)
Seek()

Bump(mob/M)
if(istype(M,/mob))//if its a mob
world<<"[M] was shot by [src.owner]'s heet seeking missile."
del(src)//delete the obj that hit the mob
else
del(src)
..()<dm>
And then the verb to fire the missile is
<dm>
fire_heat_seeker()
var/obj/hsmissile/H = new(usr.loc)
H.owner = usr.name
H.dir = usr.dir
walk(H,H.dir,2)
<dm>

I'm assuming youll ask why im not working with bit flags Lummox, well i couldnt figure it out, i need some time to get used to them.
Jotdaniel wrote:
Theres just a couple problems, when you get 3 or 4 mobs within range, the missile goes crazy, is there a way to select one mob within range and only track that mob? A way that will work with what I have here that is, if it wont work ill have to make it work.

Instead of looping through mobs in Seek(), when the missile is first spawned you should give it a target right then and there. If it doesn't have one, it should go straight, possibly locking onto a target if one comes into range.
obj/hsmissile
...
var/mob/owner
var/atom/target

New(newloc,firedby)
owner=firedby
dir=owner.dir
spawn(55) del(src)
// call Seek() now so the missile will move 1 space away from firedby.loc
Seek()

proc/Seek()
// if no target yet, acquire one
if(!target)
for(var/mob/M in oview(src))
if(M!=owner)
target=M
break
if(target)
... // calculate turning here
step(src,dir)
spawn(5) Seek()

Bump(mob/M)
if(istype(M,/mob)) //if its a mob
world<<"[M] was shot by [src.owner]'s heet seeking missile."
// you call this one way or the other, so move it out of the if block
del(src)
// don't call ..(); there's no point

And then the verb to fire the missile is
fire_heat_seeker()
var/obj/hsmissile/H = new(usr.loc)
H.owner = usr.name
H.dir = usr.dir
walk(H,H.dir,2)

This wouldn't be the best way to go about this; instead, using the New() code I did above where the player who fired is a 2nd argument to new():
fire_heat_seeker()
var/obj/hsmissile/H = new(usr.loc,usr)
All you need to do is tell the missile who fired; it will make a note of who fired it, orient itself to the player's direction, and start moving on its own. I'd manually step() it each time instead of relying on walk(), though, like I did above.

I'm assuming youll ask why im not working with bit flags Lummox, well i couldnt figure it out, i need some time to get used to them.

Most of that code is cut & paste, though; it shouldn't be hard to adapt to what you have. I can't fault you for not understanding them, though; a lot of what I wrote there was brand new to me, something I'd just come up with.

Lummox JR
In response to Lummox JR
Wow, that helped a lot. Thanks, that was just what I needed, although I prefer to use walk because the missile isnt supposed to be perfect in tracking, like a real missile isnt. Thanks a lot for all the help Lummox.