Jump to content

Weapon damage scale based on durability


Recommended Posts

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
Share on other sites

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 by Monti18
an end too much was removed
  • Thanks 1
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
 Share

×
  • Create New...