BlackORG Posted February 27, 2022 Share Posted February 27, 2022 (edited) Hello everyone! I'm little stuck with my problem: I want to insert some loot in zombie corpses, BUT I also want to apply a "modifer" to a chance, based on SandboxVars Loot Rarity (or Server Settings - Loot Rarity). Here is my test mod (text formatting may be borked, not my fault ): require 'Items/SuburbsDistributions' -- For every loot category spawn chance modifier is based on Server Settings - Loot Rarity -------------------------------------- -- Rarity Chance modifier -- 1 (Extremely Rare) 100% -- 2 (Rare) 80% -- 3 (Normal) 60% -- 4 (Common) 40% -- 5 (Abundant) 20% -------------------------------------- local modifiers = { 1, 0.8, 0.6, 0.4, 0.2 } local invTables = { male = SuburbsDistributions["all"]["inventorymale"].items, female = SuburbsDistributions["all"]["inventoryfemale"].items } local testAdditionalLoot = { FoodLoot = { ["Base.Crisps"] = 100, -- these values are just for tests ["Base.Chocolate"] = 100 }, CannedFoodLoot = {}, WeaponLoot = { ["Base.HandAxe"] = 100, ["Base.Axe"] = 100 }, RangedWeaponLoot = {}, AmmoLoot = {}, MedicalLoot = {}, SurvivalGearsLoot = {}, MechanicsLoot = {}, LiteratureLoot = {}, OtherLoot = {} } local function InsertAdditionalLoot() for gender,inventory in pairs(invTables) do for category,lootTable in pairs(testAdditionalLoot) do for name,chance in pairs(lootTable) do print("Inserting '" .. name .. "'(".. category ..") into SuburbsDistributions[all][inventory".. gender .. "] with spawn chance = " .. chance .. " (Modifer: ".. modifiers[SandboxVars[category]] ..")") table.insert(inventory, name) table.insert(inventory, chance * modifiers[SandboxVars[category]]) end end end end local function PrintSandboxVars() print("Loot Rarity Variables:") print("Fresh Food:\t\t", SandboxVars.FoodLoot) print("Canned Food:\t", SandboxVars.CannedFoodLoot) print("Melee Weapons:\t", SandboxVars.WeaponLoot) print("Ranged Weapons:\t", SandboxVars.RangedWeaponLoot) print("Ammo:\t\t", SandboxVars.AmmoLoot) print("Medical:\t\t", SandboxVars.MedicalLoot) print("Survival Gears:\t", SandboxVars.SurvivalGearsLoot) print("Mechanics:\t\t", SandboxVars.MechanicsLoot) print("Literature:\t\t", SandboxVars.LiteratureLoot) print("Other:\t\t", SandboxVars.OtherLoot) end local function InitMod() PrintSandboxVars() InsertAdditionalLoot() end If I run my mod just adding this at the end: InitMod() Everything works, BUT SandboxVars Loot Rarity values all set by default (which is 2), so in this example all additional loot has spawn chance of 80. From DebugLog (PrintSandboxVars): [27-02-22 17:08:03.215] LOG : General , 1645970883215> Loot Rarity Variables:. [27-02-22 17:08:03.216] LOG : General , 1645970883216> Fresh Food: 2. [27-02-22 17:08:03.216] LOG : General , 1645970883216> Canned Food: 2. [27-02-22 17:08:03.217] LOG : General , 1645970883217> Melee Weapons: 2. [27-02-22 17:08:03.217] LOG : General , 1645970883217> Ranged Weapons: 2. [27-02-22 17:08:03.218] LOG : General , 1645970883218> Ammo: 2. [27-02-22 17:08:03.218] LOG : General , 1645970883218> Medical: 2. [27-02-22 17:08:03.219] LOG : General , 1645970883219> Survival Gears: 2. [27-02-22 17:08:03.220] LOG : General , 1645970883220> Mechanics: 2. [27-02-22 17:08:03.220] LOG : General , 1645970883220> Literature: 2. [27-02-22 17:08:03.221] LOG : General , 1645970883221> Other: 2. If I use in-game lua events like these: Events.OnGameStart.Add(InitMyMod) -- or -- Events.OnInitWorld.Add(InitMyMod) Distribution table doesn't change (no additional loot on zombie corpses), BUT SandboxVars Loot Rarity values show their real values. From DebugLog (PrintSandboxVars): [27-02-22 17:08:07.662] LOG : General , 1645970887662> Loot Rarity Variables:. [27-02-22 17:08:07.662] LOG : General , 1645970887662> Fresh Food: 2. [27-02-22 17:08:07.662] LOG : General , 1645970887662> Canned Food: 2. [27-02-22 17:08:07.663] LOG : General , 1645970887663> Melee Weapons: 1. [27-02-22 17:08:07.663] LOG : General , 1645970887663> Ranged Weapons: 1. [27-02-22 17:08:07.663] LOG : General , 1645970887663> Ammo: 1. [27-02-22 17:08:07.663] LOG : General , 1645970887663> Medical: 1. [27-02-22 17:08:07.663] LOG : General , 1645970887663> Survival Gears: 1. [27-02-22 17:08:07.663] LOG : General , 1645970887663> Mechanics: 1. [27-02-22 17:08:07.663] LOG : General , 1645970887663> Literature: 1. [27-02-22 17:08:07.663] LOG : General , 1645970887663> Other: 1. Is what I'm trying even possible? I assume SandboxVars object (table) is initialized AFTER "SuburbsDistributions" is populated with stuff. Edited February 27, 2022 by BlackORG Added missing piece to the code (invTables) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now