Dante12129 Posted April 24, 2017 Share Posted April 24, 2017 I am trying to cause trees to drop extra charcoal when they burn. Currently, I have an ImproveTree function that sets up more logs on finished chopping and also tries to give more charcoal when the tree is chopped. It works for logs, with all trees dropping extra logs when chopped down, but for some reason I can't figure out, extra charcoal is only being dropped for trees I spawn in, not trees generated at world gen or grown from their seeds. Does anyone know why charcoal isn't working for non-spawned trees? ImproveTree: Spoiler local function ImproveTree(inst) --Do these when the tree is fully chopped local seed_chance = GetModConfigData("treeseedchance", KnownModIndex:GetModActualName("More Drops")) local oldonfinish = inst.components.workable.onfinish inst.components.workable:SetOnFinishCallback(function(inst, chopper) --Drop base logs utils.DoTimes(GetModConfigData("extralogs", KnownModIndex:GetModActualName("More Drops")), inst.components.lootdropper.SpawnLootPrefab, inst.components.lootdropper, "log") --Have a chance to spawn the appropriate seed item if inst.name == "Evergreen" and inst.components.growable.stage ~= 1 then if utils.DropLootRandom(inst, "pinecone", seed_chance) then print("Dropped seed") end elseif inst.name == "Birchnut Tree" and inst.components.growable.stage ~= 1 then if utils.DropLootRandom(inst, "acorn", seed_chance) then print("Dropped seed") end elseif inst.name == "Twiggy Tree" and inst.components.growable.stage ~= 1 then if utils.DropLootRandom(inst, "twiggy_nut", seed_chance) then print("Dropped seed") end end --Spawn extra logs for tall trees if inst.components.growable.stage == 3 then utils.DoTimes(GetModConfigData("extralogstall", KnownModIndex:GetModActualName("More Drops")), inst.components.lootdropper.SpawnLootPrefab, inst.components.lootdropper, "log") end oldonfinish(inst, chopper) end) --Do these when the tree is burnt local oldonburnt = inst.components.burnable.onburnt inst.components.burnable:SetOnBurntFn(function(inst) --Drop a charcoal when burnt for i = 1, GetModConfigData("extracharcoal", KnownModIndex:GetModActualName("More Drops")) do inst.components.lootdropper:SpawnLootPrefab("charcoal") end oldonburnt(inst) end) end Relevant section of modmain: Spoiler local trees = {"evergreen", "evergreen_sparse", "deciduoustree", "twiggytree"} for i,v in pairs(trees) do AddPrefabPostInit(v, utils.Bind(utils.RunFunctionServerOnly, ImproveTree)) end Link to comment Share on other sites More sharing options...
Aquaterion Posted April 25, 2017 Share Posted April 25, 2017 maybe try inst.prefab instead of inst.name? as if i remember correctly, trees have different names for each growth stage Link to comment Share on other sites More sharing options...
Dante12129 Posted April 26, 2017 Author Share Posted April 26, 2017 Well I am using inst.name so that the seed drops will be applied regardless of stage prefab and only on the growth based on its growth stage because all trees generated in the world are the same base 'evergreen' prefab. But that part of the code is working fine. It's the charcoal-dropping part that doesn't work on world gen-spawned trees, and that's doesn't depends on a check to inst.name. Link to comment Share on other sites More sharing options...
Aquaterion Posted April 28, 2017 Share Posted April 28, 2017 did u try it? Link to comment Share on other sites More sharing options...
CarlZalph Posted April 28, 2017 Share Posted April 28, 2017 (edited) Just looking at the evergreens prefabs you're missing quite a few: tree("evergreen", "normal", 0), tree("evergreen_normal", "normal", 2), tree("evergreen_tall", "normal", 3), tree("evergreen_short", "normal", 1), tree("evergreen_sparse", "sparse", 0), tree("evergreen_sparse_normal", "sparse", 2), tree("evergreen_sparse_tall", "sparse", 3), tree("evergreen_sparse_short", "sparse", 1), tree("twiggytree", "twiggy", 0), tree("twiggy_normal", "twiggy", 2), tree("twiggy_tall", "twiggy", 3), tree("twiggy_short", "twiggy", 1), tree("twiggy_old", "twiggy", 4), tree("evergreen_burnt", "normal", 0, "burnt"), tree("evergreen_stump", "normal", 0, "stump") You might consider just having a generic hook any prefab post init and checking against having the "tree" tag instead for ease and future update portability. Edited April 28, 2017 by CarlZalph 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