Skip to content

Instantly share code, notes, and snippets.

@Shilo
Created February 21, 2018 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shilo/c6f81e336eefabc72e7423109b5969a7 to your computer and use it in GitHub Desktop.
Save Shilo/c6f81e336eefabc72e7423109b5969a7 to your computer and use it in GitHub Desktop.
VyScript to implement open world warping. When colliding with the map edge, it will automatically warp to the next map. (Vylocity engine: http://vylocity.com/)
#define MAP_NAME_COORD_DELIMITER "_"
Mob/Player
onBump(pB)
if (pB == Map.void)
var warpMap = null
var warpX = this.xPos;
var warpY = this.yPos;
var warpMapCoords = this.get_outside_map_coords(this.mapName)
if (this.xPos == -this.xOrigin) //left
warpMapCoords.x -= 1;
warpMap = this.get_outside_map_name(warpMapCoords)
warpX = Map.getMapSize(warpMap).xPos-this.xOrigin-this.width
else if (this.yPos == -this.yOrigin) //up
warpMapCoords.y -= 1;
warpMap = this.get_outside_map_name(warpMapCoords)
warpY = Map.getMapSize(warpMap).yPos-this.yOrigin-this.height
else if (this.xPos == Map.getMapSize(this.mapName).xPos-this.xOrigin-this.width) //right
warpMapCoords.x += 1;
warpMap = this.get_outside_map_name(warpMapCoords)
warpX = -this.xOrigin
else //down
warpMapCoords.y += 1;
warpMap = this.get_outside_map_name(warpMapCoords)
warpY = -this.yOrigin
if (warpMap != null)
this.setPos(warpX, warpY, warpMap)
function get_outside_map_coords(mapName)
var pathComponents = mapName.split("/")
mapName = pathComponents[pathComponents.length-1]
var components = mapName.split(MAP_NAME_COORD_DELIMITER)
return {'x':Util.parseInt(components[0]), 'y':Util.parseInt(components[1])}
function get_outside_map_name(coords)
return this.get_outside_map_name_2(coords.x, coords.y)
function get_outside_map_name_2(x, y)
var mapName = x+MAP_NAME_COORD_DELIMITER+y
return Map.getMapSize(mapName).x>0 ? mapName : null
@Shilo
Copy link
Author

Shilo commented Feb 21, 2018

This script assumes you have maps named with the following syntax: "X_Y"
Example of a world with 9 maps connected:

  1. "-1_-1" = (top-left map)
  2. "-1_0" = (middle-left map)
  3. "-1_1" = (bottom-left map)
  4. "0_-1" = (top-center map)
  5. "0_0" = (middle-center map)
  6. "0_1" = (bottom-center map)
  7. "1_-1" = (top-right map)
  8. "1_0" = (middle-right map)
  9. "1_1" = (bottom-right map)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment