SenL Posted January 26, 2015 Share Posted January 26, 2015 Can you point me to right direction? I want my custom character to:have an extra log when chopping treeand/orhave an extra petal when picking a flower(Those only apply to my custom character) Thanks! Link to comment Share on other sites More sharing options...
rezecib Posted January 26, 2015 Share Posted January 26, 2015 (edited) have an extra petal when picking a flowerAddPrefabPostInit("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 treefunction 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) endEdit: 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 February 4, 2015 by rezecib Link to comment Share on other sites More sharing options...
SenL Posted January 26, 2015 Author Share Posted January 26, 2015 (edited) Daaaaaaaaaang. Thanks!! Edit:table.insert(inst.components.lootdropper.loot, "log")How does this work (ie: what is this "table" object)...? Edited January 26, 2015 by SenL Link to comment Share on other sites More sharing options...
Jjmarco Posted January 26, 2015 Share Posted January 26, 2015 @SenL, this is the table object of Lua. This line calls the insert method of the table objet to add the value "log" to the table inst.components.lootdropper.loot. Link to comment Share on other sites More sharing options...
SenL Posted February 4, 2015 Author Share Posted February 4, 2015 (edited) 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 February 4, 2015 by SenL Link to comment Share on other sites More sharing options...
Jjmarco Posted February 4, 2015 Share Posted February 4, 2015 @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 More sharing options...
SenL Posted February 4, 2015 Author Share Posted February 4, 2015 Yep it works.Thanks all! 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