Monti18 Posted February 5, 2021 Share Posted February 5, 2021 Hello, I'm currently trying to mod a weapon that doesn't deal damage and heals with each hit the target. THe no damage part is no problem, I just need help with the healing. This is the section where i tried to add the healing, but when I'm trying it, nothing happens. local function onattack(target) if target.components.health then target.components.health:DoDelta(5) end end inst.components.weapon:SetOnAttack(onattack) This my first try at modding, I tried searching for a solution, but didn't find anything. Any help is welcome! 1 Link to comment Share on other sites More sharing options...
Combustiblemon Posted February 6, 2021 Share Posted February 6, 2021 (edited) inst.components.weapon:SetOnAttack(onattack) This code means when this weapon attacks, weapon will call function 'onattack(inst, attacker, target)' This means you have to give value (inst, attacker, target) but you give only one value, so instead of target, the first value - inst(weapon itself) will go to function onattack, local function onattack(target) if target.components.health then target.components.health:DoDelta(5) end end So this code, will be local function onattack('your weapon') if 'your weapon'.components.health then 'your weapon'.target.components.health:DoDelta(5) --your weapon has no health components for sure so it will do nothing end end this one, of course you'll not want. To edit code, just add more value: local function onattack(inst, attacker, target) if target.components.health then target.components.health:DoDelta(5) end end This should work without problem. Edited February 6, 2021 by Combustiblemon Link to comment Share on other sites More sharing options...
Monti18 Posted February 6, 2021 Author Share Posted February 6, 2021 Thank you very much, I just tested it out, it worked flawlessly! I just didn't think of adding the other values, I will keep it in mind for the future. 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