How do I calculate total damage dealt but not damage beyond 0?

0 favourites
  • 3 posts
From the Asset Store
Cue in the war drums and battle cadences with Total War Game Music Loops!
  • Hello good people, I'm stuck on this one. Since my game has multiple attacks, I would like for 1 event to detect how much dmg enemy took.

    Let's say for example we have fireball spell

    Fireball

    Dmg=4

    TotalDmg=0

    EnemyMaxHP=10

    EnemyCurrentHP=10

    My issue is that I would like a stat that shows total dmg dealt by fireball but not including dmg beyond 0. So if it takes 3 fireballs to kill 10 hp enemy, I would like only 10 hp added to the totaldmg stat instead of 3 x Fireball dmg = 12.

    I've tried below:

    While EnemyHp<MaxHp

    EnemyCurrentHP=EnemyMaxHP-EnemyCurrentHP

    EnemyMaxHP=EnemyCurrentHP // so I can stop the loop.

    But this one ends up going in negative, so it deals dmg like: 4,4,-2

    Is there any way to stop it calculating beyond 0?

    Any help would be greatly appreciated.

    Tagged:

  • If totaldmg greater than enemycurrentHP, set totaldmg to enemycurrentHP. Is one way if it is total damage combined.

    If the problem is when the final bit of damage goes over, then you can say if currentdmg greater than enemycurrentHP, then set currentdmg to enemycurrentHP.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yup that worked perfectly. Thank you very much for your help.

    Have a great day ahead!

    This is how I implemented that:

    If EnemyHP<0

    MaxHP-HP

    Add MaxHP to TotalDmg

    Else EnemyHP>0

    DmgTaken=MaxHp-HP

    MaxHP=HP

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)