Meteor 2 Scripting Functions
World
string getWorldName()
Get the world name (map title)
print(getWorldName());
int getWorldSeed()
Get the world random seed.
print(getWorldSeed());
void setWorldSeed(int seed)
Set the world random seed for new objects.
The random seed is used to generate object names (e.g. character names and vehicle callsigns).
Using a seed ensures that object names will always be the same each time the map is run.
The default seed is generated from the map filename so renaming a map will rename all the people on it.
setWorldSeed(1234);
Changing the seed using script only affects objects created after the game is started because placed objects are created before any script is run.
To overcome this while using a predefined seed, set the "map seed" property in the Map Editor.
vector2i getWorldSize()
Get the world (map) size in pixels.
print(getWorldSize());
void setWorldSize(vector2 worldSize, bool broadcast=true)
Set the world (map) size in pixels.
setWorldSize(vector2(2500, 2500));
bool getInfiniteMap()
Determine if the map is infinite.
if(getInfiniteMap())
{
print("Map is infinite");
}
else
{
print("Map is not infinite");
}
void setInfiniteMap(bool infiniteMap)
Enable or disable infinite map. (server only)
setInfiniteMap(true);
Infinite map mode allows all objects to travel outside of the map.
Warning: When using infinite map mode the base sector has "open" collision physics outside of the map bounds allowing all objects to move without restriction (e.g. boats can drive on grass). Other sectors (created using script) are not affected.
Infinite map is disabled by default when the level reloads and restarts.
bool getPlayerFlyOffMap()
Determine if players are allowed to fly aircraft off the map.
if(getPlayerFlyOffMap())
{
print("Players can fly off map");
}
else
{
print("Players cannot fly off map");
}
void setPlayerFlyOffMap(bool playerFlyOffMap)
Enable or disable players being able to fly off and outside of the map. (server only)
setPlayerFlyOffMap(true);
Enable to allow player aircraft to leave the map (in effect to turn around without suddenly stopping at the map bounds).
float getAirHeight()
Get the air render layer height in pixels.
print("Air height is " + getAirHeight());
Objects and effects at or above this height are considered to be in the air and are rendered above ground objects, walls and trees etc.
bool isPosOnMap(vector2 pos)
Determine if a position is on the map.
print(isPosOnMap(vector2(-100, -100))); // false
Always returns true if map is infinite.
vector2 clampPosToMap(vector2 pos)
Clamp a position to the map.
print(clampPosToMap(vector2(-100, -100))); // 0, 0
X and Y are clamped individually.
Will clamp to world size even if map is infinite.
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)
Always returns true if map is infinite.
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)
Always returns true if map is infinite.
int getPosTerrainPassableType(vector2 pos)
Get terrain passable type at exact position (in pixels).
print(getPosTerrainPassableType(vector2(1000,1000)));
Result values:
0 = land
1 = solid
2 = water
3 = clear
4 = above ground
5 = closed
string getMaterialNameAtPos(vector2 pos, bool ignoreShadows=true)
Get material name of uppermost sector the texture at a position (in pixels).
string matName = getMaterialNameAtPos(getPos(PLAYER_OBJECT);
print(matName));
Material name is from textures.ini.
Material is a surface category (e.g. Grass or Ice and not a single texture). Use getTextureNameAtPos to get the texture name.
Out of map bounds will return base sector texture material name.
uint getMaterialNameLowerHashAtPos(vector2 pos, bool ignoreShadows=true)
Get material name lower case hash of the uppermost sector texture at a position (in pixels).
uint matHash = getMaterialNameLowerHashAtPos(getPos(PLAYER_OBJECT);
print(matHash));
Same as getMaterialNameAtPos but returns a hash for high speed comparisons (e.g. planting vegetation in a loop).
string getTextureNameAtPos(vector2 pos)
Get texture name of the uppermost sector texture at a position (in pixels).
string texName = getTextureNameAtPos(getPos(PLAYER_OBJECT);
print(matName));
Out of map bounds will return base sector texture name.
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(PLAYER_OBJECT), 50, 1200, 30, TPT_LAND, 0);
if(foundPos != vector2(0,0))
{
setPos(PLAYER_VEHICLE, foundPos);
}
else
{
print("No empty position found");
}
for(int i=0; i<50; i++)
{
vector2 foundPos = findNearEmptyPos(getPos(PLAYER_OBJECT), 100, 2000, 30, TPT_LAND);
if(foundPos != vector2(0,0))
{
createUnit("blob.ob", foundPos, randomDir());
}
}
for(int i=0; i<20; i++)
{
vector2 foundPos = findNearEmptyPos(getPos(PLAYER_OBJECT), 100, 1000, 30, TPT_WATER);
if(foundPos != vector2(0,0))
{
createUnit("croc.ob", 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 TPT_LAND or TPT_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(PLAYER_OBJECT), 100, 500);
setPos(PLAYER_VEHICLE, 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, TPT_LAND, 0);
if(foundPos != vector2(0,0))
{
setPos(PLAYER_VEHICLE, foundPos);
}
else
{
print("No empty position found");
}
areaSize is the diameter of the space/clearing required.
terrainType should be set to either TPT_LAND or TPT_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(PLAYER_VEHICLE, randomPos);
If the edge padding value is larger than the map width or height * 0.4 then map centre is returned.
bool isRectPassable(vector2 rectCentre, vector2 rectSize, int terrainType)
Check if a rectangle is passable to the specified terrain type.
bool clear = isRectPassable(vector2(10,10), vector2(100,100), TPT_LAND);
print(clear);
Avoid using TPT_SOLID and TPT_CLOSED (these are simply treated as TPT_LAND).
bool checkLineOfSight(vector2 pos1, vector2 pos2, int ignoreObjectID1=-1, int ignoreObjectID2=-1)
Check line of sight is clear between 2 points.
bool clear = checkLineOfSight(getPos(PLAYER_OBJECT), vector2(0,0));
print(clear);
bool clear = checkLineOfSight(getPos(PLAYER_OBJECT), vector2(0,0), PLAYER_OBJECT);
print(clear);
int enemyID = 10;
bool clear = checkLineOfSight(getPos(PLAYER_OBJECT), getPos(enemyID), PLAYER_OBJECT, enemyID);
print(clear);
Specify ignoreObjectID1 and/or ignoreObjectID2 to avoid self collisions or leave as default (-1) if not required.
bool raycast(vector2 origin, vector2 angle, int maxDistance=-1, RayHitData& outHitData, int ignoreObjectID=-1)
Perform a single raycast check along a line.
vector2 startPos = getPos(PLAYER_OBJECT);
float angle = getDir(PLAYER_OBJECT);
float maxDist = 2000;
RayHitData hitResult;
if(raycast(startPos, angle, maxDist, hitResult, PLAYER_OBJECT) && hitResult.valid)
{
print("Hit");
print("pos=" + hitResult.pos);
print("normal=" + hitResult.normal);
print("sectorID=" + hitResult.sectorID);
print("objectID=" + hitResult.objectID);
print("projectileID=" + hitResult.projectileID);
}
else
{
print("No hit");
}
Returns true if something was hit.
Set maxDistance to -1 to use the maximum allowed distance (currently 50000 pixels).
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().
void setLightColour(string colour)
Set the world light colour (server only)
setLightColour("#F77D11");
setLightColour("#F77D11");
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).
string getLightColour()
Get the world light colour.
print("light level: " + getLightLevel());
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).
void setRain(float intensity)
Set the rain intensity (server only)
setRain(0);
setRain(0.5);
setRain(1);
float getRain()
Get the world rain intensity.
print("Rain intensity: " + getRain());
void setWindSpeed(float windSpeed)
Set the world wind speed in m/s (server only)
setWindSpeed(0);
setWindSpeed(12);
setWindSpeed(33);
float getWindSpeed()
Get the world wind speed in m/s.
print("Wind speed m/s: " + getWindSpeed());
void setWindDir(float windDir)
Set the world wind direction in degrees (0-360) (server only)
setWindDir(0);
setWindDir(180);
setWindDir(270);
Wind direction is the origin of the wind (e.g. 180 is blowing from south to north)
float getWindDir()
Get the wind direction in degrees (0-360).
print("wind direction: " + getWindDir());
Wind direction is the origin of the wind (e.g. 180 is blowing from south to north)
void setFog(float density)
Set the world fog density (server only)
setFog(0);
setFog(0.2);
setFog(0.9);
float getFog()
Get the world fog density.
print("fog density: " + getFog());
void setFogColour(string colour)
Set the world fog colour (server only)
setFogColour("#FFFFFF");
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).
An alias called setFogColor can also be used.
string getFogColour()
Get the world fog colour.
print("fog colour: " + getFogColour());
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).
An alias called getFogColor can also be used.
void setAmbientFlag(int flag, float value)
Set an ambient flag for the duration of the mission (local only).
setAmbientFlag(AMB_CITY, 1);
setAmbientFlag(AMB_WATER, -1);
setAmbientFlag(AMB_SHORE, -1);
Ambient flags are used to play ambient sounds and spawn local wildlife around the player.
By default ambient flags are calculated automatically based on the player's current position.
Some flags cannot be calculated automatically and can only be set using setAmbientFlag (e.g. AMB_CITY and AMB_JUNGLE).
Set an ambient flag to -1 (default) to allow the game to work out the current value automatically based on the local player's position.
Set an ambient flag to any value between 0 and 1 to hard set the value for the duration of the current mission.
All ambient flags are reset to -1 (auto) on next mission.
Flags list:
AMB_MEADOW
AMB_FOREST
AMB_JUNGLE (manual only)
AMB_CITY (manual only)
AMB_WATER
AMB_SHORE
AMB_UNDERWATER
AMB_RAIN
AMB_WIND
AMB_STORM (manual only)
AMB_BATTLE (manual only)
AMB_CREEPY (manual only)
void setAllAmbientFlags(float value)
Set all ambient flags for the duration of the mission.
void onStart()
{
setAllAmbientFlags(0);
setAmbientFlag(AMB_UNDERWATER, 1);
}
float getAmbientFlag(int flat)
Get an ambient flag value.
print(getAmbientFlag(AMB_UNDERWATER));
This shows the configured (not current) flag value. Use getAmbientValue to get the current evaluated value.
float getAmbientValue(int flat)
Get a current ambient flag evaluated value.
print(getAmbientValue(AMB_FOREST));
This gets the current automatically (or forced) value, it will always be between 0 and 1.
For example standing near a body of water should return high values (0 to 1) for AMB_WATER and AMB_SHORE.
vector2 getAmbientSoundsGain()
Get the ambient shore pos.
The ambient shore pos is the location of the nearest shore and is used for ambient sound spatialisation.
float getAmbientSoundsGain()
Get the ambient sound gain.
Ambient sound game is specfied in the Options and is value between 0 and 1.
int createTreeSpawner(vector2 pos, float radius, bool circle, float density, bool allowOverlap, uint speciesLowerHash, float seed, int treeSpawnerID=-1, bool broadcast=true)
Create a tree spawner.
uint oakTreeHash = createStringHashLowerCase("Tree_Oak01.ini");
createTreeSpawner(getPos(PLAYER_OBJECT), 500, true, 1, false, oakTreeHash, randomSeed(), -1, true);
uint randomSpeciesHash = createStringHashLowerCase("Default");
createTreeSpawner(getPos(PLAYER_OBJECT) + vector2(500,500), 500, true, 1, false, randomSpeciesHash, randomSeed(), -1, true);
Returns tree spawner ID or -1 if failed to create.
Set circle to false to create a square shaped spawner.
void deleteTreeSpawner(int treeSpawnerID, bool broadcast=true)
Delete a tree spawner.
void updateTrees()
Force trees and trees on minimap update.
Thre is no need to call this function after adding/removing tree spawners as it is normally handled automatically.
bool saveMap(string (in maps folder) filename)
Save the map to a .map file.
saveMap("TestMap");
Useful for saving dynamically generated maps.
Filename must be a file only (no paths are allowed).
File will be saved in base\maps (or mod folder\maps).
Existing map files cannot be overwritten so the target filename must not exist.
bool saveMapSectorsOverlay(string (in maps folder) filename)
Save minimap sectors overlay image to .png file.
saveMapSectorsOverlay("MapName_Overlay_Sectors");
Saving the sectors overlay makes the minimap initialise faster on maps containing a large number of sectors/vertices.
Filename must be a file only (no paths are allowed).
File will be saved in base\maps (or mod folder\maps).
Existing files cannot be overwritten so the target filename must not exist.
bool saveMapTreesOverlay(string (in maps folder) filename)
Save minimap trees overlay image to .png file.
saveMapTreesOverlay("MapName_Overlay_Trees");
Saving the trees overlay makes the minimap initialise faster on maps containg a large number of trees and all trees and tree spawners have the same properties each time the map is loaded.
Filename must be a file only (no paths are allowed).
File will be saved in base\maps (or mod folder\maps).
Existing files cannot be overwritten so the target filename must not exist.
int getObjectsCount()
Get total number of alive objects on the map.
print("All Objects " + getObjectsCount());
int getHumansCount()
Get total number of alive humans on the map.
print("Humans: " + getHumansCount());
int getVehiclesCount()
Get total number of alive vehicles on the map.
print("Vehicles: " + getVehiclesCount());
array<int> getNearObjects(vector2 pos, float radius)
Get all objects in a circle.
array<int> objects = getNearObjects(getPos(PLAYER_OBJECT), metresToPixels(10));
for(uint i=0; i<objects.length(); i++)
{
print(objects[i] + ": " + getDisplayName(objects[i]));
}
radius is in pixels.
array<int> getAllObjects()
Get all objects.
array<int> objects = getAllObjects();
for(uint i=0; i<objects.length(); i++)
{
print(objects[i] + ": " + getDisplayName(objects[i]));
}
array<int> getNearSprites(vector2 pos, float radius)
Get all map sprites in a circle.
array<int> sprites = getNearSprites(getPos(PLAYER_OBJECT), metresToPixels(10));
for(uint i=0; i<sprites.length(); i++)
{
print(sprites[i] + ": " + getSpriteTypeName(sprites[i]));
}
radius is in pixels.
array<int> getAllSprites()
Get all map sprites.
array<int> sprites = getAllSprites();
for(uint i=0; i<sprites.length(); i++)
{
print(sprites[i] + ": " + getSpriteTypeName(sprites[i]));
}
Index