4here4 Posted January 12, 2021 Share Posted January 12, 2021 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. 1 Link to comment https://forums.kleientertainment.com/forums/topic/126031-character-specific-vanilla-item-durability/ Share on other sites More sharing options...
. . . Posted January 13, 2021 Share Posted January 13, 2021 (edited) 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) end 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) end 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 January 13, 2021 by --- -.- fixed 100 typos in code which would have caused crash it should work now Link to comment https://forums.kleientertainment.com/forums/topic/126031-character-specific-vanilla-item-durability/#findComment-1416044 Share on other sites More sharing options...
4here4 Posted January 13, 2021 Author Share Posted January 13, 2021 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 https://forums.kleientertainment.com/forums/topic/126031-character-specific-vanilla-item-durability/#findComment-1416054 Share on other sites More sharing options...
. . . Posted January 13, 2021 Share Posted January 13, 2021 4 hours ago, 4here4 said: this will only effect my character yes only your specific character Link to comment https://forums.kleientertainment.com/forums/topic/126031-character-specific-vanilla-item-durability/#findComment-1416104 Share on other sites More sharing options...
4here4 Posted January 13, 2021 Author Share Posted January 13, 2021 In that case, the code works perfectly and it's exactly what I was trying and failing to do. Thank you very much for the help. 1 Link to comment https://forums.kleientertainment.com/forums/topic/126031-character-specific-vanilla-item-durability/#findComment-1416297 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