Kaira Posted January 3, 2017 Share Posted January 3, 2017 (edited) I'm trying to set it up for my character to heal for an amount of damage dealt to him every time he gets hurt, but I'm having dificulty with messin around with data and other lil variables (I've managed to work the code to heal a set amount every hit, so no need to worry about that junk. Just finding a buncha crashes now that I'm trying to get more complicated) Quote local function HealSelf(inst, data) local target = data.target local brokenhealth = inst.components.health:GetPercent() local brokensanity = inst.components.sanity:GetPercent() --local brokendamage = inst.components.damagetracker.self:damage_done() if inst.components.health:IsDead() then return elseif brokensanity > 0 then inst.components.health:DoDelta(target.components.combat.defaultdamage) -- crashes at local target = data.target, dunno if this works yet inst.components.sanity:DoDelta(-2) end end I've also dug around in the health files hoping to find something that tells how much damage I've just taken in that moment and try to plug that in, but couldnt really make out if anything did that for me. Currently tearing up the combat/wigfrid files for this session. Edited January 3, 2017 by Kaira Link to comment Share on other sites More sharing options...
Kzisor Posted January 3, 2017 Share Posted January 3, 2017 @ImDaMisterL think we can get this moved to the modding forums? Link to comment Share on other sites More sharing options...
Kaira Posted January 3, 2017 Author Share Posted January 3, 2017 (edited) Mmm, It's been too long since I've touched these forums. Sorry about that :T Edited January 3, 2017 by Kaira Link to comment Share on other sites More sharing options...
Ryuushu Posted January 3, 2017 Share Posted January 3, 2017 @Kaira Something like this? local function OnHit(inst, attacker, damage) print("OnHit", inst, attacker, damage) local sanity = inst.components.sanity:GetPercent() if inst.components.health:IsDead() then return elseif sanity > 0 then inst.components.health:DoDelta(damage) -- Is he invincible while he has sanity? inst.components.sanity:DoDelta(-2) end end inst.components.combat:SetOnHit(OnHit) Link to comment Share on other sites More sharing options...
Kaira Posted January 3, 2017 Author Share Posted January 3, 2017 Oh so close, thanks for that~ Bout to head off for the night, but first: What does that print line do? Is there a way to save that number for a different function? (The main healtask is set to happen a short time after being hit with a DoTaskInTime listener) and on the side, he won't be invincible, I just like to code in lil chunks to make sure each lil thing works before playing the number game to balance things out. Link to comment Share on other sites More sharing options...
Ryuushu Posted January 3, 2017 Share Posted January 3, 2017 @Kaira The print line is just there for testing purpose, it displays text/values on the console. Also, yup, you can save it anywhere, like: inst.damage_taken = inst.damage_taken + damage inst.components.combat.damage_taken = inst.components.combat.damage_taken + damage Just do inst.variable_name to "declare" a new variable. Annnd (in this case) don't forget to initialize it to 0. Link to comment Share on other sites More sharing options...
Kaira Posted January 3, 2017 Author Share Posted January 3, 2017 Perfect~ Thanks for that~ Quote local function HealSelf(inst) local brokensanity = inst.components.sanity:GetPercent() if inst.components.health:IsDead() then return elseif brokensanity > .15 then inst.components.health:DoDelta(inst.DamageTaken * .2) inst.components.sanity:DoDelta(-inst.DamageTaken * .1) end end local function OnHit(inst, attacker, damage) print("OnHit", inst, attacker, damage) inst.DamageTaken = damage end 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