greykaiboy Posted March 5, 2015 Share Posted March 5, 2015 I would like to make a perk for my character, that when she has <50% health, she gain 3 times atk dmgso i write this: local function updatestats(inst) if inst.components.health.current <= 75 theninst.components.combat.damagemultiplier = 3 elseinst.components.combat.damagemultiplier = 1 end endand it has no effects in game, can someone please help me? Link to comment Share on other sites More sharing options...
mouse Posted March 5, 2015 Share Posted March 5, 2015 I think this is what you want.inst:DoPeriodicTask(.1, function(inst) if inst.components.health.currenthealth/inst.components.health.maxhealth < .5 then inst.components.combat.damagemultiplier=3 else inst.components.combat.damagemultiplier=1 endend)I'm not sure if it was a typo or not, but you were using health.current instead of health.currenthealthIf you want the multiplier to scale in direct relation to their health, you can do something like this:inst:DoPeriodicTask(.1, function(inst) inst.components.combat.damagemultiplier=(((inst.components.health.currenthealth/inst.components.health.maxhealth)-1)*3)*-1end)But be aware that her damage will actually be lower when at full health.If you want to avoid that, you can do it like this:inst:DoPeriodicTask(.1, function(inst) local asdf=(((inst.components.health.currenthealth/inst.components.health.maxhealth)-1)*3)*-1 if asdf<1 then asdf=1 end inst.components.combat.damagemultiplier=asdfend) Link to comment Share on other sites More sharing options...
rezecib Posted March 6, 2015 Share Posted March 6, 2015 @greykaiboy, All you need to do is add this to your character's master_postinit:inst:ListenForEvent('healthdelta', updatestats)because you already wrote the updatestats function, you just need to get it so that something is actually calling it. Link to comment Share on other sites More sharing options...
greykaiboy Posted March 6, 2015 Author Share Posted March 6, 2015 I think this is what you want.inst:DoPeriodicTask(.1, function(inst) if inst.components.health.currenthealth/inst.components.health.maxhealth < .5 then inst.components.combat.damagemultiplier=3 else inst.components.combat.damagemultiplier=1 endend)I'm not sure if it was a typo or not, but you were using health.current instead of health.currenthealthIf you want the multiplier to scale in direct relation to their health, you can do something like this:inst:DoPeriodicTask(.1, function(inst) inst.components.combat.damagemultiplier=(((inst.components.health.currenthealth/inst.components.health.maxhealth)-1)*3)*-1end)But be aware that her damage will actually be lower when at full health.If you want to avoid that, you can do it like this:inst:DoPeriodicTask(.1, function(inst) local asdf=(((inst.components.health.currenthealth/inst.components.health.maxhealth)-1)*3)*-1 if asdf<1 then asdf=1 end inst.components.combat.damagemultiplier=asdfend)I'll try this out when i have free time, thx @greykaiboy, All you need to do is add this to your character's master_postinit:inst:ListenForEvent('healthdelta', updatestats)because you already wrote the updatestats function, you just need to get it so that something is actually calling it.i've tried this and it crashed so i guess there is something wrong with the function codes. Link to comment Share on other sites More sharing options...
rezecib Posted March 6, 2015 Share Posted March 6, 2015 @greykaiboy, Ah, yeah, it should be crashing because you used "inst.components.health.current" instead of "inst.components.health.currenthealth". For whatever reason that's the variable it stores it in, just for health, the other two components use "current". Link to comment Share on other sites More sharing options...
greykaiboy Posted March 6, 2015 Author Share Posted March 6, 2015 @greykaiboy, Ah, yeah, it should be crashing because you used "inst.components.health.current" instead of "inst.components.health.currenthealth". For whatever reason that's the variable it stores it in, just for health, the other two components use "current".It works fine now, thanks very much, you're a life saver! Link to comment Share on other sites More sharing options...
mouse Posted March 6, 2015 Share Posted March 6, 2015 I'm not sure if it was a typo or not, but you were using health.current instead of health.currenthealthI'll try this out when i have free time, thx @greykaiboy, Ah, yeah, it should be crashing because you used "inst.components.health.current" instead of "inst.components.health.currenthealth". It works fine now, thanks very much, you're a life saver! 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