ID:178666
 
I am trying to limit the number of a certian spawn I have on the map based on the number of players in the game.

To do this I created a global variable called maxspawn and currentspawns. maxspawn is modified as players log in and log off. I have a loop setup that I am trying to get to monitor the currentspawns variable and when it drops below the value in maxspawns it will create a new spawn. This code should do it.

/proc/Random_Spawner()
while (currentspawns < maxspawns)
var/dest = pick(random_spawn)
new /obj/red_rock(dest)
++currentspawns
sleep 50

The question is how can I make this proc watch the maxspawns variable the entire time the world is running and run the code in the while loop if needed?

-Shwn
Shwn wrote:
I am trying to limit the number of a certian spawn I have on the map based on the number of players in the game.

To do this I created a global variable called maxspawn and currentspawns. maxspawn is modified as players log in and log off. I have a loop setup that I am trying to get to monitor the currentspawns variable and when it drops below the value in maxspawns it will create a new spawn. This code should do it.

/proc/Random_Spawner()
while (currentspawns < maxspawns)
var/dest = pick(random_spawn)
new /obj/red_rock(dest)
++currentspawns
sleep 50

The question is how can I make this proc watch the maxspawns variable the entire time the world is running and run the code in the while loop if needed?

-Shwn

You've almost got it...

world
New()
..()
Random_Spawner()

proc/Random_Spawner()
while (currentspawns < maxspawns)
var/dest = pick(random_spawn)
new /obj/red_rock(dest)
++currentspawns
spawn(50)
Random_Spawner()

... assuming your other pieces are in place. This will bump up your spawns to the maximum once every five seconds.
In response to Skysaw
I cannot for the life of me get this code to work

world
New()
..()
Random_Spawner()

I know that the Random_Spawner proc works fine because when I put it into a verb it is fine.

As a test I tried this

world
New()
..()
world << "Hello World"

And I get nothing???

What am I missing?
In response to Shwn
Shwn wrote:
I cannot for the life of me get this code to work

world
New()
..()
Random_Spawner()

I know that the Random_Spawner proc works fine because when I put it into a verb it is fine.

As a test I tried this

world
New()
..()
world << "Hello World"

And I get nothing???

What am I missing?
world
       New()
..()
Random_Spawner()

Indent those two like so. If they are not indented, they become procs of world.