Jump to content

Recommended Posts

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)

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 by _zwb

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...