You just answered your own question.
Use GetLocationX() and GetLocationY() if you want to use a point as the perameters.
If you're working with things like pathing maps, you should not be using GUI.
//Thanks to anitarf and Vexorian @ wc3c.net for this library, it makes things easier.
library IsTerrainWalkable initializer Init
globals
// this value is how far from a point the item may end up for the point to be considered pathable
private constant real MAX_RANGE=10.
// the following two variables are set to the position of the item after each pathing check
// that way, if a point isn't pathable, these will be the coordinates of the nearest point that is
public real X=0.
public real Y=0.
private rect r
private item check
private item array hidden
private integer hiddenMax=0
endglobals
private function Init takes nothing returns nothing
set check=CreateItem('ciri',0,0)
call SetItemVisible(check,false)
set r=Rect(0.0,0.0,128.0,128.0)
endfunction
private function HideBothersomeItem takes nothing returns nothing
if IsItemVisible(GetEnumItem()) then
set hidden[hiddenMax]=GetEnumItem()
call SetItemVisible(hidden[hiddenMax],false)
set hiddenMax=hiddenMax+1
endif
endfunction
function IsTerrainWalkable takes real x, real y returns boolean
// first, hide any items in the area so they don't get in the way of our item
call MoveRectTo(r,x,y)
call EnumItemsInRect(r,null,function HideBothersomeItem)
// try to move the check item and get it's coordinates
call SetItemPosition(check,x,y)//this unhides the item...
set X=GetItemX(check)
set Y=GetItemY(check)
call SetItemVisible(check,false)//...so we must hide it again
// before returning, unhide any items that got hidden at the start
loop
exitwhen hiddenMax<=0
set hiddenMax=hiddenMax-1
call SetItemVisible(hidden[hiddenMax],true)
set hidden[hiddenMax]=null
endloop
// return pathability status
return (x-X)*(x-X)+(y-Y)*(y-Y)<MAX_RANGE*MAX_RANGE
endfunction
endlibrary
Please excuse me for not linking the original, but here's IsTerrrainWalkable from one of my maps -
JASS://Thanks to anitarf and Vexorian @ wc3c.net for this library, it makes things easier. library IsTerrainWalkable initializer Init globals // this value is how far from a point the item may end up for the point to be considered pathable private constant real MAX_RANGE=10. // the following two variables are set to the position of the item after each pathing check // that way, if a point isn't pathable, these will be the coordinates of the nearest point that is public real X=0. public real Y=0. private rect r private item check private item array hidden private integer hiddenMax=0 endglobals private function Init takes nothing returns nothing set check=CreateItem('ciri',0,0) call SetItemVisible(check,false) set r=Rect(0.0,0.0,128.0,128.0) endfunction private function HideBothersomeItem takes nothing returns nothing if IsItemVisible(GetEnumItem()) then set hidden[hiddenMax]=GetEnumItem() call SetItemVisible(hidden[hiddenMax],false) set hiddenMax=hiddenMax+1 endif endfunction function IsTerrainWalkable takes real x, real y returns boolean // first, hide any items in the area so they don't get in the way of our item call MoveRectTo(r,x,y) call EnumItemsInRect(r,null,function HideBothersomeItem) // try to move the check item and get it's coordinates call SetItemPosition(check,x,y)//this unhides the item... set X=GetItemX(check) set Y=GetItemY(check) call SetItemVisible(check,false)//...so we must hide it again // before returning, unhide any items that got hidden at the start loop exitwhen hiddenMax<=0 set hiddenMax=hiddenMax-1 call SetItemVisible(hidden[hiddenMax],true) set hidden[hiddenMax]=null endloop // return pathability status return (x-X)*(x-X)+(y-Y)*(y-Y)<MAX_RANGE*MAX_RANGE endfunction endlibrary
Try removing the library/endlibrary lines, then change the function Init's name to InitTrig_TerrainWalkable, then put it in the Map header.
If you're getting that error, sounds like you DO have JNGP.
What was the error with the first script? before doing what magtheridon said, that is.
After importing it? Just put it in an empty trigger called "IsTerrainWalkable".
Then use IsTerrainWalkable(x,y) as a custom script elsewhere.
You should be writing jass triggers, not using custom scripts
You can convert this library to non-vJass but the effort is not worth it.
You have JNGP. You obviously have at least a beginner's knowledge of jass.
It's time to switch. PM me if you want help.
library GetPathablePoint
function GetPathablePointInRect takes rect r returns nothing
set udg_TempInt = 1
loop
exitwhen udg_TempInt > 10
set udg_TempLoc = GetRandomLocInRect(r)
if (IsTerrainWalkable(GetLocationX(udg_TempLoc), GetLocationY(udg_TempLoc))) == true then
set udg_TempInt = 10
else
set udg_TempInt = 1
endif
set udg_TempInt = udg_TempInt + 1
endloop
endfunction
endlibrary
library GetPathablePoint requires IsTerrainWalkable
function GetPathablePointInRect takes rect r returns location
local location loc
local real randX=GetRectCenterX(r)
local real randY=GetRectCenterY(r)
loop
exitwhen IsTerrainWalkable(randX,randY)
set randX=GetRandomReal(GetRectMinX(r),GetRectMaxX(r))
set randY=GetRandomReal(GetRectMinY(r),GetRectMaxY(r))
endloop
set Loc=Location(loc,randX,randY)
return loc
endfunction
endlibrary
JASS:library GetPathablePoint requires IsTerrainWalkable function GetPathablePointInRect takes rect r returns location local location loc local real randX=GetRectCenterX(r) local real randY=GetRectCenterY(r) loop exitwhen IsTerrainWalkable(randX,randY) set randX=GetRandomReal(GetRectMinX(r),GetRectMaxX(r)) set randY=GetRandomReal(GetRectMinY(r),GetRectMaxY(r)) endloop set Loc=Location(loc,randX,randY) return loc endfunction endlibrary
NB: If the given rect contains no walkable points, the thread will crash.
set Loc=Location(loc,randX,randY)
set loc=Location(randX,randY)
// Required Globals
// Create these globals using the variable editor
//real TW_MAX_RANGE
//real TW_X
//real TW_Y
//rect TW_r
//item TW_check
//item array TW_hidden
//integer TW_hiddenMax
function HideBothersomeItem takes nothing returns nothing
if IsItemVisible(GetEnumItem()) then
set udg_TW_hidden[udg_TW_hiddenMax] = GetEnumItem()
call SetItemVisible(udg_TW_hidden[udg_TW_hiddenMax], false)
set udg_TW_hiddenMax = udg_TW_hiddenMax + 1
endif
endfunction
function IsTerrainWalkable takes real x, real y returns boolean
call MoveRectTo(udg_TW_r, x, y)
call EnumItemsInRect(udg_TW_r, null, function HideBothersomeItem)
call SetItemPosition(udg_TW_check, x, y)//this unhides the item...
set udg_TW_X=GetItemX(udg_TW_check)
set udg_TW_Y=GetItemY(udg_TW_check)
call SetItemVisible(udg_TW_check, false)//...so we must hide it again
loop
exitwhen udg_TW_hiddenMax <= 0
set udg_TW_hiddenMax = udg_TW_hiddenMax - 1
call SetItemVisible(udg_TW_hidden[udg_TW_hiddenMax], true)
set udg_TW_hidden[udg_TW_hiddenMax] = null
endloop
return (x - udg_TW_X) * (x - udg_TW_X) + (y - udg_TW_Y) * (y - udg_TW_Y) < udg_TW_MAX_RANGE * udg_TW_MAX_RANGE
endfunction
function InitTrig_initTerrainWalk takes nothing returns nothing
set udg_TW_MAX_RANGE = 10
set udg_TW_X = 0
set udg_TW_Y = 0
set udg_TW_r = Rect(0, 0, 128, 128)
set udg_TW_check = CreateItem('ciri', 0, 0)
call SetItemVisible(udg_TW_check, false)
set udg_TW_hiddenMax = 0
endfunction