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.

Example
int objectID = createObject(
    "Solider_Pvt_Rifle.ob",
    vector2(100, 100),
    0.0,
    AI_ROAMING,
    1,
    "",
    false,
    false,
    false
);
print("Created object " + objectID);

See also
deleteObject

void deleteObject(int objectID)
Delete an object (server only).

Example
// Delete object ID 10
deleteObject(10);

See also
createObject

void setHidden(int objectID, bool value)
Set the hidden status of an object.

Example
// Hide object ID 0
setHidden(0, true);

See also
getHidden

bool getHidden(int objectID)
Get the hidden status of an object.

Example
if (getHidden(0))
{
    print("Object is hidden");
}
else
{
    print("Object is visible");
}

See also
setHidden

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.

Example
showTeleport(0);

uint8 getSide(int objectID)
Get the side of an object.

Example
uint8 side = getSide(0);
print("Object is on side " + side);

See also
setSide setSideID

void setSide(int objectID, uint8 side)
Set the side of an object.

Example
// Set object ID 0 to side 1
setSide(0, 1);

See also
getSide setSideID

float getHits(int objectID)
Get the hits (health) of an object.

Example
float hits = getHits(0);
print("Object has " + hits + " health");

See also
setHits

void setHits(int objectID, float hits)
Set the hits (health) of an object.

Example
setHits(0, 500);

See also
getHits

bool getIndestructible(int objectID)
Get the indestructible status of an object.

Example
if (getIndestructible(0))
{
    print("Object is indestructible");
}
else
{
    print("Object is destructible");
}

See also
setIndestructible

void setIndestructible(int objectID, bool indestructible)
Set the indestructible status of an object.

Example
// Make object ID 0 indestructible
setIndestructible(0, true);

See also
getIndestructible

float getSpeed(int objectID)
Get the current speed of an object.

Example
float speed = getSpeed(PLAYER_OBJECT);
print("Player is moving at " + metresPerSecond + " km/h");

Comments
The speed is returned in kilometres per hour.

See also
setSpeed getMaxSpeed

void setSpeed(int objectID, float speed)
Set the current speed of an object.

Example
// Set the player speed to 50 km/h
setSpeed(PLAYER_OBJECT, 50.0f);

Comments
The speed is expected in kilometres per hour.

See also
getSpeed setMaxSpeed

float getMaxSpeed(int objectID)
Get the maximum speed of an object.

Example
float maxSpeed = getMaxSpeed(PLAYER_OBJECT);
print("Player maximum speed is " + maxSpeed + " km/h");

Comments
The maximum speed is returned in kilometres per hour.

See also
setMaxSpeed getSpeed getDefaultMaxSpeed

void setMaxSpeed(int objectID, float speed)
Set the maximum speed of an object.

Example
// Set the player maximum speed to 100 km/h
setMaxSpeed(PLAYER_OBJECT, 100.0f);

Comments
The maximum speed is expected in kilometres per hour.

See also
getMaxSpeed setSpeed getDefaultMaxSpeed

float getDefaultMaxSpeed(int objectID)
Get the default maximum speed of an object.

Example
float defaultMaxSpeed = getMaxSpeed(PLAYER_OBJECT);
print("Player default maximum speed is " + defaultMaxSpeed + " km/h");

Comments
The default maximum speed is returned in kilometres per hour.

See also
getMaxSpeed getSpeed

uint8 getAiType(int objectID)
Get the AI type of an object.

Example
uint8 aiType = getAiType(0);
print("Object AI type is " + aiType);

Comments
The possible values of aiType are AI_NONE, AI_ROAMING, AI_GUARDING, AI_IDLE and AI_GOTO.

See also
setAiType

void setAiType(int objectID, uint8 aiType)
Set the AI type of an object.

Example
setAiType(0, AI_GUARDING);

Comments
The possible values of aiType are AI_NONE, AI_ROAMING, AI_GUARDING, AI_IDLE and AI_GOTO.

See also
getAiType

int getWanderChance(int objectID)
Get an object's wander chance (0 to 100).

Example
print(getWanderChance(0));

See also
setWanderChance

void setWanderChance(int objectID, int wanderChance)
Set an object's wander chance.

Example
setWanderChance(0, 50);

Comments
wanderChance value must be between 0 (never wanders) and 100 (always wanders).

See also
getWanderChance

bool getLocked(int objectID)
Get the locked status of an object.

Example
if (getLocked(0))
{
    print("Object is locked");
}
else
{
    print("Object is unlocked");
}

See also
setLocked

void setLocked(int objectID, bool locked)
Set the locked status of an object.

Example
setLocked(0, true);

See also
getLocked

bool getActive(int objectID)
Get the active status of an object.

Example
if (getActive(0))
{
    print("Object is active");
}
else
{
    print("Object is inactive");
}

See also
getForceActive setForceActive

bool getForceActive(int objectID)
Get the force active status of an object.

Example
if (getForceActive(0))
{
    print("Object is force active");
}
else
{
    print("Object is not force active");
}

See also
setForceActive getActive

void setForceActive(int objectID, bool forceActive)
Set the force active status of an object (server only).

Example
setForceActive(0, true);

Comments
Setting forceActive prevents an object from sleeping when out of view.

See also
getForceActive getActive

bool isEnemyNear(int objectID, float maxDistance=-1)
Determine if any enemies are nearby an object.

Example
if (isEnemyNear(PLAYER_OBJECT))
{
    print("One or more enemies are nearby");
}
else
{
    print("No enemies are nearby");
}

Comments
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.

See also
isEnemyVisible

bool isEnemyVisible(int objectID)
Determine if an object can see any enemies.

Example
if (isEnemyVisible(PLAYER_OBJECT))
{
    print("One or more enemies are visible");
}
else
{
    print("No enemies are visible");
}

Comments
Underwater enemies are not detected.

See also
isEnemyNear

bool isTarget(int objectID)
Determine if an object is currently being targeted by an enemy.

Example
if (isTarget(PLAYER_OBJECT))
{
    print("Player is being targeted");
}
else
{
    print("Player is not being targeted");
}

Comments
Does not detect healing by medics or engineers.
This function can be slow and should be called every frame from onUpdate. Use onTick or check at intervals instead.

See also
getNoTarget setNoTarget

bool getNoTarget(int objectID)
Get the no target status of an object.

Example
if (getNoTarget(PLAYER_OBJECT))
{
    print("Player cannot be targeted");
}
else
{
    print("Player can be targeted");
}

See also
setNoTarget isTarget

void setNoTarget(int objectID, bool noTarget)
Set the no target status of an object.

Example
setNoTarget(PLAYER_OBJECT, true);

Comments
Setting noTarget prevents AI from targetting an object.

See also
getNoTarget isTarget

bool objectExists(int objectID)
Get whether an object exists.

Example
if (objectExists(0))
{
    print("Object 0 exists");
}
else
{
    print("Object 0 doesn't exist");
}

string getTypeName(int objectTypeNumber)
Get an object type name from a object type number.

Example
string typeName = getTypeName(0);
print("Type number 0 is " + typeName);

See also
getTypeNameNumber getTypeNumber

int getTypeNameNumber(string objectTypeName)
Get an object type number from a object type name.

Example
int typeNumber = getTypeNameNumber("hoverboard.ob");
print("Hoverboard is type number " + typeNumber);

See also
getTypeNumber getTypeName

int getTypeNumber(int objectID)
Get an object type number from an object.

Example
int typeNumber = getTypeNumber(PLAYER_OBJECT);
print("Player is type number " + typeNumber);

See also
getTypeNameNumber getTypeName

void setFollow(int objectID, int objectToFollowID)
Set an object to follow another object (server only).

Example
// Make object ID 0 follow object ID 1
setFollow(0, 1);

Comments
Set objectToFollowID to -1 to stop following.

bool isOverWater(int objectID)
Is an object over water?

Example
print(isOverWater(PLAYER_OBJECT));

See also
isSwimming

bool isSwimming(int objectID)
Is an object swimming?

Example
print(isSwimming(PLAYER_OBJECT));

Comments
Only applies to human objects.

See also
isOverWater getSwimmingEnabled setSwimmingEnabled

void getHasWetsuit(bool hasWetsuit)
Determine if the specified unit has a wetsuit.

Example
bool playerHasWetsuit = getHasWetsuit(PLAYER_OBJECT);
print("playerHasWetsuit = " + playerHasWetsuit);

See also
setHasWetsuit

void setHasWetsuit(bool hasWetsuit)
Give or take wetsuit from the specified unit.

Example
// give player wetsuit
setHasWetsuit(PLAYER_OBJECT, true);
print("playerHasWetsuit = " + getHasWetsuit(PLAYER_OBJECT));

Comments
Server only.
Works for any unit or player.

See also
getHasWetsuit

void resetRespawnCoords(int objectID)
Update the respawn coordinates of an object to it's current coordinates (server only).

Example
resetRespawnCoords(0);

string getDisplayName(int objectID)
Get the display name of an object.

Example
string displayName = getDisplayName(PLAYER_OBJECT);
print("Player display name is " + displayName);

See also
getPlayerName

vector2 getTypeSize(string resourceName)
Get the size of an object type in pixels.

Example
// show non-rotated image size and largest rotated bounds size of Car01.ob
vector2 carSize = getTypeSize("Car01.ob");
print("Non-rotated size = " + carSize);
vector2 carMaxRotatedSize = carSize * 1.41;
print("Max rotated size = " + carMaxRotatedSize);

Comments
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.

void attachObject(int objectID, int parentID, vector2 offset)
Attach an object to another object.

Example
// attach object ID 10 to player
attachObject(10, getLocalPlayerObject(), vector2(0,0));

Comments
Attached objects have no physics.
Objects cannot be attached to already attached objects.

See also
detachObject getAttachedObjects getAttachedToParent

void detachObject(int objectID)
Detach an attached object from it's parent.

Example
// detach object ID 10 from it's parent
detachObject(10);

See also
attachObject getAttachedObjects getAttachedToParent

array getAttachedObjects(int parentID)
Get a list of object IDs that are attached to the specified parent object.

Example
// print object IDs attached to player
array<int> objectIDs = getAttachedObjects(getLocalPlayerObject());
for (uint i = 0; i < objectIDs.length(); i++)
{
    print(objectIDs[i]);
}

See also
attachObject detachObject getAttachedToParent

int getAttachedToParent(int objectID)
Get an attached object's parent object ID.

Example
// print parent object ID for object ID 10
int parentObjectID = getAttachedToParent(10);
print(parentObjectID);

Comments
Returns -1 if not attached to a parent object.

See also
attachObject detachObject getAttachedObjects


Index

Generated on the 24 June 2024 at 06:55:37 (UK Time)