ID:155718
 
I used to know how to do this but I lost my files during a hd crash. Making an NPC wander around without going diagonal.

Thanks in advance
Hmmm...

var/ndir=pick(NORTH,SOUTH,EAST,WEST)
step(src,ndir)



Try that out.
In response to Bravo1
Thanks for replying. Do I use this with the walk_rand proc? If I use it by itself, the npcs move one step in the direction they pick. Unless I have to loop it somehow.
In response to Chaoder
Yep, just replace step with walk
In response to Bravo1
Bravo1 wrote:
Yep, just replace step with walk

Then they'll just walk in one direction :)

To use that method, you would have to set up a simple loop (and then you get the added bonus of being able to randomize how long they wait between steps)
In response to DarkCampainger
I figured walking in one direction for as long as possible was the intention. Oh well =P
You could also anchor your mobs to prevent them from walking too far from their spawn location.

mob/npc
var
max_x=2
max_y=2
turf/anchor_loc
New()
..()
anchor_loc=src.loc
spawn()walk_loop()
proc
walk_loop()
while(src)
sleep(rand(20,50))
var/stepdir=pick(NORTH,SOUTH,EAST,WEST)
switch(stepdir)
if(NORTH) if(anchor_loc.y+max_y>=y++)
step(src,stepdir)
if(SOUTH) if(anchor_loc.y-max_y<=y--)
step(src,stepdir)
if(EAST) if(anchor_loc.x+max_x>=x++)
step(src,stepdir)
if(WEST) if(anchor_loc.x-max_x>=x--)
step(src,stepdir)
In response to SuperAntx
Thanks everyone. It totally works! I'll keep this code backed up in case my PC decides to crash again.
In response to Bravo1
Yeah but that only works for Npcs who are created not already added in the game since you used the New() proc.. Isnt there a way to make a mob run a proc with out using New()?
In response to Liight
Every atom calls New() when it is created. Every atom in the map is created when the world starts. Therefor, New() is called by everything in existence once.
In response to Robertbanks2
Thank you that helped a lot ^^