Jump to content

Recommended Posts

have an extra petal when picking a flower

AddPrefabPostInit("flower", function(inst)    if GLOBAL.TheWorld.ismastersim then        local OldPick = inst.components.pickable.Pick        inst.components.pickable.Pick = function(self, picker)            if self.canbepicked and self.caninteractwith and picker and picker.components.inventory and self.product and picker.prefab == "mycharacter" then                self.numtoharvest = 2            end            OldPick(self, picker)        end    endend)

 

 

have an extra log when chopping tree

function EvergreenPostInit(inst)    if GLOBAL.TheWorld.ismastersim then        local oldonfinish = inst.components.workable.onfinish        inst.components.workable.onfinish = function(inst, chopper)            if chopper and chopper.prefab == "mycharacter" then                table.insert(inst.components.lootdropper.loot, "log")            end            oldonfinish(inst, chopper)        end    endendlocal trees = {"evergreen", "evergreen_normal", "evergreen_tall", "evergreen_short", "evergreen_sparse", "evergreen_sparse_normal", "evergreen_sparse_tall", "evergreen_sparse_short"}for k,v in pairs(trees) do AddPrefabPostInit(v, EvergreenPostInit) end

Edit: Don't use this method (table.insert into the loot table). I didn't realize it at the time, but the table is shared between trees, so this will cause each tree to drop an extra log. Use Jjmarco's solution below!

Edited by rezecib

@SenL, that's because everytime onfinish is called, a twig (or anything else you specified) gets added as loot for evergreens, but isn't removed afterwards. That's why you get more and more twigs everytime you cut down a tree.

Try this: instead of "table.insert(inst.components.lootdropper.loot, "log")", put this instead:

function EvergreenPostInit(inst)    if GLOBAL.TheWorld.ismastersim then        local oldonfinish = inst.components.workable.onfinish        inst.components.workable.onfinish = function(inst, chopper)            if chopper and chopper.prefab == "mycharacter" then                inst.components.lootdropper:SpawnLootPrefab("twigs")            end            oldonfinish(inst, chopper)        end    endend local trees = {"evergreen", "evergreen_normal", "evergreen_tall", "evergreen_short", "evergreen_sparse", "evergreen_sparse_normal", "evergreen_sparse_tall", "evergreen_sparse_short"}for k,v in pairs(trees) do AddPrefabPostInit(v, EvergreenPostInit) 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...