TerriFried Posted December 24, 2019 Share Posted December 24, 2019 (edited) I have already got the item set for tuning, I just want to know how to make the durability (out of 100) affect the damage (out of 40). At the moment the weapon just does the default damage 40. My config options: configuration_options = { { name = "wmwbasedamage", label = "wand's Damage:", options = { {description = "low", data = 20,hover = "20 Damage"}, {description = "normal", data = 25,hover = "25 Damage"}, {description = "high", data = 30,hover = "30 Damage"}, {description = "higher", data = 35,hover = "35 Damage"}, {description = "highest", data = 40,hover = "40 Damage"}, }, default = 40, }, } Much appreciated! Woscar.zip Edited December 24, 2019 by bullbro Link to comment Share on other sites More sharing options...
TerriFried Posted December 24, 2019 Author Share Posted December 24, 2019 On top of this, what is the code for it to increase my characters movement speed by 10%? Link to comment Share on other sites More sharing options...
TerriFried Posted December 25, 2019 Author Share Posted December 25, 2019 I realized what configuration options meant... so nevermind on that. Also, I figured out how to increase movement speed, so there is that. Link to comment Share on other sites More sharing options...
Thomas Die Posted December 25, 2019 Share Posted December 25, 2019 Make a function that is activated by attacking This function should check the durability then adjust the damage Link to comment Share on other sites More sharing options...
Thomas Die Posted December 25, 2019 Share Posted December 25, 2019 (edited) if the item breaks when it hits 0 or can't be repaired then just have it that when it's used the damage should decrease a bit or how much you want inst:AddComponent("weapon") inst.components.weapon:SetDamage(100 - inst.dura) inst.components.weapon.onattack = onattack inst.dura = 0 local function onattack(inst) inst.dura = inst.dura + 1 end Edited December 25, 2019 by thomas4846 Link to comment Share on other sites More sharing options...
NikMik Posted December 25, 2019 Share Posted December 25, 2019 The solution to this is in the finiteuses component: function FiniteUses:SetUses(val) local was_positive = self.current > 0 self.current = val self.inst:PushEvent("percentusedchange", {percent = self:GetPercent()}) < This is the important line if self.current <= 0 then self.current = 0 if was_positive and self.onfinished ~= nil then self.onfinished(self.inst) end end end function FiniteUses:GetPercent() <This is also important return self.current / self.total end When the item holding the component is used, it pushes an event the item can listen out for. And so all you need is to make it listen: inst:ListenForEvent("percentusedchange", function(inst) inst.components.weapon:SetDamage(DAMAGE * inst.components.finiteuses:GetPercent()) end) Replace "DAMAGE" with whatever you want. the GetPercent just checks what percent of durability the item has left, and the * multiplies the damage by that percentage. So full durability means a 1x modifier, whereas half is a 0.5x modifier. That function belongs right beneath where you state the weapon's damage in its prefab. Link to comment Share on other sites More sharing options...
Thomas Die Posted December 25, 2019 Share Posted December 25, 2019 is the percentage normally 1 (just asking) Link to comment Share on other sites More sharing options...
NikMik Posted December 25, 2019 Share Posted December 25, 2019 (edited) 5 minutes ago, thomas4846 said: is the percentage normally 1 (just asking) Yup! I tested it all to make sure. The game doesn't really do percentages as percentages - rather as decimals. So 1 is 100%, 0.5 is 50%, etc Edited December 25, 2019 by Mr. Tiddles Link to comment Share on other sites More sharing options...
Thomas Die Posted December 25, 2019 Share Posted December 25, 2019 awesome sauce 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