Meteor 2 Scripting Functions
Events
void onWorldStart()
Locality:
Server only

Called after the map is loaded on the server.

Example
void onWorldStart()
{
    print("onWorldStart: " + getWorldName());
}

Comments
Called on server only.

See also
onStart onPlayerSpawn

void onStart()
Locality:
Server and clients

Called after the map is loaded on each computer.

Example
void onStart()
{
    print("onStart: " + getWorldName());
}

Comments
Called after onWorldStart() on server and single player. Not called on clients.
In multiplayer this is called before the local player is spawned.

See also
onWorldStart onPlayerSpawn

void onPlayerSpawn(int playerID, bool respawn)
Locality:
Server and clients

Called when any player spawns or respawns.

Example
void onPlayerSpawn(int playerID, bool respawn)
{
    // check if local player
    if(playerID == getPlayer())
    {
        if(!respawn)
        {
            // first spawn
            print("Welcome to " + getWorldName() + ", " + getDisplayName(getPlayer()));
        }
        else
        {
            // respawn
            print("You respawned");
        }
    }
}

Comments
Use setSinglePlayerRespawnEnabled to enable single player respawn.

See also
onStart setSinglePlayerRespawnEnabled getSinglePlayerRespawnEnabled getPlayerObject

void onTriggerBoxEnter(int triggerBoxID, string triggerBoxTag, int objectID)
Locality:
Server and clients

Called when any object or player enters a trigger box.

Example
// Display information every time any player or unit enters any trigger box
void onTriggerBoxEnter(int triggerBoxID, string triggerBoxTag, int objectID)
{
    print(getDisplayName(objectID) + " entered trigger box " + triggerBoxID + " '" + triggerBoxTag + "'");
}

See also
onTriggerBoxExit createTriggerBox

void onTriggerBoxExit(int triggerBoxID, string triggerBoxTag, int objectID)
Locality:
Server and clients

Called when any object or player exits a trigger box.

Example
// Display information every time any player or unit exits any trigger box
void onTriggerBoxExit(int triggerBoxID, string triggerBoxTag, int objectID)
{
    print(getDisplayName(objectID) + " left trigger box " + triggerBoxID + " '" + triggerBoxTag + "'");
}

See also
onTriggerBoxEnter createTriggerBox

void onTick(float tickDelta)
Locality:
Server and clients (local only)

Called on each tick (normally 30 times per second).

Example
void onTick(float tickDelta)
{
    // your code here
}

See also
onUpdate

void onUpdate(float deltaTime)
Locality:
Server and clients

Called every frame.

Example
void onUpdate(float tickDelta)
{
    // your code here
}

See also
onTick

void onClientConnected(int playerId)
Locality:
Server only

Called when a client connects.

Example
void onClientConnected(int playerId)
{
    print(getDisplayName(playerId) + " just connected");
}

See also
onClientDisconnected

void onClientDisconnected(int playerId)
Locality:
Server only

Called when a client connects.

Example
void onClientDisconnected(int playerId)
{
    print(getDisplayName(playerId) + " has disconnected");
}

See also
onClientConnected

void onObjectSpawn(int objectId)
Locality:
Server and clients

Called after an object or player spawns.

Example
void onObjectSpawn(int objectId)
{
    print(getDisplayName(objectId) + " spawned");
}

See also
onObjectRespawn onObjectKilled onObjectDamaged

void onObjectRespawn(int oldObjectId, int newObjectId)
Locality:
Server

Called after an object is respawned.

Example
void onObjectRespawn(int oldObjectId, int newObjectId)
{
    print(getDisplayName(oldObjectId) + " respawned, new id is " + newObjectId);
}

See also
onObjectSpawn onObjectKilled onObjectDamaged

void onObjectTargetChanged(int objectId, int targetId)
Locality:
Server only

Called when a object's target has changed.

Example
void onObjectTargetChanged(int objectId, int targetId)
{
    if(targetId != -1)
        print(getDisplayName(objectId) + "(" + objectId + ")" + " target changed to " + getDisplayName(targetId) + " (" + targetId + ")");
    else
        print(getDisplayName(objectId) + "(" + objectId + ") target cancelled");
}

Comments
targetId -1 is no target.

See also
getTarget

void onObjectDamaged(int objectId, int ownerId, int oldHits, int newHits)
Locality:
Server only

Called after an object or player is damaged.

Example
void onObjectDamaged(int objectId, int ownerId, int oldHits, int newHits)
{
    print(getDisplayName(objectID) + " was damaged by " + getDisplayName(ownerId) + " and now has " + newHits + " health");
}

See also
onObjectKilled

void onObjectKilled(int objectId, int killerId)
Locality:
Server and clients

Called when a object or player is killed.

Example
void onObjectKilled(int objectId, int killerId)
{
    print(getDisplayName(objectId) + " was killed by " + getDisplayName(killerId));
}

See also
onObjectDamaged

void onWaypointReached(int waypointId, int objectId)
Locality:
Server only

Called when a object reaches a waypoint.

Example
void onWaypointReached(int objectId, int waypointId)
{
    print(getDisplayName(objectId) + " reached waypoint " + waypointId);
}

void onVehicleEnter(int vehicleId, int objectId)
Locality:
Server only

Called when a unit enters a vehicle.

Example
void onVehicleEnter(int vehicleId, int objectId)
{
    print(getDisplayName(objectId) + " got in vehicle " + getDisplayName(vehicleId));
}

See also
onVehicleExit

void onVehicleExit(int vehicleId, int objectId)
Locality:
Server only

Called when a unit exits a vehicle.

Example
void onVehicleExit(int vehicleId, int objectId)
{
    print(getDisplayName(objectId) + " got out of vehicle " + getDisplayName(vehicleId));
}

See also
onVehicleEnter

void onPickupItem(int playerID, string itemName, int itemAmount, string powerupName)
Locality:
Server only

Called when any player picks up an item.

Example
void onPickupItem(int playerID, string itemName, int itemAmount, string powerupName)
{
    print(getDisplayName(playerID) + " picked up " + itemAmount + "x " + itemName + " from the " + powerupName);
}

void onGameSave()
Locality:
Single player only

Called while the game is being saved.

Example
// global vars that are set once (no need to save)
vector2 triggerPos = vector2(100, 100);

// global vars that change in code (must be saved)
int someInt;
vector2 someVec1;

void onGameSave()
{
    // save variables to saved game file
    saveGameVar("someInt", someInt);
    saveGameVar("someVec1", someVec1);
}

Comments
Use onGameSave to save global script variables.

See also
onGameLoad saveGameVar

void onGameLoad()
Locality:
Single player only

Called while the game is being loaded.

Example
// global vars that are set once (no need to save)
vector2 triggerPos = vector2(100, 100);

// global vars that change in code (must be saved)
int someInt;
vector2 someVec1;

void onGameLoad()
{
    // load variables from saved game file
    someInt = loadGameVar("someInt", 0);
    someVec1 = loadGameVar("someVec1", vector2(0,0));
}

See also
onGameSave loadGameVar

void onInitHud()
Locality:
Local only

Called when the HUD is initialised (also when player changes vehicle).

Example
int hudArrowSprite = 0;

void onInitHud()
{
    // resolve hudArrowSprite once (not every frame)
    hudArrowSprite = getSpriteNumber("objects\\arrow.spr");
}

See also
onBeforeDrawHud onAfterDrawHud

void onBeforeDrawHud(float deltaTime)
Locality:
Local only

Called just before the HUD is drawn.

Example
void onBeforeDrawHud(float deltaTime)
{
    drawText(vector2(100,100), "onBeforeDrawHud", "#FFFFFF", true, FONT_STANDARD, 20);
}

See also
onAfterDrawHud

void onAfterDrawHud(float deltaTime)
Locality:
Local only

Called just after the HUD is drawn.

Example
void onAfterDrawHud(float deltaTime)
{
    drawText(vector2(100,150), "onAfterDrawHud", "#00FF00", true, FONT_STANDARD, 20);
}

See also
onBeforeDrawHud


Index

Generated on the 23 November 2024 at 08:20:45 (UK Time)