ID:140317
 
Code:
mob
villan
Wolfling
icon = 'monster.dmi'
hp = 50
strength = 15
defense = 9
var/mob
New()
. = ..()
spawn()
move()
proc/move()
while(src)
var/player_found = 0
for(mob in oview(8,src))
step_towards(src,mob)
player_found = 1
break
if(player_found != 1)
step_rand(src)
sleep(10)
sleep(5)

Bump(mob/M)
if(istype(M,/mob))
attack(M)
proc/attack(mob/M)
var/damage = rand(1,strength)
M.hp -= damage
M <<"You are being attacked by [src]!"
src.exp += rand(5,10)
src.level_up()
M.death_check(src)


Problem description:
When in testing, I get within the alotted distance, and it remains still. I can attack them, and kill them, and gain experience, but they don't move.

(I may not be describing well, i'm tired >.> Damn pi.)
for(mob in oview(8,src)) is looping through ANYTHING in oview() and assigning it to the variable mob, as mob has no type. It needs to be var/mob/something (like... var/mob/mob) in order to specifically loop through only mobs.

You probably want it to be var/mob/player/something, in fact, in order to loop through only mob/players.
In response to Garthor
I'll need to mod all my variables in place and such, but i'm gonna try it. But i'm definitely making a backup file.

Edit: I changed it a little bit, but from what i can understand, same concept. I assigned a var to all real mobs, such as me or you, and it failed -.- They did move a little, but it was only occasionally, and it was south.
In response to Magicmann
mob
villan
Wolfling
icon = 'monster.dmi'
hp = 50
strength = 15
defense = 9
var/mob
New()
. = ..()
spawn()
move()
proc/move()
while(src)
var/player_found = 0
for(var/mob/M in oview(8,src))
step_towards(src,M)
player_found = 1
break
if(player_found != 1)
step_rand(src)
sleep(10)
sleep(5)
In response to Sphinxe1
Note that this will cause them to move towards any mob, which includes other NPCs.

Also, instead of player_found, you can utilize a somewhat-obtuse aspect of for(), like so:

var/mob/M
for(M in oview(8,src))
//only players should have keys
if(M.key)
break
if(M)
step_towards(src,M)
else
step_rand(src)


When you break out of the for() loop using a break statement, the value stored in the variable will be kept from inside the loop. If it exits normally without a break, the value is set to null. Therefore, we can use if(M) to determine if we used break, which indicates we found a player.
In response to Garthor
Sphinxe1, tried yours, it somewhat worked. Though, they also were attracted to each other, and didn't attack. Garthor, when i implement the code you posted to that, Dream Seeker freezes up on me.
In response to Magicmann
That's because I was only showing an example and not a complete, working system. There are, obviously, things missing from it.
In response to Garthor
True true... Been busy with algebra and stuff like that... Will look into it, for the things making it fail after i get my stuff done...
mob
villan
Wolfling
icon = 'monster.dmi'
hp = 50
strength = 15
defense = 9
var/mob
New()
. = ..()
spawn()
move()
proc/move()
while(src)
var/player_found = 0
for(mob/var/mob/M in oview(src))
step_towards(src,M)

Bump(mob/M)
if(istype(M,/mob/))
attack(M)
proc/attack(mob/M)
var/damage = rand(1,strength)
M.hp -= damage
M <<"You are being attacked by [src]!"
src.exp += rand(5,10)
src.level_up()
M.death_check(src)

I Think thats what you need... or you want make it walk around and when it finds a mob it goes directly to that mob?
You should not use infinite loops to control AI like that, and instead adopt a "per step" control. Having many infinite loops running at once is very cpu intensive.

mob/Move()
..()
for(var/mob/npc/npc in oview(src))
if(src in oview(npc.aggro_range,npc))
npc.start_ai(src) //trigger npc's AI with respect to src


If you o ly want players to trigger AI, then do mob/player/Move() instead. If you keep it how it is, you'll want to put in checks to keep NPCs from attacking one another (unless you find great enjoyment out of it like I do, haha).