• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] How to detect distance travelled?

Status
Not open for further replies.
Level 3
Joined
Aug 19, 2020
Messages
38
Greetings,
I would like to make some spells like "empower next attack after travelling a certain distance"
But I dont know how to measure the distance travelled.

I made something like
Trigger 1
every 0.1s
set position 1 = unit's position
run a timer with 0.09s

Trigger 2
timer ends
then
set position 2 = unit's position
calculate the distance between point 2 and point 1
then record the distance

But it somehow does not work, it just infinitely stack up.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I attached an example map with an ability that adds 100/200/300 bonus damage to your next attack after moving 500 distance.

You need the latest version of wc3 to open the map.

Look for the "===CONFIGURE===" comments in the triggers to find where the more configurable Actions are, such as changing the Art of the Special Effects.
 

Attachments

  • Distance Ability 1.w3m
    67.1 KB · Views: 25
Last edited:
Level 3
Joined
Aug 19, 2020
Messages
38
First of all, thanks for replying.
But I am using 1.26 version of WC3, so I can't open it unfortunately. T_T
could you please post the trigger or something else?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I wish you guys would put that in your signature or put it in the title of your post. It's sort of important when asking for help to let people know that you can't use half of the new features in the game.

Anyway, do you plan on having more than 1 Unit with this ability?
 
Level 3
Joined
Aug 19, 2020
Messages
38
I would pay attention to that next time.
Yes, I plan on making some items with these distance ability.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I would pay attention to that next time.
Yes, I plan on making some items with these distance ability.
No worries, it's not something you'd think of on your own. I was just venting my frustrations but it's partially my own fault for assuming.

Alright, good because my original design was meant to work for multiple units, which would've been overkill if it only needed to work for just one unit.

  • Setup Empower
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- === CONFIGURE === --------
      • -------- Distance required to empower the unit(s): --------
      • Set VariableSet MaxDistance = 500.00
      • -------- Abilities: --------
      • Set VariableSet Empower_Hero_Ability = Empower (Hero Ability)
      • Set VariableSet Empower_Bonus_Ability = Empower (Damage Bonus)
  • Unit Starts Moving
    • Events
      • Game - UnitMovingEvent becomes Equal to 1.00
    • Conditions
      • (Level of Empower_Hero_Ability for UDexUnits[UDex]) Greater than 0
    • Actions
      • Unit Group - Add UDexUnits[UDex] to Moving_Units
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Moving_Units) Equal to 1
        • Then - Actions
          • Countdown Timer - Start Moving_Timer as a Repeating timer that will expire in 0.10 seconds
        • Else - Actions
  • Unit Stops Moving
    • Events
      • Game - UnitMovingEvent becomes Equal to 2.00
    • Conditions
      • (Level of Empower_Hero_Ability for UDexUnits[UDex]) Greater than 0
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (UDexUnits[UDex] is in Moving_Units.) Equal to True
        • Then - Actions
          • Unit Group - Remove UDexUnits[UDex] from Moving_Units.
        • Else - Actions
      • -------- --------
      • -------- Pause timer when not in use --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Moving_Units) Equal to 0
        • Then - Actions
          • Countdown Timer - Pause Moving_Timer
        • Else - Actions
  • Movement Timer
    • Events
      • Time - Moving_Timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Moving_Units and do (Actions)
        • Loop - Actions
          • Set VariableSet CV = (Custom value of (Picked unit))
          • -------- --------
          • -------- Check if our unit has the Empower ability (If it does then do nothing) --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Empower_Bonus_Ability for (Picked unit)) Equal to 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • OldPositionExists[CV] Equal to True
                • Then - Actions
                  • -------- Increase Distance Traveled --------
                  • Set VariableSet NewPosition[CV] = (Position of (Picked unit))
                  • Set VariableSet Distance = (Distance between NewPosition[CV] and OldPosition[CV])
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Distance Greater than 0.00
                    • Then - Actions
                      • Set VariableSet DistanceTraveled[CV] = (DistanceTraveled[CV] + Distance)
                    • Else - Actions
                  • -------- --------
                  • -------- === CONFIGURE === --------
                  • -------- Check if Distance Traveled >= Max Distance --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • DistanceTraveled[CV] Greater than or equal to MaxDistance
                    • Then - Actions
                      • -------- EMPOWER: --------
                      • Unit - Add Empower_Bonus_Ability to (Picked unit)
                      • Unit - Set level of Empower_Bonus_Ability for (Picked unit) to (Level of Empower_Hero_Ability for (Picked unit))
                      • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Human\MarkOfChaos\MarkOfChaosTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Special Effect - Create a special effect attached to the weapon of (Picked unit) using Abilities\Weapons\AncestralGuardianMissile\AncestralGuardianMissile.mdl
                      • Set VariableSet Empower_Sfx[CV] = (Last created special effect)
                      • Set VariableSet DistanceTraveled[CV] = 0.00
                    • Else - Actions
                  • -------- --------
                  • -------- Clean Up Leaks: --------
                  • Custom script: call RemoveLocation (udg_OldPosition[udg_CV])
                  • Custom script: call RemoveLocation (udg_NewPosition[udg_CV])
                  • -------- --------
                  • -------- Do This Last: --------
                  • Set VariableSet OldPosition[CV] = (Position of (Picked unit))
                • Else - Actions
                  • -------- This prevents issues from happening (old position doesn't exist the first time this timer runs for a unit) --------
                  • Set VariableSet OldPosition[CV] = (Position of (Picked unit))
                  • Set VariableSet OldPositionExists[CV] = True
            • Else - Actions
  • Unit Dies While Moving
    • Events
      • Unit - A unit Dies
    • Conditions
      • OldPositionExists[(Custom value of (Triggering unit))] Equal to True
    • Actions
      • -------- It's important that you do this to prevent issues with the Movement Timer trigger --------
      • Set VariableSet CV = (Custom value of (Triggering unit))
      • Unit - Remove Empower_Bonus_Ability from (Triggering unit)
      • Special Effect - Destroy Empower_Sfx[CV]
      • Set VariableSet OldPositionExists[CV] = False
      • Custom script: call RemoveLocation (udg_OldPosition[udg_CV])
  • Remove Empower On Hit
    • Events
      • Game - DamageEvent becomes Equal to 1.00
    • Conditions
      • (Level of Empower_Bonus_Ability for DamageEventSource) Greater than 0
      • IsDamageAttack Equal to True
    • Actions
      • Set VariableSet CV = (Custom value of DamageEventSource)
      • Unit - Remove Empower_Bonus_Ability from DamageEventSource
      • Special Effect - Destroy Empower_Sfx[CV]
      • Set VariableSet OldPositionExists[CV] = False
      • Custom script: call RemoveLocation (udg_OldPosition[udg_CV])
I'm using these 3 systems created by Bribe (you'll need to find older versions to work with 1.26):
-Unit Indexer
-Damage Engine
-IsUnitMoving

The DamageEvent trigger will be different on the older versions of Damage Engine. Not entirely sure if you could detect if the damage came from an Attack back then.

Variables:
Moving_Timer = Timer
Moving_Units = Unit Group
CV = Integer
OldPositionExists = Boolean (Array)
MaxDistance = Real
DistanceTraveled = Real (Array)
Distance = Real
NewPosition = Point (Array)
OldPosition = Point (Array)
Empower_Sfx = Special Effect (Array)
Empower_Bonus_Ability = Ability Code
Empower_Hero_Ability = Ability Code
 
Last edited:
Level 3
Joined
Aug 19, 2020
Messages
38
Thanks again,
my major problem is that I don't know how to get the old position in the same trigger
and your trigger taught me.
Thanks!
 
Status
Not open for further replies.
Top