ID:179054
 
ok so I have a mod/M I want to move randomly but still keep him in a certain range on the map any sugestions how I can get this done or if its even possible
I can think of two approaches. Either use areas to restrict him like this:

mob
Blob
Move()
var/turf/new_loc = get_step(src,dir)
if(istype(new_loc,/area/blob_home)) ..()
else return

This will prevent a Blob from leaving his home. You have to define the area on the map but that should do it.

The second way would be if you wanted him to have a range restriction for his wanderings. You could do that like this:

mob
var/turf/range_center
var/max_roam = 20
New()
..()
range_center = loc
Move()
if(get_dist(get_step(src,dir),range_center) > max_roam) return
..()

This will set the mobs range center when it is created. Then, when it moves it will make sure it is within it's maximum roaming distance from it's center.
In response to English
well at first I thought I could get him to move but he wont move at all I tried some movement demos. can anyone help?
In response to Treasurecat
//still trying to get this guy to move around
mob/boothby
icon = 'person.dmi'
icon_state = "boothby"
name = "boothby"
New()
.=..()
spawn(1)
Wander()
proc/Wander()
while(src)
step_rand(src)
Wander()

mob/boothby
var/turf/range_center
var/max_roam = 20
New()
..()
range_center = loc
Move()
if(get_dist(get_step(src,dir),range_center) > max_roam) return
..()

this is the only source code I have for movement am I missing something?
In response to Treasurecat
Treasurecat wrote:
//still trying to get this guy to move around
mob/boothby
icon = 'person.dmi'
icon_state = "boothby"
name = "boothby"
New()
.=..()
spawn(1)
Wander()
proc/Wander()
while(src)
step_rand(src)
Wander()

Well, it started out good with the New(). That will call Wander to start him moving.

The problem is with the Wander proc. The first thing is that it shouldn't be under the New() proc although this may just be the byond forums butchering your spacing.

There are two problems with the Wander code itself. The first is that there is an infinite loop in the form of while(src). This means that it will excecute step_rand(src) as fast as your computer can do it until it dies. You should be using if(src) instead of while(src).

The second problem is that there isn't any delay when you call Wander within itself. Here's what it should look like:

Wander()
step_rand(src)
spawn() Wander()

It should terminate itself if the mob is killed so you shouldn't need any test statment in there. The spawn() will make the mob wait one tic (1/10 of a second) between each call of Wander.
In response to English
At tat tat! Never run the same proc over and over! Always use for() loops!

Wander()
for()
sleep(1)
step_rand(src)
It doesn't look quite as nice, but it'll keep bad things from happening around mid-game time.
In response to English
ok this is what I have now

mob/boothby
icon = 'person.dmi'
icon_state = "boothby"
name = "boothby"
New()
.=..()
spawn(1)
Wander()
proc/Wander()
step_rand(src)
spawn() Wander()

all the errors are gone but hes still not moving. what am I doing wrong?
In response to Foomer
I wonder why Deadron, Dan, and Tom say it's ok then...
In response to English
he just wont move do I need to have some kind of movement proc somwhere else?
In response to Treasurecat
ok so this seems like it would move him but no it does not

mob/boothby
icon = 'person.dmi'
icon_state = "boothby"
name = "boothby"
walk_rand()

ive tried a couple of different ways to do it I know im missing something I figured the most simple way would work
In response to Treasurecat
Treasurecat wrote:
ok so this seems like it would move him but no it does not

mob/boothby
icon = 'person.dmi'
icon_state = "boothby"
name = "boothby"
walk_rand()

ive tried a couple of different ways to do it I know im missing something I figured the most simple way would work

There's nothing to call walk_rand()
You need:
mob/boothby
icon = 'person.dmi'
icon_state = "boothby"
name = "boothby"
New()
walk_rand()

New() says "When this thing's created do..." So that'll start the walk_rand()
In response to Nova2000
ok this is what I tried

mob/boothby
icon = 'person.dmi'
icon_state = "boothby"
name = "boothby"
New()
walk_rand()

of course I tried indenting walk_rand() but it gave me error wherever I put it except for there but he still doesnt move
In response to Treasurecat
the error when I indent it is :expected 1 to 2 arguments found (0) does anyone know what that means?
In response to Treasurecat
Treasurecat wrote:
the error when I indent it is :expected 1 to 2 arguments found (0) does anyone know what that means?
Means give it some arguments. Sorry forgot that walk rand had any, anywho:
mob/boothby
icon = 'person.dmi'
icon_state = "boothby"
name = "boothby"
New()
walk_rand(src,10)
In response to Nova2000
yay hes moving thank you very much. can someone tell me why that worked? why (src,10)?
In response to Treasurecat
If you look under the F1 help it tells you what parameters you need:

Format:
walk_rand(Ref,Lag=0)
Args:
Ref: A mob or obj.
Lag: Delay in world 1/10 seconds between movement.

This tells you that you need a Ref (reference) that is either a mob or an object. In this case your telling it to use the src (in the New proc the default src is the object or mob being created) as the reference. Then it tells you to give it a lag time. This number will delay each step by whatever time you supply it. 10 would make each step delay by 1 second, 5 would make it delay by .5 seconds.

Once you get the hang of reading the F1 help it's really usefull.