Meteor 2 Scripting Functions
Object
int createObject(string objectName, vector2 pos, float angle, uint8 aiType, uint8 side, string overrideName, bool moving, bool locked, bool multiplayerRespawn)
Create an object (server only).
int objectID = createObject(
"Soldier_Pvt_Rifle.ob",
vector2(100, 100),
0.0,
AI_ROAMING,
1,
"",
false,
false,
false
);
print("Created object " + objectID);
Pass angle as -1 to assign a random angle
void deleteObject(int objectID)
Delete an object (server only).
deleteObject(10);
void moveAwayVanish(int objectID)
Tell an object to move away before being deleted when out of sight (server only).
moveAwayVanish(10);
bool getHidden(int objectID)
Get the hidden status of an object.
if (getHidden(0))
{
print("Object is hidden");
}
else
{
print("Object is visible");
}
void setHidden(int objectID, bool value)
Set the hidden status of an object.
setHidden(0, true);
Works from server and client.
bool getSimulate(int objectID)
Get the simulate status of an object.
if (getSimulate(0))
{
print("Object is not simulated");
}
else
{
print("Object is simulated");
}
void setSimulate(int objectID, bool simulate)
Start or stop simulating an object.
setSimulate(0, faalse);
Works from server and client.
Objects with simulate set to false do nothing and have no physics.
void showTeleport(int objectID)
Perform a teleport effect on an object.
This function:
- Plays a teleport sound effect.
- Shows the object.
- Damages objects underneath the object.
showTeleport(0);
uint8 getSide(int objectID)
Get the side of an object.
uint8 side = getSide(0);
print("Object is on side " + side);
void setSide(int objectID, uint8 side)
Set the side of an object.
setSide(0, 1);
bool getHostile(int objectID)
Determine if an object is hostile/enemy.
float getHits(int objectID)
Get the hits (health) of an object.
float hits = getHits(0);
print("Object has " + hits + " health");
void setHits(int objectID, float hits)
Set the hits (health) of an object.
setHits(0, 500);
Works from server and client.
float getMaxHits(int objectID)
Get the maximum hits (hp) of an object.
float hp = getMaxHits(0);
print("Object has " + hp + " max hits");
float getArmour(int objectID)
Get the armour of an object in the range (0 to 90).
float amour = getArmour(0);
print("Object has " + armour + " armour");
Armour is returned in the range 0 to 90. The result could be normalised by dividing by 100.
bool getIndestructible(int objectID)
Get the indestructible status of an object.
if (getIndestructible(0))
{
print("Object is indestructible");
}
else
{
print("Object is destructible");
}
void setIndestructible(int objectID, bool indestructible)
Set the indestructible status of an object.
setIndestructible(0, true);
Can be called from server or client.
void damageObject(int objectID, float damage, float armourPenetration, int ownerID=-1)
Damage an object.
damageObject(PLAYER_OBJECT, 10, 0);
Can be called from server or client.
float getSpeed(int objectID)
Get the current speed of an object.
float speed = getSpeed(PLAYER_OBJECT);
print("Player is moving at " + speed + " km/h");
The speed is returned in kilometres per hour.
float getMaxSpeed(int objectID)
Get the maximum speed of an object.
float maxSpeed = getMaxSpeed(PLAYER_OBJECT);
print("Player maximum speed is " + maxSpeed + " km/h");
The maximum speed is returned in kilometres per hour.
void setMaxSpeed(int objectID, float speed)
Set the maximum speed of an object.
setMaxSpeed(PLAYER_OBJECT, 100.0f);
The maximum speed is expected in kilometres per hour.
float getDefaultMaxSpeed(int objectID)
Get the default maximum speed of an object.
float defaultMaxSpeed = getDefaultMaxSpeed(PLAYER_OBJECT);
print("Player default maximum speed is " + defaultMaxSpeed + " km/h");
The default maximum speed is returned in kilometres per hour.
uint8 getAiType(int objectID)
Get the AI type of an object.
uint8 aiType = getAiType(0);
print("Object AI type is " + aiType);
The possible values of aiType are AI_NONE, AI_ROAMING, AI_GUARDING, AI_IDLE and AI_GOTO.
void setAiType(int objectID, uint8 aiType)
Set the AI type of an object.
setAiType(0, AI_GUARDING);
The possible values of aiType are AI_NONE, AI_ROAMING, AI_GUARDING, AI_IDLE and AI_GOTO.
Setting the AI type of a vehicle will also update all of its occupants.
void moveTo(int objectID, vector destPos, int destAiType=AI_GUARDING)
Tell an object to move to a position.
moveTo(1, vector2(100,100));
Objects will need to be able to move (e.g. a route must exist for ground/sea units and vehicle units must have a driver)
int getWanderChance(int objectID)
Get an object's wander chance (0 to 100).
print(getWanderChance(0));
void setWanderChance(int objectID, int wanderChance)
Set an object's wander chance.
setWanderChance(0, 50);
wanderChance value must be between 0 (never wanders) and 100 (always wanders).
float getWanderDistance(int objectID)
Get how far an object can wander from it's home position.
print(getWanderDistance(0));
void setWanderDistance(int objectID, float wanderDistance)
Set how far an object can wander from it's home position.
setWanderDistance(0, metresToPixels(20));
setWanderDistance(0, -1);
wanderDistance is in pixels.
A wanderDistance of -1 is unlimited.
vector2 getHomePos(int objectID)
Get an object's home position.
print(getHomePos(0));
void setHomePos(int objectID, vector2 homePos)
Set an object's home position.
setHomePos(0, vector2(100,100));
bool getLocked(int objectID)
Get the locked status of an object.
if (getLocked(0))
{
print("Object is locked");
}
else
{
print("Object is unlocked");
}
void setLocked(int objectID, bool locked)
Set the locked status of an object.
setLocked(0, true);
Locked vehicles cannot be used by players.
Can be called from server or client.
bool getActive(int objectID)
Get the active status of an object.
if (getActive(0))
{
print("Object is active");
}
else
{
print("Object is inactive");
}
bool getForceActive(int objectID)
Get the force active status of an object.
if (getForceActive(0))
{
print("Object is force active");
}
else
{
print("Object is not force active");
}
void setForceActive(int objectID, bool forceActive)
Set the force active status of an object (server only).
setForceActive(0, true);
Setting forceActive prevents an object from sleeping when out of view.
float getWeaponsRange(int objectID)
Get the maximum weapons range of an object.
print(getWeaponsRange(PLAYER_OBJECT));
Returns the longest weapons range of an object in pixels.
If an object has multiple weapons the longest weapon range is returned.
float getSightRange(int objectID)
Get the sight range/distance of an object.
print(getSightRange(PLAYER_OBJECT));
Returns the distance an object can see in pixels.
bool isEnemyNear(int objectID, float maxDistance=-1)
Determine if any enemies are nearby an object.
if (isEnemyNear(PLAYER_OBJECT))
{
print("One or more enemies are nearby");
}
else
{
print("No enemies are nearby");
}
maxDistance is optional (leave blank to use default value).
Similar to isEnemyVisible except without line of sight test.
Underwater enemies are detected.
Range will differ between object types.
bool isEnemyVisible(int objectID)
Determine if an object can see any enemies.
if (isEnemyVisible(PLAYER_OBJECT))
{
print("One or more enemies are visible");
}
else
{
print("No enemies are visible");
}
Underwater enemies are not detected.
int getTarget(int objectID)
Get enemy that this object is currently targeting.
print(getTarget(100));
Returns -1 if there if there is no current target.
bool isTarget(int objectID)
Determine if an object is currently being targeted by an enemy.
if (isTarget(PLAYER_OBJECT))
{
print("Player is being targeted");
}
else
{
print("Player is not being targeted");
}
Does not detect healing by medics or engineers.
This function can be slow and should not be called every frame from onUpdate etc. Use onTick or check at intervals instead.
array<int> getTargetingObjects(int targetObjectID, bool firingOnly)
Get all objects currently targeting an object.
array<int> objects = getTargetingObjects(PLAYER_VEHICLE);
for(uint i=0; i<objects.length(); i++)
{
print(objects[i] + ": " + getDisplayName(objects[i]));
}
This function can be slow and should not be called every frame from onUpdate etc. Use onTick or check at intervals instead.
Set firingOnly to true to only get objects that are engaging the target.
bool getNoTarget(int objectID)
Get the no target status of an object.
if (getNoTarget(PLAYER_OBJECT))
{
print("Player cannot be targeted");
}
else
{
print("Player can be targeted");
}
Works from server and client.
void setNoTarget(int objectID, bool noTarget)
Set the no target status of an object.
setNoTarget(PLAYER_OBJECT, true);
Setting noTarget prevents an object from being targeted by other other objects.
Works from server and client.
bool getHoldFire(int objectID)
Get the hold fire status of an object.
if (getHoldFire(10))
{
print("Object 10 is holding fire");
}
else
{
print("Object 10 can engage");
}
Works from server and client.
void setHoldFire(int objectID, bool holdFire)
Set the hold fire status of an object.
setHoldFire(10, true);
Setting holdFire prevents an object from targeting other objects.
Works from server and client.
void getUnitHasFlashlight(bool hasFlashlight)
Determine if the specified unit has a flashlight.
bool playerHasFlashlight = getUnitHasFlashlight(PLAYER_OBJECT);
print("playerHasFlashlight = " + playerHasFlashlight);
void setUnitHasFlashlight(bool hasFlashlight)
Give or take a flashlight from the specified unit.
setUnitHasFlashlight(PLAYER_OBJECT, true);
print("playerHasFlashlight = " + getUnitHasFlashlight(PLAYER_OBJECT));
Server only.
Works for any unit or player.
bool getFlashlightOn(int objectID)
Determine if a unit's flashlight is on.
print(getFlashlightOn(PLAYER_VEHICLE));
void setFlashlightOn(int objectID, bool on)
Switch a unit's flashlight on or off.
setFlashlightOn(PLAYER_OBJECT, true);
Can be called from server or client.
bool getLightMountEnabled(int objectID, int mountIndex)
Get the local enabled status of an object light mount (local only).
print(getLightMountEnabled(PLAYER_VEHICLE, 0));
Light mounts enabled are local only (not network synced).
mountIndex is zero based.
void setLightMountEnabled(int objectID, int mountIndex, bool enabled)
Set the local enabled status of an object light mount (local only).
setLightMountEnabled(PLAYER_VEHICLE, 0, false);
Only affects light mounts locally (not network synced).
mountIndex is zero based.
int getDrawOrder(int objectID)
Get the draw order of an object.
print(getDrawOrder(1));
void setDrawOrder(int objectID, int drawOrder)
Manually set the draw order of an object (server and clients).
setDrawOrder(1, 0);
Note: Draw orders can be swapped automatically but are normally swapped back later (e.g. when getting on and then off a Rocket Bike).
Note: Draw orders can be shuffled up and down as objects are added and removed (they normally remain relative to each other).
Changing the draw order only affects an object's layer (e.g. the player cannot appear under drain cover because that is on a different layer).
Flat objects (e.g. drain covers) have a negative draw order.
Changes are automatically network synced, this function can be called from the server or clients.
Use the drawOrders console command to view all objects draw orders on screen during the game.
int getOriginalDrawOrder(int objectID)
Get the original/initial draw order of an object.
print(getOriginalDrawOrder(1));
void setOriginalDrawOrder(int objectID, int originalDrawOrder)
Manually override the original/initial draw order of an object (server and clients).
setOriginalDrawOrder(1, 0);
Changes are automatically network synced, this function can be called from the server or clients.
bool objectExists(int objectID)
Check if an object exists.
if (objectExists(1))
{
print("Object 1 exists");
}
else
{
print("Object 1 does not exist");
}
int getTypeNumber(int objectID)
Get an object type number from an object ID.
int typeNumber = getTypeNumber(PLAYER_VEHICLE);
print("Player vehicle is type number " + typeNumber);
Object type numbers are the index of a loaded object type asset. They are local and can differ for each game session.
string getTypeName(int objectID)
Get an object type name from an object ID.
string playerVehicleTypeName = getTypeName(PLAYER_VEHICLE);
print("Player vehicle object type filename: " + playerVehicleTypeName);
uint getTypeNameLowerHash(int objectID)
Get an object type lower hash name from an object ID.
uint playerVehicleFileHash = getTypeNameLowerHash(PLAYER_VEHICLE);
print("Player vehicle object type filename lower hash: " + playerVehicleFileHash);
int objectTypeNameToNumber(string objectTypeName)
Resolve an object type name to an object type number.
int typeNumber = objectTypeNameToNumber("hoverboard.ob");
print("Hoverboard is type number " + typeNumber);
string objectTypeNumberToName(int objectTypeNumber)
Resolve an object type number to an object type name.
string typeName = objectTypeNumberToName(1);
print(typeName);
string getClassName(int objectID)
Get the class name for an object (e.g. "Car" or "Helicopter")
string className = getClassName(1);
print(typeName);
uint getTypeClassLowerHash(int objectID)
Get an object class name lower hash from an object ID.
uint classHash = getTypeClassLowerHash(1);
print(classHash);
string getTypeClassName(string resourceName)
Get the class name of an object type.
string className = getTypeClassName("Car01.ob");
print(className); // Car
An "object type" is a type of object not an actual object instance so no existing object is required.
void setFollow(int objectID, int leaderID)
Set an object to follow another object.
setFollow(0, 1);
Set objectToFollowID to -1 to stop following.
array getFollowingObjects(int leaderID)
Get list object IDs that are following the specified object (leader).
array<int> objectIDs = getFollowingObjects(PLAYER_OBJECT);
for (uint i = 0; i < objectIDs.length(); i++)
{
print(objectIDs[i]);
}
void getLeader(int objectID)
Get the leading object being followed by the specified object.
print(getLeader(1));
Returns -1 if not following an object.
bool isOverWater(int objectID)
Is an object entirely over water?
print(isOverWater(PLAYER_OBJECT));
Entirely all 4 corners and the centre of the object are over water.
float getOverWaterScore(int objectID)
Get an object over water score.
print(getOverWaterScore(PLAYER_OBJECT));
Result is between 0 and 1 and depends on how much the object is over water. For example: 0 is not in water, 0.5 is half in water and 1 is entirely in water.
bool isSwimming(int objectID)
Is an object swimming?
print(isSwimming(PLAYER_OBJECT));
Only applies to human objects.
bool isUnderwater(int objectID)
Is an object underwater?
print(isUnderwater(PLAYER_OBJECT));
Does not apply to submerged vehicles. Use isSubmerged to detect if a vehicle is submerged.
bool isSubmerged(int objectID)
Is an object submerged?
print(isSubmerged(PLAYER_VEHICLE));
Only applies to vehicles.
bool isMoving(int objectID)
Is an object moving?
print(isMoving(PLAYER_OBJECT));
void getHasWetsuit(bool hasWetsuit)
Determine if the specified unit has a wetsuit.
bool playerHasWetsuit = getHasWetsuit(PLAYER_OBJECT);
print("playerHasWetsuit = " + playerHasWetsuit);
void setHasWetsuit(bool hasWetsuit)
Give or take wetsuit from the specified unit.
setHasWetsuit(PLAYER_OBJECT, true);
print("playerHasWetsuit = " + getHasWetsuit(PLAYER_OBJECT));
Server only.
Works for any unit or player.
void resetRespawnCoords(int objectID)
Update the respawn coordinates of an object to it's current coordinates (server only).
resetRespawnCoords(0);
string getDisplayName(int objectID)
Get the display name of an object.
string displayName = getDisplayName(PLAYER_VEHICLE);
print("Player vehicle display name is " + displayName);
This function will return the callsign/override name if present otherwise the description is returned. To get the description name in all cases use getDescription().
string getDescription(int objectID)
Get the description of an object.
string desc = getDisplayName(PLAYER_VEHICLE);
print("Player vehicle description is " + desc);
This function will return the object description of the object as specified in the Object Editor (e.g. "Rocket Soldier" or "Tank");
vector2 getTypeSize(string resourceName)
Get the size of an object type in pixels.
vector2 carSize = getTypeSize("Car01.ob");
print("Non-rotated size = " + carSize);
vector2 carMaxRotatedSize = carSize * 1.41;
print("Max rotated size = " + carMaxRotatedSize);
An "object type" is a type of object not an actual object instance so no existing object is required.
Returned size is simply the still sprite size without rotation.
bool getInteractionEnabled(int objectID)
Get whether interaction is enabled for an object.
if (getInteractionEnabled(0))
{
print("Object is interactable");
}
else
{
print("Object is not interactable");
}
An object without interaction cannot be controlled with group control.
void setInteractionEnabled(int objectID, bool interactionEnabled)
Set whether interaction is enabled for an object.
setInteractionEnabled(0, false);
An object without interaction cannot be controlled with group control.
Can be called from server or client.
bool getMultiplayerRespawnEnabled(int objectID)
Get whether an object respawns in multiplayer.
if (getMultiplayerRespawnEnabled(0))
{
print("Object respawns in multiplayer");
}
else
{
print("Object does not respawn in multiplayer");
}
void setMultiplayerRespawnEnabled(int objectID, bool multiplayerRespawnEnabled)
Set whether an object respawns in multiplayer. (server only)
setMultiplayerRespawnEnabled(0, true);
The object must have an AI type of AI_NONE to enable multiplayer respawn.
bool isLocal(int objectID)
Determine if an object is local.
if(isLocal(123))
print("Object is local");
else
print("Object is not local");
AI objects are local to the server.
bool getPaintEnabled(int objectID)
Determine if paint is enabled for an object.
if(getPaintEnabled(PLAYER_OBJECT))
print("Player object paint is enabled");
else
print("Player object paint is disabled");
void setPaintEnabled(int objectID, bool enabled)
Enable or disable paint for an object.
setPaintEnabled(PLAYER_OBJECT, false);
Can be called from server or client.
string getPaintColour(int objectID)
Get the paint colour of an object.
print("Object ID 0 is " + getPaintColour(0));
paintColour is specified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).
void setPaintColour(int objectID, string paintColour)
Set the paint colour of an object.
setPaintColour(0, "#FF0000");
paintColour is specified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).
Can be called from server or client.
string getPaintTexture(int objectID)
Get the paint texture of an object.
print("Player paint texture is " + getPaintTexture(PLAYER_OBJECT));
void setPaintTexture(int objectID, string textureName)
Set the paint texture of an object.
setPaintTexture(PLAYER_OBJECT, "MTP_Urban01");
setPaintColour(PLAYER_OBJECT, "#FFFFFF");
Can be called from server or client.
float getPaintTextureScale(int objectID)
Get the paint texture scale of an object.
print("Player paint texture scale is " + getPaintTextureScale(PLAYER_OBJECT));
void setPaintTextureScale(int objectID, float scale)
Set the paint texture scale of an object.
setPaintTextureScale(PLAYER_OBJECT, 0.1);
Can be called from server or client.
void attachObject(int objectID, int parentID, vector2 offset, float offsetAngle)
Attach an object to another object (server and clients).
attachObject(10, PLAYER_OBJECT, vector2(0,0), 0);
Attached objects have no physics.
Objects cannot be attached to already attached objects.
void detachObject(int objectID)
Detach an attached object from it's parent (server and clients).
detachObject(10);
array getAttachedObjects(int parentID)
Get a list of object IDs that are attached to the specified parent object (server and clients).
array<int> objectIDs = getAttachedObjects(PLAYER_OBJECT);
for (uint i = 0; i < objectIDs.length(); i++)
{
print(objectIDs[i]);
}
int getAttachedToParent(int objectID)
Get an attached object's parent object ID.
int parentObjectID = getAttachedToParent(10);
print(parentObjectID);
Returns -1 if not attached to a parent object.
bool getIsVivTransport(int objectID)
Determine if an object is a vehicle in vehicle (VIV) transport (e.g. LCVP boat).
bool isViv = getIsVivTransport(PLAYER_VEHICLE);
if(isViv)
print("Vehicle can carry other vehicles");
else
print("Vehicle cannot carry other vehicles");
Essentially checks if "VIV Attach" object type helper exists.
int getVivObject(int parentID)
Get the object currently loaded onto the specified VIV transport vehicle.
bool vivChildID = getVivObject(PLAYER_VEHICLE);
if(vivChildID != -1)
print("Object " + vivChildID + " is loaded on the vehicle");
else
print("No object is loaded onto the vehicle");
Returns -1 is no object is loaded onto the vehicle.
Remote computers can take a few moments to show changes from loading/unloading.
int getVivParent(int objectID)
Get the VIV transport vehicle that the specified object is loaded onto
bool vivParentID = getVivParent(PLAYER_VEHICLE);
if(vivParentID != -1)
print("Vehicle is loaded onto parent vehicle " + vivParentID);
else
print("Vehicle is not loaded onto another vehicle");
Returns -1 is not loaded onto a parent vehicle.
Remote computers can take a few moments to show changes from loading/unloading.
void vivLoad(int objectID, bool parentID, bool hidden)
Load object onto parent VIV transport vehicle. Will fail is another vehicle is already loaded.
vivLoad(10, 100, false);
This function can fail (no space on parent vehicle etc), use getVivParent if checking is required.
void vivUnload(int objectID, bool front)
Unload object from parent VIV transport vehicle.
vivUnload(10, true)
Set front to false to unload to behind the object's parent VIV transport vehicle.
This function can fail (no space, not loaded etc), use getVivParent if checking is required.
int getTrailerObject(int parentID)
Get the current trailer object by the specified parent object (server and clients).
print("Player vehicle trailer is " + getTrailerObject(PLAYER_VEHICLE));
Returns -1 if no trailer is attached.
int getTrailerParent(int objectID)
Get the parent object for the specified trailer object (server and clients).
print("Player vehicle is being pulled by " + getTrailerParent(PLAYER_VEHICLE));
Returns -1 if the specified object is not a trailer.
int getTrailerFront(int objectID)
Get the front parent object for the specified trailer object (server and clients).
print("The front of the player train is object " + getTrailerFront(PLAYER_VEHICLE));
Gets the frontmost parent object in the trailer chain.
Returns the specified object if the object is at the front, or if the object is not a trailer.
void setTrailerObject(int parentID, int objectID)
Set the trailer object of the specified parent object (server and clients).
setTrailerObject(1, 2);
Specify -1 as the objectID to detach a trailer.
void createTrailerChain(array trailerObjectIDs)
Creates a chain of trailer objects (server and clients).
createTrailerChain({ 1, 2, 3 });
The object IDs should be from front to back.
void carryObject(int parentID, int objectID)
Pick up a carriable object (server and clients).
carryObject(PLAYER_OBJECT, 10);
Carried objects have no physics.
Only carriable objects that are not already being carried can be picked up.
Units cannot use weapons while carrying an object.
If a unit is already carrying and object it will be dropped.
void dropCarryingObject(int parentID)
Drop a carried object (server and clients).
dropCarryingObject(PLAYER_OBJECT);
parentID is the unit carrying the object (not the object being carried).
int getCarryingObject(int parentID)
Get the current object carried by the specified parent object (server and clients).
print(getCarryingObject(PLAYER_OBJECT));
Returns -1 if no carrying object.
int getCarryingParent(int objectID)
Get the parent for an object that is being carried.
int parentObjectID = getCarryingParent(10);
print(parentObjectID);
Returns -1 if object is not being carried.
int addAction(int objectID, string name, string code, float useDistance, string colour="", bool autoClose=true)
Add an object action.
void onObjectSpawn(int objectID)
{
code = "print("ID: " + OBJECT + ");";
addAction(OBJECT, "Show ID, code, 32);
}
Actions are local only.
useDistance is in pixels added to the radius (based on largest sprite dimension) of the object.
Returns -1 if the action could not be created.
Try to use the playerIO instead of the player object ID for action code because the player ID persists after player respawn in multiplayer.
void removeAction(int objectID, int actionID)
Remove an object action.
void removeAllActions(int objectID)
Remove all actions from an object.
bool getActionEnabled(int objectID, int actionID)
Determine if an object action is enabled.
void setActionEnabled(int objectID, int actionID, bool enabled)
Enable to disable an object action.
bool getActionEnabled(int objectID, int actionID)
Determine if an object action exists.
bool getActionsCount(int objectID)
The the count of actions for an object.
Index