Tesumoto Posted April 20, 2018 Share Posted April 20, 2018 (edited) Hello! I want for all my selected prefabs in the line: inst.components.workable: SetWorkLeft ("number") Replace "number" with "number * TUNING.MY_FIRMNESS" Can you help me with this? Thank you for your attention. Edited April 20, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
IronHunter Posted April 20, 2018 Share Posted April 20, 2018 (edited) Using addprefabpostinit we can make a function to add this feature to all your prefabs local workableprefabs = {"spoiled_food","spoiled_fish", "mosquitosack", "silk", "spidergland", "poop", "stinger", "cutgrass", "twigs", "guano"} --prefab examples, change to your own. for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) if GLOBAL.TheWorld.ismastersim then --if not inst.components.workable then inst:AddComponent("workable") end --not really needed if your prefabs have the workable component already. if inst.components.workable then inst.components.workable:SetWorkLeft ("number") end end end) end Edited April 20, 2018 by IronHunter Link to comment Share on other sites More sharing options...
Tesumoto Posted April 20, 2018 Author Share Posted April 20, 2018 (edited) 41 minutes ago, IronHunter said: Using addprefabpostinit we can make a function to add this feature to all your prefabs local workableprefabs = {"spoiled_food","spoiled_fish", "mosquitosack", "silk", "spidergland", "poop", "stinger", "cutgrass", "twigs", "guano"} --prefab examples, change to your own. for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) if GLOBAL.TheWorld.ismastersim then if not inst.components.disappears then inst:AddComponent("workable") end if inst.components.workable then inst.components.workable:SetWorkLeft ("number") end end end) end This function change the SetWorkLeft for all prefabs by the number that I specify? Can not change this number from prefabs, but simply multiply by 3? I use this code: local workableprefabs = { "pigtorch", "ancient_altar_broken" } --prefab examples, change to your own. for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) if GLOBAL.TheWorld.ismastersim then if not inst.components.disappears then inst:AddComponent("workable") end if inst.components.workable then inst.components.workable:SetWorkLeft(20) end end end) end But these things just stopped to react to the hammer and the others. (become indestructible) Edited April 20, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
IronHunter Posted April 20, 2018 Share Posted April 20, 2018 (edited) 44 minutes ago, Tezumoto said: This function change the SetWorkLeft for all prefabs by the number that I specify? Can not change this number from prefabs, but simply multiply by 3? I use this code: local workableprefabs = {"pigtorch","ancient_altar_broken"} for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) if GLOBAL.TheWorld.ismastersim then if not inst.components.disappears then inst:AddComponent("workable") end if inst.components.workable then inst.components.workable:SetWorkLeft(20) end end end) end But these things just stopped to react to the hammer and the others. (become indestructible) I made a typo when copy/pasting my similar code, instead of disappears it should be workable, as for why they are indestructable local workableprefabs = {"pigtorch","ancient_altar_broken"} for k,v in pairs(workableprefabs) do AddPrefabPostInit(v, function(inst) if GLOBAL.TheWorld.ismastersim then if inst.components.workable then inst.components.workable:SetWorkLeft(2) end end end)end I just tested this it works fine for me, object updated properly and hammers correctly Edited April 20, 2018 by IronHunter Link to comment Share on other sites More sharing options...
Tesumoto Posted April 20, 2018 Author Share Posted April 20, 2018 (edited) 28 minutes ago, IronHunter said: I made a typo when copy/pasting my similar code, instead of disappears it should be workable, as for why they are indestructable I just tested this it works fine for me, object updated properly and hammers correctly I can, don't change the default value, but just multiply it by a certain value? if inst.components.workable then inst.components.workable:SetWorkLeft(*2) end Edited April 20, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
IronHunter Posted April 20, 2018 Share Posted April 20, 2018 1 minute ago, Tezumoto said: I can, don't change the default value, but just multiply it by a certain value? if inst.components.workable then inst.components.workable:SetWorkLeft(*2) end A strange request but I guess you could do inst.components.workable.workleft = inst.components.workable.workleft * 2 Link to comment Share on other sites More sharing options...
Tesumoto Posted April 20, 2018 Author Share Posted April 20, 2018 (edited) 6 hours ago, IronHunter said: A strange request but I guess you could do inst.components.workable.workleft = inst.components.workable.workleft * 2 Thank you, you helped me a lot. But still I have some problems. I need to create two separate functions to forbid: 1) "repairable" and 2) "workable" for prefabs. Edited April 21, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
JohnWatson Posted April 24, 2018 Share Posted April 24, 2018 you can use AddComponentPostInit instead of AddPrefabPostInit if you want to change a value for all entities with the workable component 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