It is currently 26 Apr 2024, 10:04
   
Text Size

Way to make yourself lose a fractional amount of life?

Moderator: CCGHQ Admins

Way to make yourself lose a fractional amount of life?

Postby fallenangle » 28 Aug 2014, 03:04

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.
fallenangle
 
Posts: 319
Joined: 20 Jul 2013, 02:31
Has thanked: 73 times
Been thanked: 41 times

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

Postby NeoAnderson » 28 Aug 2014, 04:26

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)
NeoAnderson
 
Posts: 914
Joined: 10 Sep 2013, 07:49
Has thanked: 18 times
Been thanked: 139 times

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

Postby thefiremind » 28 Aug 2014, 08:47

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).
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 721 times

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

Postby NeoAnderson » 28 Aug 2014, 13:56

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:
NeoAnderson
 
Posts: 914
Joined: 10 Sep 2013, 07:49
Has thanked: 18 times
Been thanked: 139 times


Return to 2014

Who is online

Users browsing this forum: No registered users and 59 guests


Who is online

In total there are 59 users online :: 0 registered, 0 hidden and 59 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 59 guests

Login Form