Jump to content

More loot if character is X


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
Link to comment
Share on other sites

I changed from giving extra log to "twigs" but now I get 1-3 twigs instead of just 1 (want only 1).

Odd...

 

Edit:

Haha it's 1 at first then 2, then 3...

I'm guessing I shouldn't put this in modmain?

Edited by SenL
Link to comment
Share on other sites

@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
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
 Share

×
  • Create New...