• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How can i get percentage with triggers??

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Set "A" = 100 * 1.30

1.30 is your multiplier. Anything above 1.00 is an increase while anything below is a reduction. Every 0.01 = 1%.


An example:
Say you wanted a custom stat like Ability Power that increases spell damage dealt by X%, you could do this with a Real variable set to 1.00 by default.

Then for every 1 Ability Power a Unit has, increase this variable by 0.01 (1%).

So the arithmetic for calculating a unit with 50 Ability Power that deals 100 spell damage would be:
Damage = 100 * 1.50

---

And to adjust your BCD example, simply change C to 0.60 and multiply B by C.
Set "B" = 300
Set "C" = 0.60
Set "D" = ( B * C )

300*0.60 = 180
 
Last edited:
Level 21
Joined
Apr 8, 2017
Messages
1,530
Well i found a problem, in my map some bonuses r given vía triggers and variables change when my hero pick an item



This is how it works

If hero pick X item
Then - Set "effect1" = 0.50 (this reduces dmg by 50%)

If hero pick X item
Then - Set "effect2" = 1.50 (this increases dmg by 50%)

So when I'll attack, trigger will calculate hm will deal my attack

Example:

Set "A" = base dmg (no modified) - imagine A is 300

Set "B" = A * "effect1" (0.50) = dmg is 150 now

Set "B" = B * "effect2" (1.50) = dmg is 225 now



The problem is this

If effect1 is 0.50 (-50%) and effect2 is 1.50 (+50%) if i combine both effects, dmg modification should be 0% but this doesn't happens

I mean effect1 + effect2 should set dmg to +0% bonus instead of modifying it from to 225

---

The best way to solve this is checking if values r lower than 1.0

Example
Effect1 = 1.50 /// Effect2 = 0.50

Set "A" = hero dmg
Set "B" = 0.0
Set "B" = B + effect1 (0.0+1.50)
----+----
If effect2 is lower than 1.0
---then Set "B" = B - effect2
If effect2 is greater or same than1.0
---then Set "B" = B + effect2
----+----

So B will be 1.0 cuz effect2 counteracts effect1

-
Hope this can be understandable

So, is there a easier way to solve this?
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
You shouldn't be setting the variables to a specific value. Instead, you should be adding/subtracting from a base value.

For example:

AttackDamage = 1.00 (Default)

Effect1 is applied to the Hero, set AttackDamage = AttackDamage + 0.50 (50% dmg buff)

Effect2 is applied to the Hero, set AttackDamage = AttackDamage - 0.50 (-50% dmg debuff)

This results in: 1.00 + 0.50 = 1.50 --> 1.50 - 0.50 = 1.00.

As long as you're handling the addition/subtraction correctly it will always work.

Then you can check for cases of negative damage dealt (say the hero has -150% dmg, or a -1.50 multiplier) and set the damage to 0.
 
Last edited:
Level 21
Joined
Apr 8, 2017
Messages
1,530
Yh but the system of "Effects" is automatic n var values will be changing from positive/negative effects cuz they depends on items u r carrying, so it won't detect if a bonus is positive or negative

I mean something bonus can be
+50%
+5%
+12%

Just additions

Or
-35%
-10%
-2%

Just subtract

And other times
+33%
-10%
+5%
Add/Subtract/Add

Effect1/2 is the name I gave to variables in the example I used early
 
Level 21
Joined
Apr 8, 2017
Messages
1,530
You shouldn't be setting the variables to a specific value. Instead, you should be adding/subtracting from a base value.

For example:

AttackDamage = 1.00 (Default)

Effect1 is applied to the Hero, set AttackDamage = AttackDamage + 0.50 (50% dmg buff)

Effect2 is applied to the Hero, set AttackDamage = AttackDamage - 0.50 (-50% dmg debuff)

This results in: 1.00 + 0.50 = 1.50 --> 1.50 - 0.50 = 1.00.

As long as you're handling the addition/subtraction correctly it will always work.

Then you can check for cases of negative damage dealt (say the hero has -150% dmg, or a -1.50 multiplier) and set the damage to 0.

Ok, check this post, what if effect2 become a positive bonus just bcuz my hero change the item that set the effect2 value

I mean
if i pick "red gloves", effect2 become a positive bonus

But if I pick "blue gloves", effect2 become a negative bonus

In your post effect2 is subtracted but what if effect2 become a positive bonus? will still acting as a negative bonus cuz that "trigger part" will be always subtracting instead of detecting if must add or subtract

One more question (this can solve everything)
- How can i set a variable with negative values?
Example:
Set X = -2
Set H = -1.85

So i can just do "set N = 3 + (-1)
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Here's a trigger example of how you should be handling this stuff:

Red Gloves (+0.50% Attack Damage)
  • Acquire Red Gloves
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Red Gloves
    • Actions
      • Set Variable unit_cv = (Custom value of (Triggering unit))
      • Set Variable HeroDamage[unit_cv] = (HeroDamage[unit_cv] + 0.50)
  • Lose Red Gloves
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Red Gloves
    • Actions
      • Set VariableSet unit_cv = (Custom value of (Triggering unit))
      • Set VariableSet HeroDamage[unit_cv] = (HeroDamage[unit_cv] - 0.50)
Blue Gloves (-0.50% Attack Damage)
  • Acquire Blue Gloves
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Blue Gloves
    • Actions
      • Set Variable unit_cv = (Custom value of (Triggering unit))
      • Set Variable HeroDamage[unit_cv] = (HeroDamage[unit_cv] - 0.50)
  • Lose Blue Gloves
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Blue Gloves
    • Actions
      • Set VariableSet unit_cv = (Custom value of (Triggering unit))
      • Set VariableSet HeroDamage[unit_cv] = (HeroDamage[unit_cv] + 0.50)
The Default Value of HeroDamage is 1.00. You must set this default value in the Variable Editor (Control + B) or it won't work.

And here's an even better system that will do most of the work for you:
New Bonus v1.7
 
Status
Not open for further replies.
Top