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 == getLocalPlayer())
    {
        if(!respawn)
        {
            // first spawn
            print("Welcome to " + getWorldName() + ", " + getDisplayName(PLAYER_OBJECT));
        }
        else
        {
            // respawn
            print("You respawned");
        }
    }
}

Comments
Use setSinglePlayerRespawnEnabled to enable single player respawn.

See also
onStart setSinglePlayerRespawnEnabled getSinglePlayerRespawnEnabled getPlayerObject

void onStarterPack()
Locality:
Server only

Called when the "starterpack" or "sp" console command is run.

Example
void onStarterPack()
{
    print("onStarterPack");
}

Comments
Called on server only.

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, bool silent)
Locality:
Server only

Called when a object or player is killed or deleted.

Example
void onObjectKilled(int objectId, int killerId, bool silent)
{
    if (silent)
    {
        print(getDisplayName(objectId) + " was deleted");
    }
    else
    {
        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 waypointID, int objectID)
{
    print(getDisplayName(objectID) + " reached waypoint " + waypointID);
}

See also
onMoveToComplete

void onMoveToComplete(int objectID)
Locality:
Server only

Called when a object reaches its destination or fails to reach its destination using moveTo.

Example
void onMoveToComplete(int objectID, bool success)
{
    if (success)
    {
        print(getDisplayName(objectID) + " moveTo successful");
    }
    else
    {
        print(getDisplayName(objectID) + " moveTo failed");
    }
}

Comments
Called for objects moved using moveTo only (not related to waypoints).

See also
onWaypointReached

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));
}

Comments
The legacy events OnObjectTypeEnter() and onEnterVehicle_???() fire for players only.

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));
}

Comments
The legacy events OnObjectTypeExit() and OnExitVehicle_???() fire for players only.

See also
onVehicleEnter

void onVehicleSubmerged(int vehicleId)
Locality:
Server and clients

Called when a vehicle becomes submerged.

Example
void onVehicleSubmerged(int vehicleId)
{
    print(getDisplayName(vehicleId) + " has submerged");
}

See also
isSubmerged

void callOnSetCommander(int objectID, int commanderID)
Locality:
Server only

Called when an object's commander is changed.

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

void onInitAmbientSounds()
Locality:
Local only

Called just after local ambient system is initialised.

Comments
Normally found in base\scripts\ambient\sounds.as
Can also be placed in map script as either additional call or to replace entirely if sounds script is disabled in map properties.

See also
onUpdateAmbientSounds

void onUpdateAmbientSounds(float deltaTime, vector2 ambientPos)
Locality:
Local only

Called every frame to update ambient sounds.

Comments
Normally found in base\scripts\ambient\sounds.as
Can also be placed in map script as either additional call or to replace entirely if sounds script is disabled in map properties.

See also
onInitAmbientSounds

void onInitAmbientWildlife()
Locality:
Local only

Called just after local ambient widlife system is initialised.

Comments
Normally found in base\scripts\ambient\wildlife.as
Can also be placed in map script as either additional call or to replace entirely if wildlife script is disabled in map properties.

See also
onTickSpawnAmbientWildlife

void onTickSpawnAmbientWildlife(float tickDelta, vector2 ambientPos)
Locality:
Local only

Called to spawn ambient wildlife via script.

Comments
Normally found in base\scripts\ambient\wildlife.as
Can also be placed in map script as either additional call or to replace entirely if wildlife script is disabled in map properties.

See also
onInitAmbientWildlife

void onInitAmbientPlants()
Locality:
Local only

Called just after local ambient plants system is initialised.

Comments
Normally found in base\scripts\ambient\plants.as (specified in map properties plants script).
Can also be placed in map script as either additional call or to replace entirely if plants script is disabled in map properties.

See also
onTickSpawnAmbientPlants

void onTickSpawnAmbientPlants(float tickDelta, vector2 ambientPos, float plantsDistance, vector2 lastPlantsUpdatedPos, bool plantsFirstGenerated)
Locality:
Local only

Called to spawn ambient plants via script.

Comments
Normally found in base\scripts\ambient\plants.as (specified in map properties plants script).
Can also be placed in map script as either additional call or to replace entirely if plant script is disabled in map properties.

See also
onInitAmbientPlants

void onProjectileSpawn(int gameProjectileID, vector2 pos, float angle)
Locality:
Server and clients

Called after an projectile is spawned.

Example
void onProjectileSpawn(int gameProjectileID, vector2 pos, float angle)
{
    print("spawned game projectile ID " + gameProjectileID);
}

See also
onProjectileHit onProjectileDelete

void onProjectileHit(int gameProjectileID, vector2 pos, float angle, int hitObjectID)
Locality:
Server and clients

Called after an projectile hits something.

Example
void onProjectileHit(int gameProjectileID, vector2 pos, float angle, int hitObjectID)
{
    if(hitObjectID == -1)
        print("Projectile " + gameProjectileID + " hit terrain");
    else
        print("Projectile " + gameProjectileID + " hit object " + hitObjectID);
}

See also
onProjectileSpawn onProjectileDelete

void onProjectileDelete(int gameProjectileID, vector2 pos, float angle)
Locality:
Server and clients

Called just before a projectile is deleted.

Example
void onProjectileDelete(int gameProjectileID, vector2 pos, float angle)
{
    print("Projectile ID " + gameProjectileID + " deleted");
}

See also
onProjectileSpawn onProjectileDelete

string onGetItemName(int objectID, GameItem gameItem)
Locality:
Server and clients (local only)

Called to override name for item shown in inventory.

Example
string onGetItemName(int objectID, GameItem gameItem)
{
    return "Custom name";
}

Comments
Return an empty string to use the item's name.
GameItem has 3 properties:
- itemTypeNumber: The item's type number
- name: The item's name
- magAmmo: The amount of ammo in the mag (or 0 if not a mag)

See also
onGetItemDescription onUseItem onNeedItemCheck

string onGetItemDescription(int objectID, GameItem gameItem)
Locality:
Server and clients (local only)

Called to override description for item shown in inventory.

Example
string onGetItemDescription(int objectID, GameItem gameItem)
{
    return "Custom description";
}

Comments
Return an empty string to use the item's description.
GameItem has 3 properties:
- itemTypeNumber: The item's type number
- name: The item's name
- magAmmo: The amount of ammo in the mag (or 0 if not a mag)

See also
onGetItemName onUseItem onNeedItemCheck

bool onUseItem(int objectID, GameItem gameItem)
Locality:
Server and clients (local only)

Called when an item is used, either by being picked up, or double clicked in inventory (if enabled).

Example
bool onUseItem(int objectID, GameItem gameItem)
{
    // Don't allow any items to be used.
    return false;
}

Comments
Return true if the item has been used, and it will be removed automatically.
GameItem has 3 properties:
- itemTypeNumber: The item's type number
- name: The item's name
- magAmmo: The amount of ammo in the mag (or 0 if not a mag)

See also
onGetItemName onGetItemDescription onNeedItemCheck

bool onNeedItemCheck(int objectID, GameItem gameItem)
Locality:
Server and clients (local only)

Called to determine whether to show the "Take item" action.

Example
bool onNeedItemCheck(int objectID, GameItem gameItem)
{
    // All items are needed.
    return true;
}

Comments
Return true to show the "Take item" action.
This event is not called if there is no space to pick up the item.
GameItem has 3 properties:
- itemTypeNumber: The item's type number
- name: The item's name
- magAmmo: The amount of ammo in the mag (or 0 if not a mag)

See also
onGetItemName onGetItemDescription onUseItem


Index