library ItemPosition uses GetItemOwner // hiveworkshop.com/forums/showthread.php?t=184563
//Version 3.0.0.0
/*
function ItemGetX takes item i returns real
function ItemGetY takes item i returns real
function ItemGetZ takes item i returns real
//! runtextmacro ITEM_POSITION("whichItem", "xVarName", "yVarName")
- A textmacro that automatically sets variables "x" and "y".
function ItemSetX takes item i, real x returns nothing
function ItemSetY takes item i, real y returns nothing
function ItemSetZ takes item i, real z, real rate returns nothing
function ItemSetPosition takes item i, real x, real y returns nothing
Setting the item's position using these controls will set the item
owner's position as well. If you don't want this feature, don't use
these functions.
*/
globals
private location l = Location(0., 0.)
public unit tU
endglobals
function ItemGetX takes item i returns real
if (IsItemOwned(i)) then
return GetUnitX(GetItemOwner(i))
endif
return GetItemX(i)
endfunction
function ItemGetY takes item i returns real
if (IsItemOwned(i)) then
return GetUnitY(GetItemOwner(i))
endif
return GetItemY(i)
endfunction
function ItemGetZ takes item i returns real
if (IsItemOwned(i)) then
set tU = GetItemOwner(i)
call MoveLocation(l, GetUnitX(tU), GetUnitY(tU))
return GetLocationZ(tU) + GetUnitFlyHeight(u)
endif
call MoveLocation(l, GetItemX(i), GetItemY(i))
return GetLocationZ(l)
endfunction
//! textmacro ITEM_POSITION takes ITEM, X, Y
if (IsItemOwned($ITEM$)) then
set ItemPosition_tU = GetItemOwner($ITEM$)
set $X$ = GetUnitX(ItemPosition_tU)
set $Y$ = GetUnitY(ItemPosition_tU)
endif
set $X$ = GetItemX($ITEM$)
set $Y$ = GetItemY($ITEM$)
//! endtextmacro
function ItemSetPosition takes item i, real x, real y returns nothing
if (IsItemOwned(i)) then
set tU = GetItemOwner(i)
call SetUnitX(tU, x)
call SetUnitY(tU, y)
else
call SetItemPosition(i, x, y)
endif
endfunction
function ItemSetX takes item i, real x returns nothing
if (IsItemOwned(i)) then
call SetUnitX(GetItemOwner(i), x)
else
call SetItemPosition(i, x, GetItemY(i))
endif
endfunction
function ItemSetY takes item i, real y returns nothing
if (IsItemOwned(i)) then
call SetUnitY(GetItemOwner(i), y)
else
call SetItemPosition(i, GetItemX(i), y)
endif
endfunction
function ItemSetZ takes item i, real z, real rate returns nothing
if (IsItemOwned(i)) then
set tU = GetItemOwner(i)
call MoveLocation(l, GetUnitX(tU), GetUnitY(tU))
call SetUnitFlyHeight(tU, z + GetLocationZ(l), rate)
endif
endfunction
endlibrary