• My Pages
  • Comments
  • Add Link
  • Subscribe
  • Subscribe User
  • Edit (Text)
  • Rename Page
  • Copy Page
  • Load Page
  • Save Page
  • Delete Page
  • Attachments
  • Check Spelling
  • Diffs
  • Info
  • Revert to this revision
  • XML
  • Render as Docbook
  • Print View
  • Raw Text
  • Delete Cache
  • Like Pages
  • Local Site Map
  • Remove Spam
  • Package Pages
  • Sync Pages
    • Diff for "MapFunctions"
    Differences between revisions 7 and 14 (spanning 7 versions)
    Revision 7 as of 2014-12-26 20:39:13
    Size: 5517
    Editor: Inanna
    Comment:
    Revision 14 as of 2014-12-26 22:10:16
    Size: 10009
    Editor: Inanna
    Comment:
    Deletions are marked like this. Additions are marked like this.
    Line 3: Line 3:
    See also: ...<<BR>> See also: FieldTypes<<BR>>
    Line 7: Line 7:
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start;                    " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;                    ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!GetFieldId(coords) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;                    ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">coords = "460,355"<<BR>>echo !GetFieldId(coords) ||
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start; " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!GetFieldId(coords) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">coords = "460,355"<<BR>>echo !GetFieldId(coords) ||
    Line 29: Line 29:
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start;                    " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;                    ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!FieldIdToCoords(fieldId) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;                    ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">fid = 284460<<BR>>echo !FieldIdToCoords(fid) ||
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start; " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!FieldIdToCoords(fieldId) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">fid = 284460<<BR>>echo !FieldIdToCoords(fid) ||
    Line 48: Line 48:
    == FindField ==
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start; " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!FindField(x,y,radius,!FieldTypes[,level]) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!FindField(city.x,city.y,20,12,10) ||

    See also: FieldTypes

    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 "0" for any level. You can echo the results directly, or find and manipulate them from $result.

    This example finds all the flats within a specified radius around your city, then echos the level of each:
     . {{{
    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})."

    label checkFlat
    thisFlat = flats.shift()
    if thisFlat == null end
    echo "Coord: {FieldIdToCoords(thisFlat)} is a level {GetLevel(thisFlat)} flat."
    if flats.length goto checkFlat

    Result (debug off to reduce confusing/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
    }}}

    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 FieldIdToCoords.

     . {{{
    list = FindField(city.x,city.y,20,12,10).sort(city.compareByDistanceToCastle)
    echo list

    Result:
    17:09:36 251614,250815,250014,250813,251613,250015,252412,254818,246020,250823,243621,247602,237221,244396
    17:09:37 Script stopped
    }}}
    Line 49: Line 99:
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start;                    " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;                    ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!MapDistance(x1,y1,x2,y2) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;                    ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!MapDistance(123,456,111,222) ||
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start; " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!MapDistance(x1,y1,x2,y2) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!MapDistance(123,456,111,222) ||
    Line 75: Line 125:
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start;                    " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;                    ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!FormatDistance(fieldId1,fieldId2) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;                    ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!FormatDistance(12345,23456) ||
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start; " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!FormatDistance(fieldId1,fieldId2) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!FormatDistance(12345,23456) ||
    Line 111: Line 161:
    == GetLevel ==
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start; " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!GetLevel(fieldId) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!GetLevel(city.fieldId) ||

    This function returns the level of whatever is located at a certain field id.

     . {{{
    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

    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
    }}}

    == GetZoneName ==
    ||<tablebgcolor="#F9F9F9" tablestyle="margin:1em 1em 1em 0px;border-style:solid;border-color:rgb(170, 170, 170);color:rgb(0, 0, 0);font-family:sans-serif;font-size:13px;line-height:19.5px;text-align:start; " tableclass="wikitable"#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Usage: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!GetZoneName(fieldId) ||
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em; ">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">!GetZoneName(city.fieldId) ||

    This function returns the name of the state a field id is located in.

     . {{{
    echo "My city is located in {GetZoneName(city.fieldId)}."

    Results:
    16:34:28 Running line 1
    16:34:28 My city is located in thuringia.
    16:34:29 Script stopped
    }}}

    See also: FieldTypes
    See also: ...

    GetFieldId

    Usage:

    GetFieldId(coords)

    Example:

    coords = "460,355"
    echo GetFieldId(coords)

    This function converts coordinates into a field id.

    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.

    This example finds the coordinates of a field id:

    • coords = "460,355"
      echo GetFieldId(coords)
      
      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

    FieldIdToCoords

    Usage:

    FieldIdToCoords(fieldId)

    Example:

    fid = 284460
    echo FieldIdToCoords(fid)

    This function converts a field id into coordinates.

    This example finds the coordinates of a field id:

    • fid = 284460
      echo FieldIdToCoords(fid)
      
      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

    FindField

    Usage:

    FindField(x,y,radius,FieldTypes[,level])

    Example:

    FindField(city.x,city.y,20,12,10)

    See also: FieldTypes

    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 "0" for any level. You can echo the results directly, or find and manipulate them from $result.

    This example finds all the flats within a specified radius around your city, then echos the level of each:

    • 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})."
      
      label checkFlat
      thisFlat = flats.shift()
      if thisFlat == null end
      echo  "Coord: {FieldIdToCoords(thisFlat)} is a level {GetLevel(thisFlat)} flat."
      if flats.length goto checkFlat
      
      Result (debug off to reduce confusing/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

    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 FieldIdToCoords.

    • list = FindField(city.x,city.y,20,12,10).sort(city.compareByDistanceToCastle)
      echo list
      
      Result:
      17:09:36 251614,250815,250014,250813,251613,250015,252412,254818,246020,250823,243621,247602,237221,244396
      17:09:37 Script stopped

    MapDistance

    Usage:

    MapDistance(x1,y1,x2,y2)

    Example:

    MapDistance(123,456,111,222)

    This function finds the distance between two sets of coordinates on the map.

    This example finds the distance between your own city and target coordinates, rounded to 2 decimal places:

    • 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."
      
      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

    FormatDistance

    Usage:

    FormatDistance(fieldId1,fieldId2)

    Example:

    FormatDistance(12345,23456)

    This function finds the distance between two field ids and displays it in a nice readable format.

    Basic example:

    • echo FormatDistance(12345,23456)
      
      Result:
      15:27:46 Starting script
      15:27:46 Running line 1
      15:27:46 90.09 miles
      15:27:47 Script stopped

    This example finds the distance between your own city and a target coordinates:

    • targ = "123,456"
      targetId = GetFieldId(targ)
      distance = FormatDistance(city.fieldId,targetId)
      echo "Distance from {city.coords} to {targ} is {distance}.
      
      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

    GetLevel

    Usage:

    GetLevel(fieldId)

    Example:

    GetLevel(city.fieldId)

    This function returns the level of whatever is located at a certain field id.

    • 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
      
      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

    GetZoneName

    Usage:

    GetZoneName(fieldId)

    Example:

    GetZoneName(city.fieldId)

    This function returns the name of the state a field id is located in.

    • echo "My city is located in {GetZoneName(city.fieldId)}."
      
      Results: 
      16:34:28 Running line 1
      16:34:28 My city is located in thuringia.
      16:34:29 Script stopped


    CategoryFunctions

    MapFunctions (last edited 2016-05-16 18:23:10 by Inanna)