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(
"Solider_Pvt_Rifle.ob",
vector2(100, 100),
0.0,
AI_ROAMING,
1,
"",
false,
false,
false
);
print("Created object " + objectID);
void deleteObject(int objectID)
Delete an object (server only).
deleteObject(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);
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);
void damageObject(int objectID, float damage, float armourPenetration, int ownerID=-1)
Damage an object (server only).
damageObject(PLAYER_OBJECT, 10, 0);
float getSpeed(int objectID)
Get the current speed of an object.
float speed = getSpeed(PLAYER_OBJECT);
print("Player is moving at " + metresPerSecond + " 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.
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)
Get 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. (server only)
setLocked(0, true);
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.
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)
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.
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");
}
void setNoTarget(int objectID, bool noTarget)
Set the no target status of an object.
setNoTarget(PLAYER_OBJECT, true);
Setting noTarget prevents AI from targeting an object.
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);
void setFollow(int objectID, int objectToFollowID)
Set an object to follow another object (server only).
setFollow(0, 1);
Set objectToFollowID to -1 to stop following.
bool isOverWater(int objectID)
Is an object over water?
print(isOverWater(PLAYER_OBJECT));
bool isSwimming(int objectID)
Is an object swimming?
print(isSwimming(PLAYER_OBJECT));
Only applies to human objects.
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);
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 getInteractionEnabled(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.
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, string paintColour)
Enable or disable paint for an object (server only).
setPaintEnabled(PLAYER_OBJECT, false);
string getPaintColour(int objectID)
Get the paint colour of an object.
print("Object ID 0 is " + getPaintColour(0));
paintColour 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 setPaintColour(int objectID, string paintColour)
Set the paint colour of an object (server only).
setPaintColour(0, "#FF0000");
paintColour 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 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 (server only).
setPaintTexture(PLAYER_OBJECT, "MTP_Urban01");
setPaintColour(PLAYER_OBJECT, "#FFFFFF");
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 (server only).
setPaintTextureScale(PLAYER_OBJECT, 0.1);
void attachObject(int objectID, int parentID, vector2 offset, float offsetAngle)
Attach an object to another object (server and clients).
attachObject(10, getLocalPlayerObject(), 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(getLocalPlayerObject());
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 inVehicle(int objectID)
Get whether an object is in a vehicle.
if (inVehicle(PLAYER_OBJECT))
{
print("Player is in a vehicle");
}
else
{
print("Player is not in a vehicle");
}
int getVehicle(int objectID)
Get the vehicle object ID which an object is in, or the object's ID if not in a vehicle.
print("Object 1's vehicle object is " + getVehicle(1));
print("Player's vehicle object is " + PLAYER_VEHICLE);
bool getInVehicle(int objectID, int vehicleObjectID)
Place an object in a vehicle.
getInVehicle(PLAYER_OBJECT, 1);
bool getOutOfVehicle(int objectID, bool placeInCentre)
Get an object out of a vehicle.
getOutOfVehicle(PLAYER_OBJECT, false);
getOutOfVehicle(PLAYER_OBJECT, true);
Setting placeInCentre to false will search for a suitable location for the object to get out, and will fail if a suitable location is not found.
Setting placeInCentre to true will get the object out on top of the vehicle, but is guaranteed to succeed.
Index