Page 1 of 1

Way to make yourself lose a fractional amount of life?

PostPosted: 28 Aug 2014, 03:04
by fallenangle
I've been trying to code Doomsday, and I can get it to do everything I want except make me lose half my life total when I cast it. I've tried using Blood Tribute and Pox as models to code this effect, but so far I've been unsuccessful. Can anyone show me what the code would look like for an RTA to make the caster of a spell lose half his or her life? Thanks in advance for all of your help and advice.

Re: Way to make yourself lose a fractional amount of life?

PostPosted: 28 Aug 2014, 04:26
by NeoAnderson
fallenangle wrote:I've been trying to code Doomsday, and I can get it to do everything I want except make me lose half my life total when I cast it. I've tried using Blood Tribute and Pox as models to code this effect, but so far I've been unsuccessful. Can anyone show me what the code would look like for an RTA to make the caster of a spell lose half his or her life? Thanks in advance for all of your help and advice.
Try with something like this: UNTESTED
Code: Select all
 local value = math.ceil(EffectController():GetLifeTotal / 2)
 EffectController():LoseLife(value)

Re: Way to make yourself lose a fractional amount of life?

PostPosted: 28 Aug 2014, 08:47
by thefiremind
NeoAnderson wrote:Try with something like this: UNTESTED
Code: Select all
local value = math.ceil(EffectController():GetLifeTotal() / 2)
EffectController():LoseLife(value)
Yes, that should work, except for the missing parentheses after GetLifeTotal (I added them in the quoted message :wink:).

This is an alternative that doesn't use Lua's math library, in case someone is interested:
Code: Select all
local life = EffectController():GetLifeTotal()
local value = life / 2 + life % 2
EffectController():LoseLife(value)
Rounding up is made by adding the remainder of the division (if the life total is odd, then the remainder will be 1, otherwise it will be 0).

Re: Way to make yourself lose a fractional amount of life?

PostPosted: 28 Aug 2014, 13:56
by NeoAnderson
thefiremind wrote:
NeoAnderson wrote:Try with something like this: UNTESTED
Code: Select all
local value = math.ceil(EffectController():GetLifeTotal() / 2)
EffectController():LoseLife(value)
Yes, that should work, except for the missing parentheses after GetLifeTotal (I added them in the quoted message :wink:).
Ahahhaa sorry probably i was too tired when i posted the answer!!!! :lol: