ID:261324
 
My monster wont come after me;

mob
var
Var = 1
mob
icon = 'Icons.dmi'
icon_state = "Player"

mob/other
monster
icon = 'Icons.dmi'
icon_state = "Monster"
var
movement = 3

New()
look()
dillydally()
..()
proc
look()
for(var/mob/M as mob in oview())
if(M.Var >= 1)
walk_towards(M,src,movement)
else
look()
return ..()
dillydally()
walk_rand(src,movement)
look()

turf
icon = 'Icons.dmi'
icon_state = "Grass"

My monster wanders around....but doesnt come after me. Whats wrong with it? (It being the code, not the monster ;))

The Bearded One
Read my code snippet i posted earlier, asking for help on.


<font color="red"> Super saiyan3

I Have A Beard wrote:
My monster wont come after me;
...
proc
look()
for(var/mob/M as mob in oview())
if(M.Var >= 1)
walk_towards(M,src,movement)
else
look()
return ..()

I see a few problems here:

  • oview() defaults to something like oview(6,usr), and usr is inappropriate for this case. I'd try oview(6,src) instead. (BTW, you shouldn't need to use "as mob", since the variable already has a /mob type.)
  • The M and src in walk_towards are in the wrong order. This will make M walk toward the monster.
  • It's probably a good idea to return immediately after calling walk_towards(), so you don't continue through the loop to find other targets.
  • The recursive call to look() after else will cause an infinite loop if the first mob in oview() has M.Var<1. You can safely eliminate the entire else block. (The call to ..() is also redundant, since this proc isn't overriding anything.)

    Hope that helps you.
    One thing you might want to keep in mind with code like this is that the same mob might not always be the best target, and sometimes a monster may dither between two targets, trying to decide which is best. If you decide to get fancy with the code later, you can add an algorithm to figure out which mob is closest, or the most "attractive" target (like, maybe your monster can smell blood and home in on a hurt player); it also couldn't hurt to add a temporary target var to the monster, and set that, so that subsequent calls to look will simply short-circuit to following that target as long as it's in view. (I.e., your code could be used to set target=M and start the monster walking, then another if could be set up to always check for a target first. So the monster looks around, finds a likely victim, and follows it relentlessly from there out.)

    Lummox JR
In response to Lummox JR
oview() defaults to something like oview(6,usr), and usr is inappropriate for this case. I'd try oview(6,src) instead. (BTW, you shouldn't need to use "as mob", since the variable already has a /mob type.)

Teensy correction... it defaults to oview(world.view, usr). =)

Also, you can simply use oview(src).