OldManDan Posted June 6, 2024 Share Posted June 6, 2024 I have code to make a specific character more efficient with a specific set of tools, the code I use is as follows for each individual item I was wondering if I could fit multiple items into just one string instead of needing to copy and paste this a bunch of time for each individual item? Any help on condensing this would be greatly appreciated! AddPrefabPostInit("yellowstaff",function(inst) if inst.components~=nil then local old_Use = inst.components.finiteuses.Use inst.components.finiteuses.Use = function(self,val,...) if self.inst~=nil and self.inst.components~=nil and self.inst.components.inventoryitem~=nil and self.inst.components.inventoryitem.owner~=nil and self.inst.components.inventoryitem.owner.prefab == "dmagnus" then val = .5 -- set usage to 0 if it is in inventory of our character end return old_Use(self,val,...) -- call the original function now end end end) AddPrefabPostInit("opalstaff",function(inst) if inst.components~=nil then local old_Use = inst.components.finiteuses.Use inst.components.finiteuses.Use = function(self,val,...) if self.inst~=nil and self.inst.components~=nil and self.inst.components.inventoryitem~=nil and self.inst.components.inventoryitem.owner~=nil and self.inst.components.inventoryitem.owner.prefab == "dmagnus" then val = .5 -- set usage to 0 if it is in inventory of our character end return old_Use(self,val,...) -- call the original function now end end end) Link to comment https://forums.kleientertainment.com/forums/topic/156560-help-character-modding-want-to-make-code-a-little-neater/ Share on other sites More sharing options...
_zwb Posted June 7, 2024 Share Posted June 7, 2024 (edited) Explicitly define the second parameter passed into AddPrefabPostInit as a function and pass the function instead. function my_postinit(inst) -- Do stuff end AddPrefabPostInit("yellowstaff", my_postinit) Edited June 7, 2024 by _zwb Link to comment https://forums.kleientertainment.com/forums/topic/156560-help-character-modding-want-to-make-code-a-little-neater/#findComment-1720599 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