Jump to content

Need some help on making perks of a custom character


Recommended Posts

I would like to make a perk for my character, that when she has <50% health, she gain 3 times atk dmg


so i write this:


 

local function updatestats(inst)
 
if inst.components.health.current <= 75 then
inst.components.combat.damagemultiplier = 3
 
else
inst.components.combat.damagemultiplier = 1
 
end
 
end




and it has no effects in game, can someone please help me?
Link to comment
Share on other sites

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.currenthealth

If 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

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.currenthealth

If 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

@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

@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

I'm not sure if it was a typo or not, but you were using health.current instead of health.currenthealth

I'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!

post-239075-0-79652700-1425655480_thumb.

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...