Meteor Scripting Functions
World
string getWorldName()
Get the world name (map title)
print(getWorldName());
vector2i getWorldSize()
Get the world (map) size in pixels.
print(getWorldSize());
vector2i getWorldTilesSize()
Get the world (map) size in tiles.
print(getWorldTilesSize());
For reference each tile is 16 by 16 pixels.
int getTile(posX int, posY int)
Get a tile from the map.
print(getTile(0, 0));
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.
void setTile(posX int, posY int, tileIndex int)
Set a tile on the map (server only).
int posX = int(getPos(getPlayer()).x / TILE_SIZE);
int posY = int(getPos(getPlayer()).y / TILE_SIZE);
setTile(posX, posY, 23);
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.
bool isPosOnMap(vector2 pos)
Determine is a position is on the map.
print(isPosOnMap(vector2(-100, -100))); // false
vector2 clampPosToMap(vector2 pos)
Clamp a position to the map.
print(clampPosToMap(vector2(-100, -100))); // 0, 0
X and Y are clamped individually.
bool isPosNearMap(vector2 pos, float maxDistanceFromMapEdge)
Determine if a position is near the map.
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)
maxDistanceFromMapEdge is the max allowed distance from the edge of the map if pos is outside of the map.
bool isRectOnMap(vector2 centrePos, vector2 size)
Determine if a rectangular area intesects the map.
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)
vector2 findNearEmptyPos(vector2 searchPos, float minRadius, float maxRadius, float areaSize, int terrainType, int maxAttempts)
Find an empty nearby land or water position.
vector2 foundPos = findNearEmptyPos(getPos(getPlayer()), 50, 1200, 30, TT_LAND, 0);
if(foundPos != vector2(0,0))
{
setPos(getPlayer(), foundPos);
}
else
{
print("No empty position found");
}
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());
}
}
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());
}
}
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.
vector2 findNearRandomPos(vector2 searchPos, float minDistance, float maxDistance)
Find a random nearby position without any checking.
vector2 nearPos = findNearRandomPos(getPos(getPlayer()), 100, 500);
setPos(getPlayer(), nearPos);
If no position was found the return value is 0,0.
vector2 findEmptyPos(float mapEdgePadding, float areaSize, int terrainType, int maxAttempts)
Find an empty land or water position anywhere on the map.
vector2 foundPos = findEmptyPos(100, 20, TT_LAND, 0);
if(foundPos != vector2(0,0))
{
setPos(getPlayer(), foundPos);
}
else
{
print("No empty position found");
}
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).
vector2 findRandomPos(float mapEdgePadding)
Find a random position anywhere on the map without any checking.
vector2 randomPos = findRandomPos(100);
setPos(getPlayer(), randomPos);
If the edge padding value is larger than the map width or height * 0.4 then map centre is returned.
bool checkLineOfSight(vector2 pos1, vector2 pos2, int[/dt} ignoreObjectID=-1)
Check line of sight is clear between 2 points.
bool clear = checkLineOfSight(getPos(getPlayer()), vector2(0,0));
print(clear);
bool clear = checkLineOfSight(getPos(getPlayer()), vector2(0,0), getPlayer());
print(clear);
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)
setLightLevel(0);
setLightLevel(getNightLightLevel());
setLightLevel(1);
float getLightLevel()
Get the world light level.
print("light level: " + getLightLevel());
float getNightLightLevel()
Get the night light level threshold value.
print("night light level threshold: " + getNightLightLevel());
This value is currently a fixed constant and cannot be changed.
float isNight()
Is night?
print("light level: " + getLightLevel());
This function returns true if the light level drops low enough to be considered night, less than getNightLightLevel().
Index
Generated on the 15 May 2024 at 09:00:40 (UK Time)