ID:1379255
 
(See the best response by Nadrew.)
Problem description: I need help making a mob spawning proc since i'm going back on working with my game Zombie Survival.

Best response
The most ideal method is by using a spawner object, which you can place on the map.

obj
zombie_spawner
var
spawn_type = /mob/zombie
spawn_delay = 20 // Seconds
proc
SpawnLoop()
while(src)
new spawn_type(src.loc)
sleep((spawn_delay*10))
New()
..()
spawn(1) SpawnLoop()
This is my code

obj
zombie_spawner
icon='Objects.dmi'
icon_state="ZS"
var
Make
spawn_type = /mob/Zombies/Zombie
spawn_type2 = /mob/Zombies/Quick_Zombie
spawn_delay = 20 // Seconds
proc
SpawnLoop()
while(src)
pick(1,2)
if(1)
Make = spawn_type
world << Make
if(2)
Make = spawn_type2
world << Make
new Make(src.loc)
sleep((spawn_delay*10))
New()
..()
spawn(1) SpawnLoop()


It's only letting the quick zombies actually being made i don't know why i know this because of the color of the zombies eyes and the speed.
In response to -._.DreamBunny._.-
The statement pick(1,2) on its own does nothing. Both if (1) and if (2) will evaluate as true because they're truthy values. The quick zombie is always spawned because BYOND executes code from top to bottom, so quick zombie is what Make ends up being set to (because the if (2) block is executed last and is seen as true).

You'd want to store the result of pick() in variable and then check against that variable in the if statements you have.
you could just use Rand(1,2) then go from there
In response to Chumble93
Not really?

"You'd want to store the result of pick() in variable and then check against that variable in the if statements you have."

^ would still apply if he replaced pick with rand. Technically if he doesn't want a var he could just do if(prob(50)).
rand() isn't the best way to go about having a random type picked for spawning for sure, neither is the usage of pick() you're using. You'd want to do something like

var/list/spawn_types = list(/mob/Zombies/Zombie,/mob/Zombies/Quick_Zombie)


Then inside of SpawnLoop() you'd have something like

var/picked_zombie = pick(spawn_types)
new picked_zombie(src.loc)


This way, you can easily expand the types of zombies that can be spawned or even make children types like

obj
zombie_spawner
// Main code here
hard_zombies
spawn_types = list(/mob/Zombies/Super_Zombie,/mob/Zombies/Mega_Zombie)


Or something of that nature, I'm sure you can figure it out.
Best Choice ^^^^^^ Go with him he seems to be the most experienced so far :P
In response to -._.DreamBunny._.-
Nadrew's advice is probably what you should go with, but I want to help you understand what went wrong with your original method (LordAndrew touched on this, but I'm not sure his response will make any sense to someone without experience):

-._.DreamBunny._.- wrote:
This is my code

>                   pick(1,2)
> if(1)
> if(2)
>


As already mentioned, this structure does nothing (at least not what you think it does)

The reason is that there is no connection between this pick() and the following if()s. You have only instructed your program to do the following:

1) Pick a number, 1 or 2 (but do nothing with it; without anything connected to this value, it just floats off into nothing)
2) Check if 1 is true (and select one zombie type)
3) Check if 2 is true (and select the quick zombie type)

Those if() checks, without something to tie them to the pick(), are completely ignorant of what that pick() did. They do not care, because they weren't told to care. They're just checking the number 1 and the number 2 to see if they are TRUE values (all non-zero numbers are TRUE, so both of these if() statements pass) Since the one that picks the quick zombies comes last, that's the one that gets to set the final value into "Make" (the code is sticking the regular zombie type into Make by the first if(), but then the second if() changes it)

In order to tie them to the pick()ed value, you need to do one of two things:

1) set up a temporary variable to store the pick()ed number, then use that variable's value in the if() checks.

var/whatever=pick(1,2)
if(whatever==1)
//make regular zombie
if(whatever==2)
//make quick zombie


2) Use our handy friend, switch(), which is a convenient way to shorten the example above.

switch(pick(1,2))
if(1)
//make regular zombie
if(2)
//make quick zombie


Those two methods are how you would connect your pick() value to your if() checks to actually make them use the number that was picked.

But again, Nadrew's method is probably better all-around, anyway, so I would drop this method and go with that. But like I said, just so you can better understand why your code didn't work (it will come up in other cases!)