ID:2174539
 
(See the best response by Kozuma3.)
Code:
turf/grass
icon='grass.dmi'
mob/Monsters/
Rat
icon='rat.dmi'
Bat
icon='bat.dmi'

var/list/spawnlist=list(new/mob/Monsters/Rat,new/mob/Monsters/Bat)

turf
Spawn
Entered(mob/M)
if(istype(M,/mob))
var/mob/spawnpicker=pick(spawnlist)
new spawnpicker.type(src)


Problem description:
Hi there! I re-joined byond the other day and my fondness for it back in the day and overall nostalgia has happily lead me to make the leap to learn programming! Onto my issue however. My spawn works, but unfortunately, both the rats and bats spawn reoccurring-ly with every single step in the spawn zone. I've referenced the DM guide but I'm not exactly sure where I should be looking and how to mock up the code from this point to makeshift for an low probable encounter chance. I'd appreciate any senior/intermediate programming direction and or help on the matter!
Best response
You could have multiple lists each containing a specific type of creature and have a variable that you can switch() that will allow you to pick from a specific list.

You can also for probability do something like.
if(prob(2)) //2% chance to be TRUE
In response to Kozuma3
Kozuma3 wrote:
You could have multiple lists each containing a specific type of creature and have a variable that you can switch() that will allow you to pick from a specific list.

You can also for probability do something like.
if(prob(2)) //2% chance to be TRUE


Firstly, thank you for responding so quickly!

I settled with the if(prob(2), I feel almost embarrassed that it could have been that easy this entire time. The multiple list for creature types definitely sounds more interesting(and organized) so you can bet I'll look more into doing that.

Thank you Kozuma3!
You can also use pick() and set specific probs for each monster.
I usually tab and not space out my work... ..and am on a phone so bear with me haha.
pick(
prob(60)
new/mob/Monsters/Rat(src.loc)
prob(40)
new/mob/Monsters/Bat(src.loc)
)


This might be an easier method to start with and is my preferred way of doing things. Might not end up being better in the long run - beats me.
You can also add a ..() instead of a spawn to make a chance for nothing to spawn.