Jump to content

Spawn chances


Maris

Recommended Posts

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:takeKeyId();
					item:setName("Key " .. item:getKeyId());
				end
				item:setAutoAge();
			end
		end
		alt = not alt;
	end
end

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

 

Wow!

 

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?

10?

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
Link to comment
Share on other sites

  • 4 weeks later...

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
Link to comment
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.

Spoiler

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

local IMPORT_ALL = {'clothingrack','freezer','locker','shelvesmag',
    'desk','filingcabinet','stove','microwave','medicine','wardrobe',
    'crate','counter','sidetable','fridge','vendingsnack','vendingpop',
    '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);
            end
        end
    end
    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);
                end
                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);
                end
                c.rolls = c.rolls or math.max((all[cat_name].rolls or 0) + 2, 4); --higher chance in specific room
            end
        end
        c.rolls = c.rolls or 3; --not nil for sure
    end
    table.insert(c.items, item_name);
    table.insert(c.items, chance);
end

 

 

Example:

AddLoot('pharmacystorage','counter','CureVirus.CVMag1',1);
AddLoot('dentiststorage','metal_shelves','CureVirus.CVMag1',15);

Edited by Maris
Link to comment
Share on other sites

  • 10 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...