certif Posted November 4, 2023 Share Posted November 4, 2023 Is it possible to make it so tools/weapons do not lose durability when they hit walls (and fences)? Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 4, 2023 Share Posted November 4, 2023 If you want all tools/weapons to not lose durability when hitting falls/fences, then I'd hook into the function that handles that durability loss, which is the OnAttack function in the weapon component. This worked for me after a little testing: AddComponentPostInit("weapon", function(self) local _old_onattack = self.OnAttack function self:OnAttack(attacker, target, projectile, ...) if target ~= nil and target:HasTag("wall") then self.attackwearmultipliers:SetModifier("nowallattackwear", 0) else self.attackwearmultipliers:RemoveModifier("nowallattackwear") end _old_onattack(self, attacker, target, projectile, ...) end end) To explain what's going on here, I'm saving the existing OnAttack function in _old_onattack, then overriding OnAttack with my code and calling _old_onattack after it, so the previous behaviors (and other mods doing this) are unaffected. This is what is referred to as "function hooking" and it's EXTREMELY useful, I use it really often. For the other part of the code, I'm checking if the target has the "wall" tag (walls and fences do), and if it does then I'm setting a custom multiplier named "nowallattackwear" to be 0, so that there's no attack wear (since any number multiplied by 0 is 0). Otherwise, I make sure to remove my modifier if it's there, so any other existing modifiers are unaffected and the weapon still loses durability like normal. 1 1 Link to comment Share on other sites More sharing options...
certif Posted November 5, 2023 Author Share Posted November 5, 2023 Thanks again! 1 Link to comment 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