I want to create n units randomly on the playable map, but they should only spawn on a walkable location.
The problem is that it does not seem to work. Anyone got see what is wrong?
-
Init
-
Events
- Map initialization
- Conditions
-
Actions
- Visibility - Disable fog of war
- Visibility - Disable black mask
- Set tmp_reg = (Playable map area)
-
For each (Integer A) from 1 to 200, do (Actions)
-
Loop - Actions
- Set tmp_point = (Random point in tmp_reg)
- Custom script: call walkable(udg_tmp_point)
- Unit - Create 1 Peasant for Player 1 (Red) at tmp_point facing Default building facing degrees
- Custom script: call RemoveLocation(udg_tmp_point)
-
Loop - Actions
- Custom script: call RemoveRect(udg_tmp_reg)
-
Events
JASS:
function walkable takes location l returns nothing
local boolean b
local real x = GetLocationX(l)
local real y = GetLocationY(l)
loop
set b = IsTerrainWalkable(x, y)
if b == true then
set udg_tmp_point = Location(x, y)
exitwhen true
else
set l = Location(GetRandomReal(GetRectMinX(udg_tmp_reg), GetRectMaxX(udg_tmp_reg)), GetRandomReal(GetRectMinY(udg_tmp_reg), GetRectMaxY(udg_tmp_reg)))
set x = GetLocationX(l)
set y = GetLocationY(l)
endif
endloop
endfunction
The problem is that it does not seem to work. Anyone got see what is wrong?