[Snippet] GetZ

Codes & Snippets

14 years
edited 8 years
A very simple snippet. It allows you to retrieve the Z values of points and units.

Note: Try not to use terrain deformations or abilities that cause terrain deformations (shock wave, war stomp, etc.), or else this may cause a desync. (rare cases, but has been rumored to have happened)

Code (jass) Select
library GetZ /* v1.0.0.0
*******************************************************************
*
*   This script will provide an interface to retrieve Z-values
*   of points and units without requiring you to deal with
*   locations.
*
*******************************************************************
*
*   function GetPointZ takes real x, real y returns real
*
*      -  Returns the Z-value of a particular point on the terrain.
*
*   function GetUnitZ takes unit u returns real
*
*      -  Returns the Z-value of a unit.
*      -  This will take both terrain height and fly height into
*         account.
*
*******************************************************************/

    globals
        private location loc = Location(0, 0)
    endglobals

    function GetPointZ takes real x, real y returns real
call MoveLocation(loc, x, y)
return GetLocationZ(loc)
    endfunction

    function GetUnitZ takes unit u returns real
call MoveLocation(loc, GetUnitX(u), GetUnitY(u))
return GetLocationZ(loc) + GetUnitFlyHeight(u)
    endfunction

endlibrary
14 years
I think it's important to add to the first post the specifications about desyncs for using this technique over dynamic terrain deformations.

But in general It's lovely.
14 years
Added the note. Thanks!
14 years
Perfect :) and now it goes where it belongs :)
13 years
If i believe people (can be easily tested anyway) GetLocationZ can return a different value with walkable destructables with animations.
It's a fact that animations are not synced, they are even not played at all if you don't have the view on it.
So, no need to GetLocalPlayer to have different values on different computers.

That's probably the same with spell animations like shockwave (again it's easy to test, one player is enough)
13 years
I remember having animations not synced, and it was an annoying issue when it came to map making. However, I reopened the editor today and tested my old maps and I couldn't reproduce the problem.

I made a blank map and made archimonde cast his spell slam when I hit esc. When I tested it, I took my camera to the edge of the map (archimonde not in sight) then I pressed esc, and then brought my camera to him and it still played the animation. I tested this a few times with the same results.

So... did blizzard fix this problem in some patch? I am using 1.26, and unless I ran the tests wrong, it seems like they are played just fine. But idk.
13 years
Quote from: Purgeandfire on August 02, 2012, 07:34:03 PM
I remember having animations not synced, and it was an annoying issue when it came to map making. However, I reopened the editor today and tested my old maps and I couldn't reproduce the problem.

I made a blank map and made archimonde cast his spell slam when I hit esc. When I tested it, I took my camera to the edge of the map (archimonde not in sight) then I pressed esc, and then brought my camera to him and it still played the animation. I tested this a few times with the same results.

So... did blizzard fix this problem in some patch? I am using 1.26, and unless I ran the tests wrong, it seems like they are played just fine. But idk.

Well, that was not my point.

Display the Z of the same point on the spell area effect over time, and check if it changes while you have not the view on it or if it doesn't.
13 years
Okay. I made a tauren chieftain, gave him shockwave, and made him cast it upon pressing ESC. I had another trigger read the Z values of the point he cast it on periodically.

I first had my camera on him, then I cast it and it read 0.00 several times, then read -0.287 or w/e then reverted back to 0.00.

Then I moved my camera away, made him cast, and had the same results (it read 0.00, then -0.287 a few times, then 0.00 again)

I don't know if those results are true for all patches, but I can confirm that those are the results from patch 1.26. That means that even if it is not in view, it will still perform the animations/deformation. I haven't tested it extensively, but w/e.
13 years
Ok, and what about walkable destructables with animations ? (if you care to test it)
13 years
I'm just wondering what happens if you use coordinates which are outside the whole map (GetWorldBounds).
You could add some debug stuff in GetPointZ if it crash wc3 (in debug mode or not).

Same for GetUnitZ, it shouldn't crash with an invalid unit, but it should return the Z of the Location(0,0) and not just 0, now again maybe some debug stuff is unecessary.

Note that here i'm only guessing, tests are needed.

At least i think that it should be mentionned by some comments.
13 years
I'll check it out soon and report back with results/details.
13 years
Lol yeah