- Joined
- Apr 3, 2010
- Messages
- 1,889
JASS:
library GetTerrainZ /* v1.1.0.0, created by DeathChef
Description
The most effective and efficient way to get the z coodrinate
of the terrain through the x and y coordinates
What is useful about this snippet?
- It makes using a local real redundant in the right situation and helps
keep things clean
- If you need to get the TerrainZ two or three times in a single instance
you only need to do two commands with the second and third one being even
more simple
- Can be blended in with ITE(if then else) in situations when using Terrain Z
could be used either once or three times
Fields
constant location locZ
real storedZ
Functions
function GetTerrainZ takes real x, real y returns real
- Plain returning z coordinate without add-ons
function StoreGetTerrainZ takes real x, real y returns real
- Does same as run except value is stored into global
//Single line functions
function GetStoredZ takes nothing returns real
- Returns stored value
USE THIS LINE INSTEAD
storedZ
function GetLastZ takes nothing returns real
- Returns z coordinate from last instance
USE THIS LINE INSTEAD
GetLocationZ(locZ)
*/
globals
constant location locZ = Location(0, 0)
real storedZ
endglobals
function GetTerrainZ takes real x, real y returns real
call MoveLocation(locZ, x, y)
return GetLocationZ(locZ)
endfunction
function StoreGetTerrainZ takes real x, real y returns real
call MoveLocation(locZ, x, y)
set storedZ = GetLocationZ(locZ)
return storedZ
endfunction
function GetStoredZ takes nothing returns real
return storedZ
endfunction
function GetLastZ takes nothing returns real
return GetLocationZ(locZ)
endfunction
endlibrary
Example:
The example doesn't compile or have a real use but you should get the point.
JASS:
function Example takes integer UnitIndex returns real
local unit u = TestU[UnitIndex]
local real PredictedUnitZ = UnitZ[UnitIndex] - momentum
if StoreGetTerrainZ(GetUnitX(u), GetUnitY) >= PredictedUnitZ then
//If this condition is a lot less likely to pass you
//could just use "GetTerrainZ" instead and
//
//return GetLocationZ(locZ)
return storedZ
else
return PredictedUnitZ
endif
endfunction
The one [here] I find incomplete to how I like doing things.
Last edited: