(See the best response by Kaiochao.)
Hi everyone,
I'm new to Byond and I have followed a tutorial to make a PvE game and I want to make a spawner so that you never run out of mobs. As there were 2 enemies in this tutorial (Although, I have added more myself), I want to know who to make this spawner be able to spawn all of them, but the harder to defeat the enemies, the lower chance it has. I have been looking throughout the forums and none of them meets my criteria.
Thank you in advance
Best response
If you know ahead of time how relatively difficult enemies are, you can use a weighted pick to randomly choose what type of enemy to spawn:
var/list/enemy_type_weights = list(
/mob/enemy/weak = 3,
/mob/enemy/normal = 2,
/mob/enemy/strong = 1,
var/enemy_type = pickweight(enemy_type_weights)
new enemy_type(loc)

edit: bolded link for clarity
Um... pickweight isn't a built in function? Are you using this:

proc/pickweight(list/L)    // make this global
var/total = 0
for(item in L)
if(!L[item]) L[item] = 1 // if we didn't set a weight, call it 1
total += L[item]
total=rand(1, total)
for(item in L)
if(total <= 0) return item
return null // this should never happen, but it's a fallback
In response to Magicsofa
Magicsofa wrote:
Um... pickweight isn't a built in function? Are you using this:

@Kaiochao has linked to a library called pickweight, which already has this function