ID:165391
 
I need a turf that checks the spaces around it, or even the world for a certain number of a certain monster. When this number goes below what it should be it waits a few minutes and respawns another monster in its place. I have a basic idea of what it should look like but Im not sure...
proc/monstercheck()
for(/mob/monster/slime/s in world)
if(s<s.population)
sleep(1000)
new/mob/monster/slime

I havent tested the above code, its only what I think it would look like to do the above mentioned.
I think it would be like this:

proc/monstercheck() // Proc name. (Duh)
var/population // This will be the variable of the total slimes in the world.
for(/mob/monster/slime/M in world) // For each slime in world,
population ++ // Add 1 to the population.
if(population < poplimit) // If the total of slimes is under max..
sleep(1200) // Wait 2 minutes.
new /mob/monster/slime // Create a new slime, you will have to define where though.


This isn't tested, but I believe it should work.
In response to Masuko Shintaro
Masuko Shintaro wrote:
I think it would be like this:

> proc/monstercheck() // Proc name. (Duh)
> var/population // This will be the variable of the total slimes in the world.
> for(/mob/monster/slime/M in world) // For each slime in world,
> population ++ // Add 1 to the population.
> if(population < poplimit) // If the total of slimes is under max..
> sleep(1200) // Wait 2 minutes.
> new /mob/monster/slime // Create a new slime, you will have to define where though.
>

This isn't tested, but I believe it should work.

Would I set the population limit under the slime, or as a global var? Also to set the new slimes location i'd just set
new/mob/monster/slime loc=locate(?,?,?)

right?
or would it need to be?
new/mob/monster/slime/s
s.loc=locate(?,?,?)
In response to FriesOfDoom
Both will have the same effect, by default, so just use the former; note that you're incorrect; the methods go like this:
//first
new /mob/monster/slime(locate(1,1,1))

//second
var/mob/monster/slime/s = new
s.loc=locate(1,1,1)


(LOOK PROCS UP BEFORE USING THEM!)

Also, you will probably want to sleep() at the beginning of the proc, because now you sleep after you determined the number of slimes in the world, and by the time you finish sleeping, that can indeed change. As I got it, you'll also want the proc to run in an infinite loop [as long as the 'src' turf still exists] - put all of it in a "for()" or "while(1)" statements (both have the effect of creating an infinite loop).
In response to Kaioken
I have the slimes spawning.....but they're going crazy! Every time they multiply! Whats wrong with my code? I'm calling the proc when a new slime is made.
mob/proc/slimecheck()
sleep(15)//this is temporary
for(var/mob/monster/Slime/S in world)
S.population+=1
if(S.population<S.poplimit)
new/mob/monster/Slime(locate(8,29,2))
slimecheck()
In response to FriesOfDoom
nvm.....fixed it, except now, if I kill all of the slimes, the proc no longer replaces them.