Jump to content

Character-Specific Vanilla Item Durability

Recommended Posts

Hello, I was hoping I could get help with this problem I've been having. I'm trying to find advice on how to give an item infinite durability, but only when it's being held by my custom character. There are a lot of threads out there I've found that deal with infinite durability, but they only touch on what to do with custom items. I only want the vanilla Dark Sword and vanilla Night Armor to have infinite durability, and only when being held by my custom character. I'm stumped on how to go about this or if it's even possible. Any help is greatly appreciated. Thank you.

  • GL Happy 1
Link to comment
Share on other sites

I think maybe this can work.

inst:ListenForEvent("onattackother", function(inst)
	local weapon = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
	if weapon and weapon.prefab == "nightsword" then
		local percent = weapon.components.finiteuses:GetPercent()
		weapon:DoTaskInTime(0, function() weapon.components.finiteuses:SetPercent(percent+.01) end)

inst:ListenForEvent("attacked", function(inst)
	local armor = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
	if armor and armor.prefab == "armor_sanity" then
		local percent = armor.components.armor:GetPercent()
		armor:DoTaskInTime(0, function() armor.components.armor:SetPercent(percent+.01) end)

put them both inside the master_postinit in yourcharactername.lua

what it does is basically when you get hit and wear night armor the armor's durability is restored fully and when you attack someone with a dark sword its durability fully restored. It's not exactly infinite durability, but it basically is the same since the stuff will have infinite durability when used by the character


I just edited code cause I realized if the armor or sword is really broken it will go back to fully durability you probably don't want. New code idk if 100% works but it should just add 1% when used to basically you use no durability of the stuff.

Edited by --- -.-
fixed 100 typos in code which would have caused crash it should work now
Link to comment
Share on other sites

Wow! Thank you so much for such a prompt and profoundly helpful response. I had to tweak the armor percent value slightly higher, as many attacks take off more than 1% of its durability, but otherwise this works perfectly! If I understand correctly, since it's my character's lua listening for when it attacks or is attacked, this will only effect my character, correct? I wouldn't want this to break the game for the people I play with.

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

  • Create New...