Jump to content

Recommended Posts

Hi, i was trying to change trees' loot table, but somehow this change sometimes crashes/corrupts the world to the point where some things just don't spawn at all.

I don't know why this happens, can anybody help?

THANKS!

if GLOBAL.TheNet:GetIsClient() then
    return
end

local custom_loot_table = {
    short = {
        guaranteed = { },
        random = { { "bee", 0.5 }, { "twigs", 0.5 }, { "log", 1 } }
    },
    normal = {
        guaranteed = { "log" },
        random = { { "bird_egg", 0.1 }, { "log", 1 } }
    },
    tall = {
        guaranteed = { "log", "log", "log", "pinecone" },
        random = { { "bird_egg", 0.5 }, { "rottenegg", 0.5 }, { "crow", 0.5 }, { "pinecone", 1 } }
    },
    old = {
        guaranteed = { "twigs", "pinecone", "pinecone" },
        random = { { "rottenegg", 0.1 }, { "pinecone", 1 } }
    },
    burnt = {
        guaranteed = { "coal" },
        random = { { "coal", 1 }, { "coal", 0.5 }, { "feather_crow", 0.5 } }
    },
    haunted = {
        guaranteed = { "terrorbeak" },
        random = {}
    }
}


local function SetRandomLoot(self, random)
    self.inst.components.lootdropper:SetLootSetupFn(function(lootdropper)
        for i = 1, #random do
            lootdropper:AddRandomLoot(random[1], random[2])
        end
        lootdropper.numrandomloot = 1
    end)
end

local SetLootOld

local function SetLoot(self, loots)
    local names = { "short", "normal", "tall", "old" }
    local random = {}

    if (self.inst:HasTag("burnt")) then
        random = custom_loot_table["burnt"].random
        loots = custom_loot_table["burnt"].guaranteed

    elseif (self.inst:HasTag("haunted")) then
        random = custom_loot_table["haunted"].random
        loots = custom_loot_table["haunted"].guaranteed

    else
        random = custom_loot_table[names[self.inst.components.growable.stage]].random
        loots = custom_loot_table[names[self.inst.components.growable.stage]].guaranteed
    end

    SetRandomLoot(self, random)
    SetLootOld(self, loots)
end

AddPrefabPostInit("evergreen", function(inst)
    if not GLOBAL.TheWorld.ismastersim then
        return
    end

    SetLootOld = inst.components.lootdropper.SetLoot
    inst.components.lootdropper.SetLoot = SetLoot

end)

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