- Joined
- Oct 11, 2012
- Messages
- 711
Hi all. How can I detect whether a unit is in a rect? Should I use
Thanks.
IsUnitInRegion()
?Thanks.
IsUnitInRegion()
?In a quick way I can only image two solutions
- UnitInregion()
- You can write that function by yourself
--> IsUnitInRect(unit, rect)
-------------------------------------------------------------
--> function IsUnitInRect takes unit WhichUnit , rect r returns boolean
--> Now you GroupEnumUnit in that rect and run a FirstOfGroup loop
--> loop
....
--> if WhichUnit == u then
--> return true
--> endif
--> endloop
.....
--> return false
--> endfunction
------------------------------------------------------------
function IsUnitInRect takes rect whichRect, unit whichUnit returns boolean
local region r = CreateRegion()
local boolean inside
call RegionAddRect(r, whichRect)
set inside = IsUnitInRegion(r, whichUnit)
call RemoveRegion(r)
set r = null
return inside
endfunction
library IsUnitInRect
globals
private region r = CreateRegion()
private boolean result
endglobals
function IsUnitInRect takes rect whichRect, unit whichUnit returns boolean
call RegionAddRect(r, whichRect)
set result = IsUnitInRegion(r, whichUnit)
call RegionClearRect(r, whichRect)
return result
endfunction
endlibrary
you have minx, miny, maxx, and maxy of the rect as well as x,y of the unit.
x >= minx and x <= maxx and y >= miny and y <= maxy
function IsUnitInRect takes rect r, unit u returns boolean
return GetUnitX(u) < GetRectMaxX(r) and GetUnitY(u) < GetRectMaxY(r) and GetUnitX(u) > GetRectMinX(r) and GetUnitY(u) > GetRectMinY(r)
endfunction
The person asked for the detection of a unit inside a rectangle, not a region, he was simply asking if he should use IsUnitInRegion.
Than why post?I know this already.
Than why post?