Meteor Scripting Functions
World
string getWorldName()
Get the world name (map title)

Example
print(getWorldName());

vector2i getWorldSize()
Get the world (map) size in pixels.

Example
print(getWorldSize());

See also
getWorldTilesSize

vector2i getWorldTilesSize()
Get the world (map) size in tiles.

Example
print(getWorldTilesSize());

Comments
For reference each tile is 16 by 16 pixels.

See also
getWorldSize

int getTile(posX int, posY int)
Get a tile from the map.

Example
// print tile number at top-left corner of map
print(getTile(0, 0));

Comments
Pos values are in tile coords, tiles are 16x16 or use the TILE_SIZE constant.
If the pos is off the map 0 is returned.

See also
setTile

void setTile(posX int, posY int, tileIndex int)
Set a tile on the map (server only).

Example
// get tile coords under player (divide by TILE_SIZE and cast to int to round result towards 0)
int posX = int(getPos(getPlayer()).x / TILE_SIZE);
int posY = int(getPos(getPlayer()).y / TILE_SIZE);

// change tile under player to mud
setTile(posX, posY, 23);

Comments
Pos values are in tile coords, tiles are 16x16 or use the TILE_SIZE constant.
Tile changes are automatically synced to clients.
Normal tileIndex range is 0 to 1024, if the map used an extended tileset the range is from 0-2047.
Add 1024 to tileIndex is setting a tile from an extended tileset.
If the pos is off the map or tileIndex is invalid this function has no effect.

See also
getTile

bool isPosOnMap(vector2 pos)
Determine is a position is on the map.

Example
print(isPosOnMap(vector2(-100, -100))); // false

See also
clampPosToMap isPosNearMap isRectOnMap

vector2 clampPosToMap(vector2 pos)
Clamp a position to the map.

Example
print(clampPosToMap(vector2(-100, -100))); // 0, 0

Comments
X and Y are clamped individually.

See also
isPosOnMap isPosNearMap isRectOnMap

bool isPosNearMap(vector2 pos, float maxDistanceFromMapEdge)
Determine if a position is near the map.

Example
print(isPosNearMap(vector2(0, -101), 100)); // false (not within 100 pixels from map)
print(isPosNearMap(vector2(0, 100), 100)); // true (within 100 pixels from map)
print(isPosNearMap(vector2(1, 1), 100)); // true (always true if on map)

Comments
maxDistanceFromMapEdge is the max allowed distance from the edge of the map if pos is outside of the map.

See also
isPosOnMap clampPosToMap isRectOnMap

bool isRectOnMap(vector2 centrePos, vector2 size)
Determine if a rectangular area intesects the map.

Example
print(isRectOnMap(vector2(100,100), vector2(50,50))); // true (within map)
print(isRectOnMap(vector2(25,25), vector2(50,50))); // true (partially on map)
print(isRectOnMap(vector2(-50,-50), vector2(25,25))); // false (entirely off map)

See also
isPosOnMap clampPosToMap isPosNearMap

vector2 findNearEmptyPos(vector2 searchPos, float minRadius, float maxRadius, float areaSize, int terrainType, int maxAttempts)
Find an empty nearby land or water position.

Example 1
// look between 50 and 1200 pixels from player for 30x30 pixel big area on land.
vector2 foundPos = findNearEmptyPos(getPos(getPlayer()), 50, 1200, 30, TT_LAND, 0);

// move player to foundPos
if(foundPos != vector2(0,0))
{
    setPos(getPlayer(), foundPos);
}
else
{
    print("No empty position found");
}

Example 2
// create up to 50 zombies near player
for(int i=0; i<50; i++)
{
    vector2 foundPos = findNearEmptyPos(getPos(getPlayer()), 100, 2000, 30, TT_LAND);

    if(foundPos != vector2(0,0))
    {
        createUnit("Zombie.ini", foundPos, randomDir());
    }
}

Example 3
// create up to 20 crocodiles near player (in water only)
for(int i=0; i<20; i++)
{
    vector2 foundPos = findNearEmptyPos(getPos(getPlayer()), 100, 1000, 30, TT_WATER);

    if(foundPos != vector2(0,0))
    {
        createUnit("Croc.ini", foundPos, randomDir());
    }
}

Comments
If no position was found the return value is 0,0.
areaSize is the diameter of the space/clearing required.
terrainType should be set to either TT_LAND or TT_WATER.
maxAttempts can be left at 0 (auto based on searchRadius) or be specified.

See also
findNearRandomPos findEmptyPos findRandomPos

vector2 findNearRandomPos(vector2 searchPos, float minDistance, float maxDistance)
Find a random nearby position without any checking.

Example
// find a random position at least 100 but no more than 500 pixels of the player.
vector2 nearPos = findNearRandomPos(getPos(getPlayer()), 100, 500);

// move player to nearPos
setPos(getPlayer(), nearPos);

Comments
If no position was found the return value is 0,0.

See also
findNearEmptyPos findEmptyPos findRandomPos

vector2 findEmptyPos(float mapEdgePadding, float areaSize, int terrainType, int maxAttempts)
Find an empty land or water position anywhere on the map.

Example
// teleport player to a random empty position at least 20x20 pixels big and at least 100 pixels from the edge of the map.
vector2 foundPos = findEmptyPos(100, 20, TT_LAND, 0);

if(foundPos != vector2(0,0))
{
    setPos(getPlayer(), foundPos);
}
else
{
    print("No empty position found");
}

Comments
areaSize is the diameter of the space/clearing required.
terrainType should be set to either TT_LAND or TT_WATER.
maxAttempts can be left at 0 to use default (1000 attempts).

See also
findRandomPos findNearEmptyPos findNearRandomPos

vector2 findRandomPos(float mapEdgePadding)
Find a random position anywhere on the map without any checking.

Example
// find a random position at least 100 pixels from the edge of the map
vector2 randomPos = findRandomPos(100);

// move player to randomPos
setPos(getPlayer(), randomPos);

Comments
If the edge padding value is larger than the map width or height * 0.4 then map centre is returned.

See also
findRandomEmptyPos findNearEmptyPos findNearRandomPos

bool checkLineOfSight(vector2 pos1, vector2 pos2, int[/dt} ignoreObjectID=-1)
Check line of sight is clear between 2 points.

Example 1
// check line of sight
bool clear = checkLineOfSight(getPos(getPlayer()), vector2(0,0));
print(clear);

Example 2
// check line of sight ignoring player
bool clear = checkLineOfSight(getPos(getPlayer()), vector2(0,0), getPlayer());
print(clear);

Comments
Specify ignoreObjectID to avoid self collisions or leave as default (-1) if not required.

void setLightLevel(float level)
Set the world light level (server only)

Example
// Example 1: total darkness
setLightLevel(0);

// Example 2: dark
setLightLevel(getNightLightLevel());

// Example 3: daylight
setLightLevel(1);

See also
getLightLevel getNightLightLevel isNight

float getLightLevel()
Get the world light level.

Example
print("light level: " + getLightLevel());

See also
setLightLevel isNight getNightLightLevel

float getNightLightLevel()
Get the night light level threshold value.

Example
print("night light level threshold: " + getNightLightLevel());

Comments
This value is currently a fixed constant and cannot be changed.

See also
setLightLevel getLightLevel isNight

float isNight()
Is night?

Example
print("light level: " + getLightLevel());

Comments
This function returns true if the light level drops low enough to be considered night, less than getNightLightLevel().

See also
setLightLevel getLightLevel getNightLightLevel


Index