ID:164750
 
Hello I need help creating a set movement for my mobs so they rotate freely around the town I have created. Would anyone be able to help?
Like...An automatic walk?
If I understand you correctly, you want to give an NPC a predetermined path to walk along, then when the game starts you want that NPC to continuously walk along that path. Is that correct? If so...

There are several ways you can go about this depending on the game. I will give an example of the way I usually prefer to accomplish it.

First, using a datum to coordinate each movement action makes keeping track of them simple. I give the object variables to keep track of the location/direction of movement, the number of steps to take (if movement is direction rather than location), movement delay, and the next movement datum in the queue.
MovePath
var
move
steps
delay = 1
MovePath/next
proc
Move(atom/movable/M)
var/i = 0
while(i < steps)
if(isnum(move)) //If move is a direction constant (NORTH, SOUTH, etc.)
if(step(M, move)) i += 1
else
if(step_toward(M, move)) i += 1
sleep(delay)
return 1

That object can take care of a single movement-action for a movable object. An object can either walk in a specified direction for a certain number of steps, or it can be directed towards a specific object.

Then the moving object needs a way to process it. All you have to do is to give the moving object a variable to keep track of its move path, and a function to execute it.
atom/movable
var
MovePath/path
proc
MovePath()
var/MovePath/current_action = path
while(current_action)
current_action.Move(src)

If you want the path to be a loop that the object moves around forever, as it sounds like you do, you can either have a function that calls the movement-execution inside an infinite loop, or you can just have the last movement datum in a movement queue have its 'next' variable reference the first one.

Also remember that you can carry out more complex movement queues than just a simple loop. For example, you can give an object variables to reference multiple movement queues and call them in sequence.
mob/guard
var
list/patrolTower[4]
/* There are 4 towers in the castle, and each one has a seperate
movement queue for it which moves the guard from the barracks
to the tower, patrols that tower, then moves the guard back*/

proc
patrol()
while(src)
var/tower = rand(1,4) //select one of the towers at random
var/MovePath/path = patrolTower[tower]
path.Move(src)
oview(src) << "Tower [tower] clear; I'm going to rest a while."
sleep(150)