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

Called after the map is loaded.

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

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() + ", " + getUnitDisplayName(getPlayer()));
        }
        else
        {
            // respawn
            print("You respawned");
        }
    }
}

Comments
Use setSinglePlayerRespawnEnabled to enable single player respawn.

See also
setSinglePlayerRespawnEnabled getSinglePlayerRespawnEnabled

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

Called when any unit 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(getUnitDisplayName(objectID) + " entered trigger box " + triggerBoxID + " '" + triggerBoxTag + "'");
}

See also
onTriggerBoxExit createTriggerBox

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

Called when any unit 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(getUnitDisplayName(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 rendered 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(getUnitDisplayName(playerId) + " just connected");
}

See also
onClientDisconnected

void onClientDisconnected(int playerId)
Locality:
Server only

Called when a client connects.

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

See also
onClientConnected

void onUnitSpawn(int objectId)
Locality:
Server and clients

Called after a unit or player spawns.

Example
void onUnitSpawn(int objectID)
{
    print(getUnitDisplayName(objectId) + " spawned");
}

See also
onUnitKilled onUnitDamaged

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

Called when a unit's target has changed.

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

Comments
targetId -1 is no target.

See also
getUnitTarget

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

Called after a unit or player is damaged.

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

See also
onUnitKilled

void onUnitKilled(int objectId, int killerId)
Locality:
Server only

Called when a unit or player is killed.

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

See also
onUnitDamaged

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(getUnitDisplayName(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


Index