<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>MapFunctions</title><revhistory><revision><revnumber>31</revnumber><date>2016-05-16 18:23:10</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>30</revnumber><date>2015-09-07 22:51:45</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>29</revnumber><date>2015-09-07 22:48:28</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>28</revnumber><date>2015-09-07 22:46:03</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>27</revnumber><date>2015-09-07 22:28:01</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>26</revnumber><date>2015-09-07 22:22:07</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>25</revnumber><date>2015-09-07 22:21:03</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>24</revnumber><date>2015-09-07 22:16:44</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>23</revnumber><date>2015-04-20 15:01:39</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>22</revnumber><date>2015-02-08 05:25:51</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>21</revnumber><date>2014-12-27 21:20:28</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>20</revnumber><date>2014-12-27 21:19:37</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>19</revnumber><date>2014-12-27 19:20:38</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>18</revnumber><date>2014-12-27 19:20:02</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>17</revnumber><date>2014-12-27 18:07:19</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>16</revnumber><date>2014-12-27 18:00:48</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>15</revnumber><date>2014-12-26 22:12:48</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>14</revnumber><date>2014-12-26 22:10:16</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>13</revnumber><date>2014-12-26 22:04:50</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>12</revnumber><date>2014-12-26 21:53:20</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>11</revnumber><date>2014-12-26 21:35:05</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>10</revnumber><date>2014-12-26 21:34:43</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>9</revnumber><date>2014-12-26 21:30:08</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>8</revnumber><date>2014-12-26 21:29:21</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>7</revnumber><date>2014-12-26 20:39:13</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>6</revnumber><date>2014-12-26 20:32:02</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>5</revnumber><date>2014-12-26 20:30:57</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>4</revnumber><date>2014-12-26 20:30:38</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>3</revnumber><date>2014-12-26 20:12:45</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>2</revnumber><date>2014-12-26 20:12:07</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>1</revnumber><date>2014-12-26 20:02:18</date><authorinitials>Inanna</authorinitials></revision></revhistory></articleinfo><para>See also: <ulink url="http://guide.neatportal.com/wiki/MapFunctions/wiki/FieldTypes#">FieldTypes</ulink></para><section><title>AllCastles</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>AllCastles(fieldId1,fieldId2) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>AllCastles(0,159399) </para></entry></row></tbody></tgroup></informaltable><para>This function returns an array of MapCastleBean objects within an area. The first fieldId will be the northwest (top left) most corner of the area. The second fieldId will be the southeast (bottom right) most corner of the area. Both values must be field id not coordinates.  </para><para>This example returns an array of all MapCastleBean objects within the state of Friesland: </para><itemizedlist><listitem override="none"><screen><![CDATA[scanrec 0,0 199,199
castles = AllCastles(GetFieldId(0,0),GetFieldId(199,199))
]]><![CDATA[
Result:
Too long to post, just try it ;)]]></screen></listitem></itemizedlist><para>This example will return an array of all MapCastleBean objects within a specified distance. Like a radius but in a rectangle... </para><itemizedlist><listitem override="none"><screen><![CDATA[distance = 5
execute "rescanrec {city.x - distance},{city.y - distance} {city.x + distance},{city.y + distance}"
castles = AllCastles(GetFieldId(city.x - distance,city.y - distance),GetFieldId(city.x + distance , city.y + distance))
]]><![CDATA[
echo "There are {castles.length} cities within {distance} miles of {city.name}({city.coords})." 
]]><![CDATA[
label next
info = castles.shift()
if info == null end
echo  "Coord: {FieldIdToCoords(info.id)}, Username: {info.userName}, Alliance: {info.allianceName}, Prestige: {info.prestige}"
goto next
]]><![CDATA[
Result (debug off to reduce confusion/spam):
12:58:08 SCAN COMPLETED: 455,350 465,360
12:58:09 There are 6 cities within 5 miles of MyCity(460,355).
12:58:12 Coord: 455,353, Username: Bob, Alliance: null, Prestige: 4991
12:58:16 Coord: 457,353, Username: Fred, Alliance: null, Prestige: 8060
12:58:20 Coord: 459,357, Username: George, Alliance: null, Prestige: 10847
12:58:24 Coord: 457,358, Username: George, Alliance: null, Prestige: 10847
12:58:28 Coord: 464,360, Username: Harry, Alliance: null, Prestige: 0
12:58:32 Coord: 460,355, Username: YayMe, Alliance: 123456, Prestige: 14517826
12:58:35 Script stopped]]></screen></listitem></itemizedlist></section><section><title>FieldIdToCoords</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>FieldIdToCoords(fieldId) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>fid = 284460</para><para>echo FieldIdToCoords(fid) </para></entry></row></tbody></tgroup></informaltable><para>This function converts a field id into coordinates. </para><para>This example finds the coordinates of a field id: </para><itemizedlist><listitem override="none"><screen><![CDATA[fid = 284460
echo FieldIdToCoords(fid)
]]><![CDATA[
Result:
14:58:01 Starting script
14:58:01 Running line 1
14:58:01 fid = 284460
14:58:02 Running line 2
14:58:02 460,355
14:58:03 Script stopped]]></screen></listitem></itemizedlist></section><section><title>FindField</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>FindField(x,y,radius,FieldTypes[,level]) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>FindField(city.x,city.y,20,12,10) </para></entry></row></tbody></tgroup></informaltable><para>See also: <ulink url="http://guide.neatportal.com/wiki/MapFunctions/wiki/FieldTypes#">FieldTypes</ulink> </para><para>This function can find objects on the map within a specified radius of the searching city. You can for example use FindField to generate a list of all players near you, or all npcs level 10 within 20 miles, or whatever. The FieldTypes usable with FindField are linked above. The level is optional and can be omitted, or you may use &quot;0&quot; for any level. You can echo the results directly, or find and manipulate them from $result. </para><para>This example finds all the flats within a specified radius around your city, then echos the level of each: </para><itemizedlist><listitem override="none"><screen><![CDATA[radius = 20
execute "rescanmap {city.coords} {radius}"
flats = FindField(city.x,city.y,radius,10)
echo "There are {flats.length} flats around {city.name} ({city.coords})."
]]><![CDATA[
label checkFlat
thisFlat = flats.shift()
if thisFlat == null end
echo  "Coord: {FieldIdToCoords(thisFlat)} is a level {GetLevel(thisFlat)} flat."
if flats.length goto checkFlat
]]><![CDATA[
Result (debug off to reduce confusion/spam):
17:02:45 SCAN COMPLETED: 422,319 radius 20
17:02:46 There are 12 flats around MyCity (422,319).
17:02:49 Coord: 410,321 is a level 3 flat.
17:02:53 Coord: 414,320 is a level 5 flat.
17:02:57 Coord: 414,327 is a level 4 flat.
17:03:01 Coord: 419,331 is a level 9 flat.
17:03:05 Coord: 421,306 is a level 1 flat.
17:03:09 Coord: 422,309 is a level 3 flat.
17:03:13 Coord: 423,301 is a level 2 flat.
17:03:17 Coord: 423,308 is a level 1 flat.
17:03:21 Coord: 424,301 is a level 10 flat.
17:03:25 Coord: 424,311 is a level 3 flat.
17:03:29 Coord: 425,302 is a level 9 flat.
17:03:33 Coord: 425,306 is a level 1 flat.
17:03:35 Script stopped]]></screen></listitem></itemizedlist><para>This example gets a list of all npcs level 10 within 20 miles of your city, and then sorts them into an array of nearest to furthest from your city. Note - these are fieldIds not coordinates. You can turn the fieldIds into coordinates using <link linkend="FieldIdToCoords">FieldIdToCoords</link> </para><itemizedlist><listitem override="none"><screen><![CDATA[list = FindField(city.x,city.y,20,12,10).sort(city.compareByDistanceToCastle)
echo list
]]><![CDATA[
Result:
17:09:36 251614,250815,250014,250813,251613,250015,252412,254818,246020,250823,243621,247602,237221,244396
17:09:37 Script stopped]]></screen></listitem></itemizedlist></section><section><title>FormatDistance</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>FormatDistance(fieldId1,fieldId2) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>FormatDistance(12345,23456) </para></entry></row></tbody></tgroup></informaltable><para>This function finds the distance between two field ids and displays it in a nice readable format. </para><para>Basic example: </para><itemizedlist><listitem override="none"><screen><![CDATA[echo FormatDistance(12345,23456)
]]><![CDATA[
Result:
15:27:46 Starting script
15:27:46 Running line 1
15:27:46 90.09 miles
15:27:47 Script stopped]]></screen></listitem></itemizedlist><para>This example finds the distance between your own city and a target coordinates: </para><itemizedlist><listitem override="none"><screen><![CDATA[targ = "123,456"
targetId = GetFieldId(targ)
distance = FormatDistance(city.fieldId,targetId)
echo "Distance from {city.coords} to {targ} is {distance}.
]]><![CDATA[
Result:
15:29:56 Starting script
15:29:56 Running line 1
15:29:56 targ = 123,456
15:29:57 Running line 2
15:29:57 targetId = 364923
15:29:58 Running line 3
15:29:58 distance = 351.80 miles
15:29:59 Running line 4
15:29:59 Distance from 460,355 to 123,456 is 351.80 miles.
15:30:00 Script stopped]]></screen></listitem></itemizedlist></section><section><title>GetDetailInfo</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>GetDetailInfo(FieldId,[priority],[expireSeconds],[compareSeconds]) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>echo GetDetailInfo(GetFieldId(123,456)).name </para></entry></row></tbody></tgroup></informaltable><para>This function is used to get detailed information about a field id. Field id is required as a parameter, priority, expire seconds, and compare seconds are optional.  </para><para><emphasis><emphasis role="strong">Priority</emphasis></emphasis> is a true/false value to determine whether to place a request to the top of the queue for faster processing. It is only used if we have to queue update request. The default is false. </para><para><emphasis><emphasis role="strong">ExpireSeconds</emphasis></emphasis> is how long since map data was last updated until the bot considers data &quot;expired&quot;. This uses current time or value of &quot;now&quot; parameters as described below. The default is 0. If data is considered expired, the bot will queue an update request as needed. </para><para><emphasis><emphasis role="strong">CompareSeconds</emphasis></emphasis> is the timestamp used to compare with for ExpireSeconds. The bot uses the current time if this is set to 0. The default is 0. </para><para>This example returns previously cached map data if we have it cached less than 30 seconds ago (then it returns null, and auto-requests map update) </para><itemizedlist><listitem override="none"><screen><![CDATA[id = GetFieldId(123,234)
data = GetDetailInfo(id, false, 30) 
data = GetDetailInfo(id, false, 0, date().getTime() - 30000) // same as the line above]]></screen></listitem></itemizedlist><para>The above would make &quot;data&quot; into a variable containing the MapCastleBean object for that field id, which you could then reference, for example: </para><itemizedlist><listitem override="none"><screen><![CDATA[id = GetFieldId(123,234)
data = GetDetailInfo(id, false, 30) 
if data == null repeat // repeat above if the map detail info is not available yet
echo data.name
echo data.id
]]><![CDATA[
Result:
16:17:39 Grassland
16:17:40 187323
16:17:41 Script stopped]]></screen></listitem></itemizedlist><para>Or you can even echo the entire object with all it's properties like so: </para><itemizedlist><listitem override="none"><screen><![CDATA[id = GetFieldId(123,234)
data = GetDetailInfo(id, false, 30) 
if data == null repeat // repeat above if the map detail info is not available yet
echo json_encode(data)
]]><![CDATA[
Result:
16:16:54 {"id":187323,"prestige":0,"furlough":false,"name":"Grassland","lastUpdated":1419714992381,"changeface":0,"canLoot":false,"honor":0,"playerLogoUrl":null,"canScout":true,"zoneName":"LOWER LORRAINE","canOccupy":true,"state":1,"npc":false,"userName":null,"canTrans":false,"flag":null,"allianceName":null,"relation":6,"canSend":false}
16:16:55 Script stopped]]></screen></listitem></itemizedlist></section><section><title>GetFieldId</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>GetFieldId(coords) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>coords = &quot;460,355&quot;</para><para>echo GetFieldId(coords) </para></entry></row></tbody></tgroup></informaltable><para>This function converts coordinates into a field id.  </para><para>The field id is a number between 0-63999. Each number directly corresponds to a square on the 800x800 grid map. The game server uses field ids to reference all the squares on the map... 0,0 has field id of 0.... 1,0 has field id of 1... 799,0 has field id of 799... 1,1 is field id 800... and so on. Many of the advanced scripting functions require you to convert your coordinates into fieldIds to use them. </para><para>This example finds the coordinates of a field id: </para><itemizedlist><listitem override="none"><screen><![CDATA[coords = "460,355"
echo GetFieldId(coords)
]]><![CDATA[
Result:
15:07:40 Starting script
15:07:40 Running line 1
15:07:40 coords = 460,355
15:07:42 Running line 2
15:07:42 284460
15:07:43 Script stopped]]></screen></listitem></itemizedlist></section><section><title>GetFieldName</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>GetFieldName(#) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>GetFieldName(10) </para></entry></row></tbody></tgroup></informaltable><para>This function converts a numeric field value into a named string, for example: </para><itemizedlist><listitem override="none"><screen><![CDATA[// get the name of field type 3
echo GetFieldName(3)
]]><![CDATA[
Result:
18:42:42 Hill
18:42:43 Script stopped]]></screen></listitem><listitem override="none"><screen><![CDATA[// first get the type of the 1st valley held in the city, then get the name for that type
echo city.fields[0].type
echo GetFieldName(city.fields[0].type)
]]><![CDATA[
Result:
18:47:30 5
18:47:31 Grassland
18:47:32 Script stopped]]></screen></listitem></itemizedlist><para>The possible field numerics -&gt; strings are as follows: </para><itemizedlist><listitem override="none"><screen><![CDATA[1  Forest    
2  Desert    
3  Hill      
4  Swamp     
5  Grassland 
6  Lake      
10 Flat      ]]></screen></listitem></itemizedlist></section><section><title>GetLevel</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>GetLevel(fieldId) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>GetLevel(city.fieldId) </para></entry></row></tbody></tgroup></informaltable><para>This function returns the level of whatever is located at a certain field id. </para><itemizedlist><listitem override="none"><screen><![CDATA[echo "The object on the map at {FieldIdToCoords(1234)} is level {GetLevel(1234)}." //This is a level 1 desert at coords 434,1 on the map
]]><![CDATA[
Results: 
16:28:35 Running line 1
16:28:35 The object on the map at 434,1 is level 1.
16:28:36 Script stopped]]></screen></listitem></itemizedlist></section><section><title>GetZoneName</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>GetZoneName(fieldId) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>GetZoneName(city.fieldId) </para></entry></row></tbody></tgroup></informaltable><para>This function returns the name of the state a field id is located in. </para><itemizedlist><listitem override="none"><screen><![CDATA[echo "My city is located in {GetZoneName(city.fieldId)}."
]]><![CDATA[
Results: 
16:34:28 Running line 1
16:34:28 My city is located in thuringia.
16:34:29 Script stopped]]></screen></listitem></itemizedlist></section><section><title>MapDistance</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>MapDistance(x1,y1,x2,y2) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>MapDistance(123,456,111,222) </para></entry></row></tbody></tgroup></informaltable><para>This function finds the distance between two sets of coordinates on the map. </para><para>This example finds the distance between your own city and target coordinates, rounded to 2 decimal places: </para><itemizedlist><listitem override="none"><screen><![CDATA[targX = 123
targY = 456
distance = round(MapDistance(city.x,city.y,targX,targY),2)
echo "Distance from {city.coords} to {targX},{targY} is {distance} miles."
]]><![CDATA[
Result:
15:36:13 Starting script
15:36:13 Running line 1
15:36:13 targX = 123
15:36:14 Running line 2
15:36:14 targY = 456
15:36:15 Running line 3
15:36:15 distance = 351.81
15:36:16 Running line 4
15:36:16 Distance from 460,355 to 123,456 is 351.81 miles.
15:36:17 Script stopped]]></screen></listitem></itemizedlist></section><section><title>StateCoords</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>Usage: </para></entry><entry colsep="1" rowsep="1"><para>StateCoords(zone) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Example: </para></entry><entry colsep="1" rowsep="1"><para>StateCoords(&quot;bohemia&quot;) </para></entry></row></tbody></tgroup></informaltable><para>The function returns the state coordinates range, or null if invalid. You may use the zone name or number, for example &quot;Friesland&quot; or 0.  </para><para>Some examples: </para><itemizedlist><listitem override="none"><screen><![CDATA[echo StateCoords("upper lorraine")  // outputs "0,400 199,599"
echo StateCoords(8)                 // outputs "0,400 199,599"
]]><![CDATA[
echo StateCoords("all")             // outputs "0,0 799,799"
]]><![CDATA[
state = "Lombardy"
coords = StateCoords(state)         // coords = "200,600 399,799"
if !coords die "Unknown state name '{state}'"
execute "scanmap {coords}"          // scanmap 200,600 399,799]]></screen></listitem></itemizedlist><!--rule (<hr>) is not applicable to DocBook--><para> <ulink url="http://guide.neatportal.com/wiki/MapFunctions/wiki/CategoryFunctions#">CategoryFunctions</ulink> </para></section></article>