ID:177521
 
Ok, so I have this problem. I want my npc's to be able to walk around town freely, but i dont want them to walk NW SW SE or NE because pc's can only walk north south east and west. So, I want the npc to walk around, but i want them to be restricted to a specific area. Like they cant walk out of area/NPC or something. I'm not sure if thats possible but if so, I'd be very appreciative if anyone could help.


-=ErdricktheGreat=-
Quite possible. :)


I'm assuming that you're using step_rand() to move your NPCs, so this tiny little tidbit of code should replace that, only allowing 4 directional movement:

step(M, pick(NORTH, EAST, SOUTH, WEST))  // Assuming 'M' is your mob that you want to move
In response to Malver
this is the code i have for it but it doesnt work.


proc/skip(mob/M as mob)
step(M, pick(NORTH, EAST, SOUTH, WEST))
sleep(20)
mob
dog
icon = 'BlackLink.dmi'
src.skip


whats wrong?

-=ErdricktheGreat=-


another thing, is there anyway to make sleep() random? like in my game it looks strange because all the npc's move at the same time. Is there a way to like make sleep(rand(10,20) or something?
In response to Erdrickthegreat2
Chances are it's because you aren't calling the proc at all. You need to call a proc in order for it to do something.
In response to Malver
um can you read this over again i just edited malver, and is there a way you can help me, how would i call the proc?
In response to Erdrickthegreat2
Maybe try something like this:

proc/Move_mobs()
for(var/mob/M in world)
if(!M.client)
spawn(rand(5, 20))
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(10)
Move_mobs()

world/New()
..()
Move_mobs()

In response to Malver
thanx