Jump to content

Example (41.52): ProceduralDistributions, Distributions, VehicleDistributions


lordixi

Recommended Posts

In 41.51 many mods are broken due new distribution system.

Here working distribution example for 41.52 for little mod "Siphoning Needs Hoses (build 41)".

File media\lua\server\Items\RubberHose_Distributions.lua

 

require "Items/Distributions"
require "Items/ProceduralDistributions"
require "Vehicles/VehicleDistributions"

local i, j, d

-- Distributions for ProceduralDistributions.lua
local myDistTable = {
  "CrateMechanics", 100, 
  "CrateTools", 100,
  "GarageTools", 100,  
  "StoreShelfMechanics", 100,
  "MechanicShelfTools", 100,
  "MechanicShelfMisc", 100,
  "GigamartTools", 100,
--"KitchenRandom", 100,
--"GarageMechanic", 100,  
}

for i = 1, #myDistTable, 2 do 
  table.insert(ProceduralDistributions.list[myDistTable[i]].items, "Base.RubberHose")
  table.insert(ProceduralDistributions.list[myDistTable[i]].items, myDistTable[i+1])
end

-- Distributions for Distributions.lua. May be broken in next updates due devs going to ProceduralDistributions
myDistTable = nil
myDistTable = {
  {"all",{
    "metal_shelves",100,
    "crate",100,
    "bin",100,
    }
  },
  {"armyhanger",{
    "metal_shelves",100,
    "counter",100,
    "locker",100,
    }
  },
  {"storageunit",{
    "all",100,
    }
  },
  {"toolstore",{
    "shelves",100,
    "counter",100,
    }
  },
}

for i, d in ipairs(myDistTable) do
  print(d[1]);
  for j = 1, #d[2], 2 do
    table.insert(Distributions[1][d[1]][d[2][j]].items, "Base.RubberHose")
    table.insert(Distributions[1][d[1]][d[2][j]].items, d[2][j+1])
    print(d[1],d[2][j]);
  end   
end

myDistTable = nil
myDistTable = {
  "Bag_SurvivorBag",100,
  "Toolbox",100,
  "Bag_JanitorToolbox",100  
}
for i = 1, #myDistTable, 2 do
  table.insert(Distributions[1][myDistTable[i]].items, "Base.RubberHose")
  table.insert(Distributions[1][myDistTable[i]].items, myDistTable[i+1])
end

-- Distributions for VehicleDistributions.lua. May be broken in next updates due devs going to ProceduralDistributions
myDistTable = nil
myDistTable = {
  "GloveBox", 100,
  "TrunkStandard", 100,
  "TrunkHeavy", 100,
  "TrunkSports", 100,
  "SurvivalistTruckBed", 100,
  "FossoilTruckBed", 100,
}

for i = 1, #myDistTable, 2 do  
  table.insert(VehicleDistributions[myDistTable[i]].items, "Base.RubberHose")
  table.insert(VehicleDistributions[myDistTable[i]].items, myDistTable[i+1])
end

myDistTable = nil

 

Edited by lordixi
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
On 8/15/2021 at 7:37 PM, Nebula said:

How do you regulate the probability of an item appearing (if there are several different items) in this example?

Number past container name is probability.

"metal_shelves",100,

 

I set 100 in example just for test, to see that item 100% appear.

 

Now in work code first table looks like:

local myDistTable = {
  "CrateMechanics", 10, 
  "CrateTools", 6,
  "CrateMetalwork", 6,
  "CrateFarming", 6,
  "GarageTools", 10,
  "GarageMetalwork", 10,
  "GarageMechanic", 10,    
  "StoreShelfMechanics", 10,
  "GardenStoreTools", 8,
  "MechanicShelfTools", 8,
  "MechanicShelfMisc", 8,
  "GigamartTools", 4,
  "GigamartFarming", 6,
}

 

Edited by lordixi
Link to comment
Share on other sites

  • 2 months later...

Been a while since I looked at PZ, but I have a mod.

 

You're joking right? There is no backwards compatibilty for code like this below? 

I see there is a SuburbsDistributions.lua still in PZ41, so hopefully not. This would break TONS of mods if not. 

require 'Items/SuburbsDistributions'

table.insert(SuburbsDistributions["fossoil"]["shelvesmag"].items, "Base.BedfordMap");
table.insert(SuburbsDistributions["fossoil"]["shelvesmag"].items, 0.2); 

table.insert(SuburbsDistributions["all"]["shelvesmag"].items, "Base.BedfordMap");
table.insert(SuburbsDistributions["all"]["shelvesmag"].items, 0.1); 

 

Link to comment
Share on other sites

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