ID:144299
 
Code:
mob
proc
Jelly_Legs()
usr.random=rand(1,4)
if(usr.random==1)
usr.dir=NORTH
if(usr.random==2)
usr.dir=SOUTH
if(usr.random==3)
usr.dir=WEST
if(usr.random==4)
usr.dir=EAST
spawn() Jelly_Legs()


Problem description:
How can I stop this spawn within like 40 sec
The answer to this is pretty simple, but there's a couple other things about DM that you could use to learn about, so forgive me if I go on about what may seem unneeded.

Instead of using all those ifs, you can just use one switch statement:
var/random = rand(1, 4)
switch(random)
if(1)
do_stuff
if(2)
do_stuff


For this example, though, we don't even need to go that far:
dir = pick(NORTH, SOUTH, WEST, EAST)


The above eliminates all those if statements, and doesn't require that every mob have a variable called "random".

To make sure that your proc stops after 40 seconds, we can make a loop and put in some sleep statements:
mob/proc/Jelly_Legs()
var/time_between_changes = 10 // 1 second
var/number_of_changes = 40
for(var/count = 1 to number_of_changes)
dir = pick(NORTH, SOUTH, WEST, EAST)
sleep(time_between_changes)


That will change the mob's direction once ever second for 40 changes, or a total of 40 seconds. If you're not familiar with the use of any of those procs, you should look them up in the DM reference.