Goregonzola Posted August 28, 2022 Share Posted August 28, 2022 Hey there! I have a bit of trouble figuring out how to get around a scaling mechanic. It's about a custom weapon that deals damage based on its current durability percentage - just like the ham bat does. This function is similar to the hambat's one, but it's set to SetDamage instead of running it after every equip, unequip, load and whatnot. It looks like this: Spoiler local function ChargedGraft(inst) local dmg = 350 * inst.components.finiteuses:GetPercent() dmg = Remap(dmg, 0, 350, 50, 350) inst.components.weapon:SetDamage(dmg) end end --------------------------------------------------------------------------------------- inst:AddComponent("weapon") inst.components.weapon:SetDamage(ChargedGraft) I'm not sure how to return a value to the SetDamage in a code-structure like this. What should I change here? Thanks in advance! Link to comment https://forums.kleientertainment.com/forums/topic/142879-weapon-damage-scale-based-on-durability/ Share on other sites More sharing options...
IronHunter Posted August 28, 2022 Share Posted August 28, 2022 You are going to need to update your damage everytime durability is updated. Maybe there is a event you can listen for from finite uses? If not you can hook the finite uses function for when it updates and make your own event. Link to comment https://forums.kleientertainment.com/forums/topic/142879-weapon-damage-scale-based-on-durability/#findComment-1596124 Share on other sites More sharing options...
Monti18 Posted August 29, 2022 Share Posted August 29, 2022 (edited) SetDamage can either be a value or a function. If it's a function, it should return a number value, as this is needed for the game to calculate the damage by calling Weapon:GetDamage. To make your function work, you just need to change it like this: local function ChargedGraft(inst) local dmg = 350 * inst.components.finiteuses:GetPercent() return Remap(dmg, 0, 350, 50, 350) end --------------------------------------------------------------------------------------- inst:AddComponent("weapon") inst.components.weapon:SetDamage(ChargedGraft) Edited August 29, 2022 by Monti18 an end too much was removed 1 Link to comment https://forums.kleientertainment.com/forums/topic/142879-weapon-damage-scale-based-on-durability/#findComment-1596192 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