Jump to content

How to make item in a container regain durability ?


Recommended Posts

Hi,

 

I would like to make a chest that will "repair" item in it. So for example, weapon, armor and tool will regain durability when in it. The creation of a container itself is ok, but i'm not sure how to achieve the "regain durability" part. If someone has ideas or knowledge of how to do this, it would be helpful.

Ideally i would like being able to define tier of speed (quick for basic tool, normal for basic armor, slow for advanced weapon and armor) but it would just be a cherry on the cake :D

Edited by Lumina
Link to comment
Share on other sites

Was messing around and came up with this to repair items in a container.

 

local armorrepairvalue = .2 --20%
local weaponrepairvalue = .1 --10%
local toolrepairvalue = .3


--this code goes in function that triggers the repair
local items = inst.components.container:FindItems(function(v) return v.components.armor or v.components.weapon or v.components.tool end)		
for i, v in ipairs(items) do		
	if v.components.armor then			
		v.components.armor:SetPercent(v.components.armor:GetPercent() + armorrepairvalue)				
	elseif v.components.finiteuses then			
		if v.components.weapon then
			if v.components.finiteuses:GetPercent() < 1 - weaponrepairvalue then				
				v.components.finiteuses:SetPercent(v.components.finiteuses:GetPercent() + weaponrepairvalue)
			else				
				v.components.finiteuses:SetPercent(1)
			end
		elseif v.components.tool then                                                            
			if v.components.finiteuses:GetPercent() < 1 - toolrepairvalue then
				v.components.finiteuses:SetPercent(v.components.finiteuses:GetPercent() + toolrepairvalue)
			else
				v.components.finiteuses:SetPercent(1)
			end
		end
	end
end

if you want it to slowly repair them over time then you could probably use "DoPeriodicTask"

Edited by Wolf_EX
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...