Jump to content
Dr_Cox1911

Distribution-files, explanation?

Recommended Posts

Greetings,
 
can someone explain me how the distribution-files like "suburbdistribution.txt" work?
Are the following assumptions correct?
 

module SuburbsDistribution{imports {Base //What does this do?}validmaps{50_50, //What does this do?} containeritemdistribution //Defining the container-typ (like counters, shelfs,...)?{Room =  shed, //Defining a special room (optional)?Containers =  counter, //Refering to the container the following entries apply to?Hammer =  1, //Chance that the item will spawn (in percent)?Plank =  10,Nails =  12,}

Share this post


Link to post
Share on other sites

Base imports the Base module so you can call the items defined in that module (e.g.: Base.Screwdriver).

The 50_50 value defines for which map area it is valid (IIRC).

 

 

If you want to spawn items I'd use the lua method:

table.insert(SuburbsDistributions["Kitten"]["counter"].items, "NotEnoughBags.PaperBag");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 5);

Share this post


Link to post
Share on other sites

Thanks for the explanation!

I already can spawn items (with the methods you mentioned but want to understand the "inside" of PZ.

For example what the number stands for (e.g. how PZ tosses the dice for lootspawn).

Share this post


Link to post
Share on other sites

Thanks for the explanation!

I already can spawn items (with the methods you mentioned but want to understand the "inside" of PZ.

For example what the number stands for (e.g. how PZ tosses the dice for lootspawn).

 

The inside of PZ is a scary and beautiful place :o:D

 

Well the exact "math" for the filling is:

ItemPicker.rollItem = function(containerDist, container)    if containerDist ~= nil then        -- we are looking for the zombie density in this area, more zombie density mean more loots        local zombieDensity = 0;        local chunk = getWorld():getMetaChunk((getPlayer():getX()/10), (getPlayer():getY()/10));        if chunk then            zombieDensity = chunk:getLootZombieIntensity();        end        local alt = false;        local itemname = nil;        for m = 0, 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;                --~                     print (itemname);                else -- next step is the random spawn part                    if ZombRand(10000) <= ((((k*100) * ZomboidGlobals.LootModifier) + (zombieDensity * 10))) then                        -- make an item in the container of that type.                        local item = container:AddItem(itemname);                        item:setAutoAge();                    end                end                alt = not alt;            end        end    endend
I'd suggest you take a closer look at the ItemPicker.lua file ;)

 

As I said the validmaps value defines for which part of the whole world grid this distribution list works. The farmingdist for example has a valid_maps value of 49_48.

EDIT: For completeness, there also is some distribution handling in the java source but I'm not sure if and to what extend it is (still) used.

Share this post


Link to post
Share on other sites

 

Greetings,

 

can someone explain me how the distribution-files like "suburbdistribution.txt" work?

Are the following assumptions correct?

 

module SuburbsDistribution{imports {Base //What does this do?}validmaps{50_50, //What does this do?} containeritemdistribution //Defining the container-typ (like counters, shelfs,...)?{Room =  shed, //Defining a special room (optional)?Containers =  counter, //Refering to the container the following entries apply to?Hammer =  1, //Chance that the item will spawn (in percent)?Plank =  10,Nails =  12,}

 

That file shouldn't be there. It's existence is a mistake. It's outdated and unused. Distributions are done in the lua files now as RoboMat explains

Share this post


Link to post
Share on other sites

That file shouldn't be there. It's existence is a mistake. It's outdated and unused. Distributions are done in the lua files now as RoboMat explains

 

Ah that's great to know, thanks lemmy :)

 

On that note, may I ask if the script system will be oberhauled / kept for item creation or will it be totally replaced with lua?

Share this post


Link to post
Share on other sites

Ah that's great to know, thanks lemmy :)

 

On that note, may I ask if the script system will be oberhauled / kept for item creation or will it be totally replaced with lua?

 

Aww what's wrong with the way it works now? :( This would force me to learn lua, which would be good, but I like the scripting system.

Share this post


Link to post
Share on other sites

I didn't say there was anything wrong with it ;)

 

So is there talk if it changing? If so, that's gonna suck, cuz I got stuff made already. I rally need to quit talking about learning lua and just learn it lol.

Share this post


Link to post
Share on other sites

I don't think we're gonna change this system, it's working pretty well and easy to understand.

 

Thanks for the info RJ :)

 

 

Ah, thanks for the clarification lemmy andRoboMat!

 

So the "SuburbsDistributions.lua" is the right place for spawnstuff.

 

That's correct.

 

table.insert(SuburbsDistributions["Kitchen"]["counter"].items, "NotEnoughBags.PaperBag");table.insert(SuburbsDistributions["Kitchen"]["counter"].items, 5);

 

The above code just inserts new values to the tables originally defined in the SuburbsDistributions.lua :)

Share this post


Link to post
Share on other sites

Hmm, so when exactly do these two lines need to be called to change the spawn distribution? I suppose some of the early pre map loading events?

If I undertand your question correctly, you don't need any events for the table insertion. Just create a file called YourMod_Distribution and insert all the spawn stuff there. As an example here is my complete Distribution file from my Lockpicking mod:

-- ================================================-- LOCKPICKING-- created by RoboMat-- ================================================table.insert(SuburbsDistributions["all"]["bin"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["bin"].items, 3);table.insert(SuburbsDistributions["all"]["counter"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["counter"].items, 5);table.insert(SuburbsDistributions["all"]["inventorymale"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["inventorymale"].items, 2);table.insert(SuburbsDistributions["all"]["inventoryfemale"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["inventoryfemale"].items, 2);table.insert(SuburbsDistributions["all"]["desk"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["desk"].items, 10);table.insert(SuburbsDistributions["all"]["filingcabinet"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["filingcabinet"].items, 8);table.insert(SuburbsDistributions["all"]["officedrawers"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["officedrawers"].items, 10);table.insert(SuburbsDistributions["Kitten"]["counter"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 5);

That's all it needs.

 

P.S.: Just to be clear ... the file-name isn't mandatory for the Distribution to work, but it's nice to have an organized code ;)

Share this post


Link to post
Share on other sites

If I undertand your question correctly, you don't need any events for the table insertion. Just create a file called YourMod_Distribution and insert all the spawn stuff there. As an example here is my complete Distribution file from my Lockpicking mod:

-- ================================================-- LOCKPICKING-- created by RoboMat-- ================================================table.insert(SuburbsDistributions["all"]["bin"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["bin"].items, 3);table.insert(SuburbsDistributions["all"]["counter"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["counter"].items, 5);table.insert(SuburbsDistributions["all"]["inventorymale"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["inventorymale"].items, 2);table.insert(SuburbsDistributions["all"]["inventoryfemale"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["inventoryfemale"].items, 2);table.insert(SuburbsDistributions["all"]["desk"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["desk"].items, 10);table.insert(SuburbsDistributions["all"]["filingcabinet"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["filingcabinet"].items, 8);table.insert(SuburbsDistributions["all"]["officedrawers"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["all"]["officedrawers"].items, 10);table.insert(SuburbsDistributions["Kitten"]["counter"].items, "Lockpicking.BobbyPin");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 5);

That's all it needs.

 

P.S.: Just to be clear ... the file-name isn't mandatory for the Distribution to work, but it's nice to have an organized code ;)

 

 

Remember to change the "Kitten" to "k-i-t-c-h-e-n" without the -.... Don't want stuff to spawn inside of our kitty kats.

Share this post


Link to post
Share on other sites

If I undertand your question correctly, you don't need any events for the table insertion. Just create a file called YourMod_Distribution and insert all the spawn stuff there. As an example here is my complete Distribution file from my Lockpicking mod:

That's all it needs.

 

P.S.: Just to be clear ... the file-name isn't mandatory for the Distribution to work, but it's nice to have an organized code ;)

 

Couldn't that be problematic if Suburbsdistribution.lua is not parsed first?

 

What I don't quite understand is where and when the new spawn rules take effect. If I add

 

table.insert(SuburbsDistributions["JohndoughsKitchen"]["fridge"].items, "JohndoughsMod.CanOfBeer");table.insert(SuburbsDistributions["JohndoughsKitchen"]["fridge"].items, 5);

and then load up an old saved game where I am standing in a JohndoughsKitchen - do I then suddenly get a 5% chance of having a beer in my fridge? This is probably a stupid question, but anyway...

Share this post


Link to post
Share on other sites

Well if you want to be sure you can add require 'Items/SuburbsDistributions' to the top.

 

Do you have a JohndoughsKitchen in the game? ;) It also will only work for containers that haven't been filled yet.

Share this post


Link to post
Share on other sites

Do you have a JohndoughsKitchen in the game?

 

No, unfortunately not yet, only Johndough beer.  :cool:

 

  ;) It also will only work for containers that haven't been filled yet.

 

And which containers would that be, exactly? The ones that haven't yet been opened?

Share this post


Link to post
Share on other sites

No, unfortunately not yet, only Johndough beer.  :cool:

 

 

And which containers would that be, exactly? The ones that haven't yet been opened?

 

I'm not sure exactly but I think it fills the containers in the room you are currently in (might be wrong here). To be sure I'd simply move to the next house and try the containers there ;)

Share this post


Link to post
Share on other sites

I'm not sure exactly but I think it fills the containers in the room you are currently in (might be wrong here). To be sure I'd simply move to the next house and try the containers there ;)

 

Oh, that wouldn't work. I've been everywhere. And the few places I haven't been, I can't remember. 

 

I guess I need to do some testing. Asking questions usually saves a lot of time though :)

Share this post


Link to post
Share on other sites

And which containers would that be, exactly? The ones that haven't yet been opened?

well that depends.

mostly the containers that you haven't ever been near and now are loaded into the game (screen is nearly the same as the loaded objects field)

 

if the container isn't been loaded ever since the creation of the world it will use the distribution code that has the now new table additions

(it goes without saying that the table only is changed when you restart the game and the scripts are ran.)

 

best advice if your testing is to just create a new world.

Share this post


Link to post
Share on other sites

I tested with both an old world and a new, with a 100% chance of spawning a new item.

 

Without the require... none of my new items would spawn (possibly because my mod starts with C and is loaded before the Items directory).

 

The items would not spawn in containers I had already opened. They would, however, spawn in containers inside rooms I had visited(without opening the container). Old or new world didn't matter. 

Share this post


Link to post
Share on other sites

Im having issues with my new File it will not spawn anything at all. tried new game and old game nothing :( i know its a typo but i have looked at it for hours and cant find it.

 

require "Items/SuburbsDistributions"; JerkyMod = {}JerkyMod.version = "1.0.1";JerkyMod.author = "Shivster";JerkyMod.modName = "Jerky Mod"; function Jerky.init()print("Mod Loaded: " .. JerkysMod.modName .. " by " .. JerkyMod.author .. " (v" .. JerkyMod.version ..")");end table.insert(SuburbsDistributions["Kitten"]["counter"].items, "Jerky.Salt");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 10);table.insert(SuburbsDistributions["Kitten"]["counter"].items, "Jerky.Pepper");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 10);table.insert(SuburbsDistributions["Kitten"]["counter"].items, "Jerky.Soysauce");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 10);table.insert(SuburbsDistributions["Kitten"]["counter"].items, "Jerky.Worcestershire");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 10);table.insert(SuburbsDistributions["Kitten"]["counter"].items, "Jerky.Liquidsmoke");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 10);table.insert(SuburbsDistributions["Kitten"]["counter"].items, "Jerky.Garlicpowder");table.insert(SuburbsDistributions["Kitten"]["counter"].items, 10); Events.OnGameBoot.Add(JerkyMod.init);

 

 

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.

Guest
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.

Loading...

×
×
  • Create New...