ID:856636
 
(See the best response by Kaiochao.)
Code:
    enemy/Beast
icon = 'new base.dmi'
Health = 1200
Strength = 120
Control = 50
Powerlevel = 75
Harmful = 1
New()
.=..()
sleep(1)
src.NPCSYS()

mob/enemy
proc
NPCSYS()
// if(src == /mob/enemy/Beast)
var/mob/m
if(m in oview(5,src))
walk_towards(src,m,15,0.9)
spawn(1) src.NPCSYS()
else
walk_rand(src,25,0.9)
..()
spawn(1) src.NPCSYS()


Problem description:
As you can see in the above, i want the NPC to walk_rand, but if it spots a mob with 5 tiles away i want it to walk_towards it. When i run the game all it does is just walk_rand, ;(, a little help?

instead of using if use for(var/mob/M in oview())
Best response
When you used the if(), it's checking if 'null' is in oview(). This makes sense because you declared m and never set a value to it.

The simplest way to get a nearby mob is to look for one. This can be done with the locate() proc, or even a for() loop.
// e.g. locate()
var mob/m = locate() in oview(5, src)
// m is now either null, or the first mob found using 'in'.

// e.g. for() loop, more flexible than locate()
var mob/m // to be found
for(m in oview(5, src))
if(m is not a mob to be looking for)
continue
break
// because of 'break', m either has the last mob to be
// searched, or null if none have been found.