Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,219
hi, I was playing around in vjass and I was making a function called GetClosestTile() but its not working well at all.
I even made the detectrange extremely huge just for testing but it wont detect a single one. It only works if you put the tile ON that location.
-
demo Copy
-
Events
- Player - Player 1 (Red) skips a cinematic sequence
- Conditions
-
Actions
- Set terrain = Lordaeron Summer - Grassy Dirt
- Set x = (Center of Region 000 <gen>)
- Custom script: set udg_location = GetClosestTile(udg_terrain,udg_x)
- Unit - Create 1 Footman for Player 1 (Red) at location facing Default building facing degrees
-
Events
JASS:
globals
real searchRange = 9000
endglobals
function GetClosestTile takes integer tileid, location loc returns location point
local location start = loc
local location x
local location closestLoc
local real startDistance = 1
local real startAngle = 0
local real closestDistance = 9999
local real tempDistance
local integer exit = 0
call BJDebugMsg("function called")
loop
exitwhen exit == 1
set x = PolarProjectionBJ(start, startDistance, startAngle)
if GetTerrainType(GetLocationX(x), GetLocationY(x)) == tileid then
set tempDistance = DistanceBetweenPoints(x, start)
call BJDebugMsg("found tile")
if tempDistance <= closestDistance then
set closestDistance = tempDistance
set closestLoc = x
endif
endif
set startDistance = startDistance + 1
if startDistance <= searchRange then
set startAngle = startAngle + 1
set startDistance = 1
if startAngle >= 360 then
set exit = 1
call BJDebugMsg("ended")
endif
endif
endloop
return closestLoc
endfunction
I even made the detectrange extremely huge just for testing but it wont detect a single one. It only works if you put the tile ON that location.