Jump to content

Spawn chances

Recommended Posts

What exactly spawn chances mean?


For example, I set 0.001 to my item for crates. Does it mean that each crate have a chance 0.001 that I will see my item in it?

Share this post

Link to post
Share on other sites

Okay, here is the part of game code which spawns items in containers:

local alt = false;
local itemname = nil;
for m = 1, containerDist.rolls do
	for i, k in ipairs(containerDist.items) do
		if not alt then -- first we take the name of the item
			itemname = k;
		else -- next step is the random spawn part
			local lootModifier = ItemPicker.getLootModifier(itemname) or 0.6;
			if ZombRand(10000) <= ((((k*100) * lootModifier) + (zombieDensity * 10))) then
				-- make an item in the container of that type
				local item = ItemPicker.tryAddItemToContainer(bag:getItemContainer(), itemname);
				if not item then return end
				if instanceof(item, "Key") then
					item:setName("Key " .. item:getKeyId());
		alt = not alt;

Variable lootModifier depends on game options:

Abundant - 4
Common - 2
Normal - 1
Rare - 0.6
Extremely rare - 0.2


So spawn chance 100 (normal settings) should spawn an item always.

9999 < 100 * 100 * 1


zombieDensity variable may have value from 0 to 8.

And 8 is equal to chance 0.8

So even if you set chance 0, real chance will be up to 0.8 (normal settings) depending on location.

Minimum chance that you can set is 0.01. Ofc +0.8 from zombieDensity. So it will be minimum 0.81 if there are hords of zombies.

Let's look what it means "0.81":

By default it means 0.81% spawn chance of item for EACH ROLL.

But usually we have few rolls in settings. May be 3-5.

So real chance is 0.81 * 3 = 2.43%

0.81 * 5 = 4.05




Let me think a little.


So I set Katana chance = 0.000000000000000000000000000000000000001.

And suddenly if police storage is arounded by zombies I have 4% chance of Katana.... IN EACH CONTAINER.

Wait a minute.

How many containers are there?


So it's 40% of Katana............


I obviously miss something in this life.........


Okay, you think that on extremely rare option in settings (0.2 modifier) it will be only 8% of Katana in a police storage. And ~12 times is needed to get Katana. But you are wrong! Look at the code again! lootModifier doesn't affect zombieDensity!! So it's still 40%!

Edited by Maris

Share this post

Link to post
Share on other sites

Structure of SuburbsDistributions (Distributions.lua):

First level - room name. Special name: "all" if no room.

Second level - container name. Special names: "all" and "other".


When container is filling we have two main parameter - room name and container name (type).

  • If no room OR if no current room name exists in SuburbsDistributions, room name "all" will be used.
  • If player in a room AND there is room record in SuburbsDistributions, but there are no container records "all", "other" and container name, then room name "all" wiil be used again. So be careful. For example, there are rooms named "room1" on the map. Loot will be generated from room "all" of SuburbsDistributions.
  • If a player is in a room AND there is room record in SuburbsDistributions AND there are container record "all", "other" or container name, then this room record will be used.


When specific room of SuburbsDistributions is picked, we have 2 steps:

  1. Check container "all" if it exists in SuburbsDistributions[room]. And generate loot in container.
  2. Check container name in SuburbsDistributions[room]. And generate loot. If it doesn't exists, check name "other" and generate loot instead.

In other words, game will fill container

from SuburbsDistributions[room]["all"] + SuburbsDistributions[room][type]/SuburbsDistributions[room]["other"].


Note that SuburbsDistributions["all"]["other"] is defined for sure. So if you have new/rare container name with no loot defined at all, SuburbsDistributions["all"]["other"] will be used.


Edited by Maris

Share this post

Link to post
Share on other sites

Okey, now we understand, how loot appears in containers.

Now we can create a tool for new loot which won't break other loot.


require "Items/SuburbsDistributions"
require "Items/ItemPicker"

local IMPORT_ALL = {'clothingrack','freezer','locker','shelvesmag',
    'bin','officedrawers','metal_shelves','shelves','other'}; --no "all" but "other"
local sd = SuburbsDistributions;
local all = sd.all;
local function AddLoot(room_name,cat_name,item_name,chance,rolls)
    local r = sd[room_name];
    if not r then --all should have been used
        r = {};
        sd[room_name] = r;
        --import "all".
        for _,c in pairs(IMPORT_ALL) do
            r[c] = {
                rolls = all[c].rolls,
                items = {},
            for i,v in ipairs(all[c].items) do --copy
                table.insert(r[c].items, v);
    local c = r[cat_name];
    if not c then
        c = {
            rolls = rolls, --may be nil
            items = {},
        r[cat_name] = c;
        --import "other" if exists
        if cat_name ~= "all" then
            if r.other then
                for i,v in ipairs(r.other.items) do --copy
                    table.insert(c.items, v);
                c.rolls = c.rolls or r.other.rolls;
            elseif all[cat_name] then --import from "all"
                for i,v in ipairs(all[cat_name].items) do --copy
                    table.insert(c.items, v);
                c.rolls = c.rolls or math.max((all[cat_name].rolls or 0) + 2, 4); --higher chance in specific room
        c.rolls = c.rolls or 3; --not nil for sure
    table.insert(c.items, item_name);
    table.insert(c.items, chance);





Edited by Maris

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...