# [General] (Trigger) Getting Distances between Target A and B

Discussion in 'World Editor Help Zone' started by Freyky, Dec 26, 2016.

1. ### Freyky

Joined:
Aug 6, 2014
Messages:
87
Resources:
0
Resources:
0
Hey I was wondering if there's a way to gather the distance between target A and B. My plan is to do a spell which deals extra damage for the distance traveled or at least the distance when it was cast between the caster and the target, how should I do that?

Also: Is it possible to get if sum1 got hit by a Shockwave / Crushing Wave?

2. ### pOke

Joined:
Mar 24, 2013
Messages:
1,103
Resources:
1
Maps:
1
Resources:
1
There is an operation "Distance between points"

You wont be able to get who was hit by shockwave using the default spells, but if you trigger your own, you can get that information.

### Spell Reviewer

Joined:
Jan 18, 2005
Messages:
26,134
Resources:
3
Maps:
1
Spells:
2
Resources:
3
There is and it involves using highschool mathematics. Such highschool level mathematics have been implemented in the GUI function "Distance between points" as pOke has suggested.

The implementation of that GUI function is...
Code (vJASS):
function DistanceBetweenPoints takes location locA,location locB returns real
local real dx = GetLocationX(locB) - GetLocationX(locA)
local real dy = GetLocationY(locB) - GetLocationY(locA)
return SquareRoot(dx * dx + dy * dy)
endfunction

As you can see here, this is the kind of stuff you learn in S2 in Scotland at highschool, a long way from any kind of advanced mathematics so the sort everyone knows (should know...).

It is an implementation of 2D Euclidean distance formula, equivalent to Pythagoras's theorem so invented at least 2500 years ago.

When one casts an ability or issues an order you can get a point for both the caster/ordered unit and the target unit/object/point. These can be put into the Euclidean distance formula to get a distance out.

Distance returned will be in Warcraft III units, which have a meaning of 128 units per tile edge. Eg a distance of 512 Warcraft III units is exactly 4 tiles if parallel with one of the tile edges. To this day no one is sure why Blizzard chose such strange distance unit for Warcraft III, with their later StarCraft II game having a much more sensible distance unit of tile edge length. Due to a lack of aspect ratio correction tiles may appear rectangular when Warcraft III is played on a non 4:3 display, however internally they are a perfect square when viewed top down.

A damage detection system can detect the damage. However it is very difficult to detect if it was only from a shockwave / crushing wave / carrion swarm ability and not any other available damage source, especially which deals similar damage values.

In StarCraft II they really boosted damage detection by allowing one to filter and query what effect caused the damage. Unfortunately WC3 lacks the concept of damage effects so it is not something I would expect to see patched in any time soon.

Last edited: Dec 26, 2016
4. ### Freyky

Joined:
Aug 6, 2014
Messages:
87
Resources:
0
Resources:
0
OK thx 4 the info

And @Dr Super Good, oh well I'm quite good in maths and understand it yeah but I've looked for the function because I haven't really found one, now I found it thanks to you

Have a great day and happy new year in 4 days to both of you.