# [Trigger]% Life difference, math.

Status
Not open for further replies.

#### Jordguitar

Level 1
Hey Hive, I have a problem with figuring a trigger out.
The thing is, I want it so the units doesn't just flee when they see they have less % hp then the other unit. I want it to be a % difference.
Like; "percentage life of attacked unit is 15% greater than percentage of attacking unit". But I can't figure it out. Ty for help.
Here's what the trigger looks like:

Flee
Events
Unit - A unit Is attacked
Conditions
((Attacked unit) is A Hero) Equal to True
((Attacking unit) is A Hero) Equal to True
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Percentage life of (Attacked unit)) Greater than (Percentage life of (Attacking unit))
Then - Actions
Unit - Order (Attacked unit) to Attack (Attacking unit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Owner of (Attacking unit)) Equal to Player 1 (Red)
Then - Actions
Unit - Order (Attacking unit) to Move To (Position of Town Hall 0004 <gen>)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Owner of (Attacking unit)) Equal to Player 2 (Blue)
Then - Actions
Unit - Order (Attacking unit) to Move To (Position of Town Hall 0001 <gen>)
Else - Actions
Do nothing
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Percentage life of (Attacking unit)) Greater than (Percentage life of (Attacked unit))
Then - Actions
Unit - Order (Attacking unit) to Attack (Attacked unit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Owner of (Attacking unit)) Equal to Player 2 (Blue)
Then - Actions
Unit - Order (Attacked unit) to Move To (Position of Town Hall 0004 <gen>)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Owner of (Attacking unit)) Equal to Player 1 (Red)
Then - Actions
Unit - Order (Attacked unit) to Move To (Position of Town Hall 0001 <gen>)
Else - Actions
Do nothing
Else - Actions
Do nothing

#### Squiggy

Level 28
Set a variable where you set the value you want to have the trigger work with. Then compare the life percentage to your set value and do stuff.
(Also, you can delete those 'Do nothing' actions - they serve no purpose.)

#### Dr Super Good

Spell Reviewer
Level 64
( life of attacked unit / maximum life of attacked unit ) >= ( life of attacking unit / maximum life of attacking unit ) + 0.15

#### Jordguitar

Level 1
How do I put the +0.15 at the end?

#### rulerofiron99

Level 25
Use the Arithmetic function.

Also, I'm not sure if these functions used 100 or 1.00 for 100%, so if you get funny values, replace 0.15 with 15.

#### ABM

Level 7
use the Arithmetic ...twice

[trigger=]Initialisation map
Events
Conditions
((Vie of (Attacked unit)) / (Vie Max of (Attacked unit))) less or equal to (((Vie of (Attacking unit)) / (Vie Max of (Attacking unit))) + 0.15)
Actions
[/trigger]

also when posting trigger try to use this [/trigger] at the end and this at the beggining [trigger=] with your text in between

#### Jordguitar

Level 1
Great, I just found it and came back to tell.
Of course arithmetic, I'm quite new to triggers.
Thank you all, this is solved.

Status
Not open for further replies.

Replies
16
Views
965
Replies
9
Views
1K
Replies
6
Views
635
Replies
2
Views
704
[Trigger] Does this leak?
Replies
17
Views
1K