[Spell] Random Damage in Integer Percentage

Level 13
Joined
Sep 11, 2013
Messages
467
Greetings!
I wish to create a passive ability that has 100% chance on each attack to give a random damage between 1% and 7% to enemy from enemy max life, but only integer numbers (if possible) (1%,2%,3%...7% from Enemies max hp ). I don't wish this passive to deal damage to allies. Also I wish to take xp and gold from kills if the killed unit is killed by this passive. The passive must be just 1 level. I think the damage percentage must be Pure.

How can I do that if is possible? First I was thinking was simple, but after few fails, now I think is not so simple. :peasant-sad:

The help will be appreaciated!
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
  • Events
    • Unit - Any unit takes damage
  • Conditions
    • (Damage from normal attack) equal to True
    • (Level of PASSIVE for Damaged Unit) greater than 0
  • Actions
    • Set DMG = (Real(Random integer from 1 to 7) / 100.00)
    • Set DMG = (DMG x (Damaged Unit Maximum Life)) //this is called Unit - Property
    • Unit - Cause Damage Source to damage Damaged Unit for DMG amount of attack type Magic and Damage type Universal
I believe Universal ignores armor but you could also use Chaos or Divine if you haven't changed the armor table in your map (I don't remember).
 
Level 13
Joined
Sep 11, 2013
Messages
467
  • Events
    • Unit - Any unit takes damage
  • Conditions
    • (Damage from normal attack) equal to True
    • (Level of PASSIVE for Damaged Unit) greater than 0
  • Actions
    • Set DMG = (Real(Random integer from 1 to 7) / 100.00)
    • Set DMG = (DMG x (Damaged Unit Maximum Life)) //this is called Unit - Property
    • Unit - Cause Damage Source to damage Damaged Unit for DMG amount of attack type Magic and Damage type Universal
I believe Universal ignores armor but you could also use Chaos or Divine if you haven't changed the armor table in your map (I don't remember).
  • PassiveLifestealer
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Unit-type of (Damage source)) Equal to Rifleman
      • (Damage From Normal Attack) Equal to True
    • Actions
      • Set VariableSet RealNaix = (Real(((Random integer number between 1 and 7) / 100)))
      • Game - Display to (All players) the text: (String(RealNaix))
      • Set VariableSet RealNaix = (RealNaix x (Max life of (Damage Target)))
      • Unit - Cause (Damage source) to damage (Damage Target), dealing RealNaix damage of attack type Magic and damage type Universal
      • Game - Display to (All players) the text: (String(RealNaix))
Hi and thank you for your help!
I understand your math logic, but sadly this will not work because the Real variable will take only the integer part and if the integer is 0, everything will go to 0.

Ex. 7/100 = 0.07 => Real = 0 and 0 x Anything else = 0 :peasant-sad:
 
Convert the integer to real BEFORE dividing and what you have done should work.

I usually thinks math is annoying to do in GUI and often do things like:
set udg_myRealVariable = 0.01 * GetRandomInt(1, 7)
From a "Custom Code" GUI element.
It has advantages and disadvantages to do it I like to do of course (need to remember udg_ on gui-variables, need to "know" the function names for various things, but I usually do the code in VSCode and copy-paste it into the editor...).
 
Level 13
Joined
Sep 11, 2013
Messages
467
Convert the integer to real BEFORE dividing and what you have done should work.

I usually thinks math is annoying to do in GUI and often do things like:
set udg_myRealVariable = 0.01 * GetRandomInt(1, 7)
From a "Custom Code" GUI element.
It has advantages and disadvantages to do it I like to do of course (need to remember udg_ on gui-variables, need to "know" the function names for various things, but I usually do the code in VSCode and copy-paste it into the editor...).
Thank you for help! @Pyrogasm and @ThompZon
I solved the problem in the end!

  • PassiveLifestealer
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Unit-type of (Damage source)) Equal to Rifleman
      • (Damage From Normal Attack) Equal to True
    • Actions
      • Event Response - Set Damage of Unit Damaged Event to 0.00
      • Set VariableSet IntegerNaix = (Random integer number between 1 and 7)
      • Set VariableSet RealNaix = ((Real(IntegerNaix)) / 100.00)
      • Set VariableSet RealNaix = (RealNaix x (Max life of (Damage Target)))
      • Unit - Cause (Damage source) to damage (Damage Target), dealing RealNaix damage of attack type Spells and damage type Universal
 
Level 13
Joined
Sep 11, 2013
Messages
467
If you look closely, the conversion in my typed trigger is around the 1-7 before the division occurs, so it's real division. Also don't forget you put that line to disable the attack's damage (probably for testing?).
Wow...
I would never have realized this subtlety that makes such a big difference.
Right now I looked back at the whole past to understand how I did things differently.

So now i see.. (very hard to spot for me)

In the first trigger I choose --------> 1.Arithmetic and then 2.Convert Integer to Real
In your first trigger you choose ---> 1.Convert Integer to Real and then 2.Arithmetic

Since both options are written almost the same, and I didn't even know such a thing existed, it was impossible for me to see the difference at that time. Even now is like.. no way.:peasant-shocked:
  • Set VariableSet RealNaix = ((Real((Random integer number between 1 and 7))) / 100.00)
  • Set VariableSet RealNaix = (Real(((Random integer number between 1 and 7) / 100)))
Thank you for telling me. Your trigger was good from start, but I failed to copy it correctly.:peasant-thumbs-up-cheers:

Also don't forget you put that line to disable the attack's damage (probably for testing?).
I know, it was, indeed, for testing. Thank you for notice.:peasant-cheers:
 
Top