Meteor 2 Scripting Functions
Events
void onWorldStart()
Server only
Called after the map is loaded on the server.
void onWorldStart()
{
print("onWorldStart: " + getWorldName());
}
Called on server only.
void onStart()
Server and clients
Called after the map is loaded on each computer.
void onStart()
{
print("onStart: " + getWorldName());
}
Called after onWorldStart() on server and single player. Not called on clients.
In multiplayer this is called before the local player is spawned.
void onPlayerSpawn(int playerID, bool respawn)
Server and clients
Called when any player spawns or respawns.
void onPlayerSpawn(int playerID, bool respawn)
{
if(playerID == getPlayer())
{
if(!respawn)
{
print("Welcome to " + getWorldName() + ", " + getDisplayName(getPlayer()));
}
else
{
print("You respawned");
}
}
}
Use setSinglePlayerRespawnEnabled to enable single player respawn.
void onTriggerBoxEnter(int triggerBoxID, string triggerBoxTag, int objectID)
Server and clients
Called when any object or player enters a trigger box.
void onTriggerBoxEnter(int triggerBoxID, string triggerBoxTag, int objectID)
{
print(getDisplayName(objectID) + " entered trigger box " + triggerBoxID + " '" + triggerBoxTag + "'");
}
void onTriggerBoxExit(int triggerBoxID, string triggerBoxTag, int objectID)
Server and clients
Called when any object or player exits a trigger box.
void onTriggerBoxExit(int triggerBoxID, string triggerBoxTag, int objectID)
{
print(getDisplayName(objectID) + " left trigger box " + triggerBoxID + " '" + triggerBoxTag + "'");
}
void onTick(float tickDelta)
Server and clients (local only)
Called on each tick (normally 30 times per second).
void onTick(float tickDelta)
{
}
void onUpdate(float deltaTime)
Server and clients
Called every frame.
void onUpdate(float tickDelta)
{
}
void onClientConnected(int playerId)
Server only
Called when a client connects.
void onClientConnected(int playerId)
{
print(getDisplayName(playerId) + " just connected");
}
void onClientDisconnected(int playerId)
Server only
Called when a client connects.
void onClientDisconnected(int playerId)
{
print(getDisplayName(playerId) + " has disconnected");
}
void onObjectSpawn(int objectId)
Server and clients
Called after an object or player spawns.
void onObjectSpawn(int objectId)
{
print(getDisplayName(objectId) + " spawned");
}
void onObjectRespawn(int oldObjectId, int newObjectId)
Server
Called after an object is respawned.
void onObjectRespawn(int oldObjectId, int newObjectId)
{
print(getDisplayName(oldObjectId) + " respawned, new id is " + newObjectId);
}
void onObjectTargetChanged(int objectId, int targetId)
Server only
Called when a object's target has changed.
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");
}
targetId -1 is no target.
void onObjectDamaged(int objectId, int ownerId, int oldHits, int newHits)
Server only
Called after an object or player is damaged.
void onObjectDamaged(int objectId, int ownerId, int oldHits, int newHits)
{
print(getDisplayName(objectID) + " was damaged by " + getDisplayName(ownerId) + " and now has " + newHits + " health");
}
void onObjectKilled(int objectId, int killerId)
Server and clients
Called when a object or player is killed.
void onObjectKilled(int objectId, int killerId)
{
print(getDisplayName(objectId) + " was killed by " + getDisplayName(killerId));
}
void onWaypointReached(int waypointId, int objectId)
Server only
Called when a object reaches a waypoint.
void onWaypointReached(int objectId, int waypointId)
{
print(getDisplayName(objectId) + " reached waypoint " + waypointId);
}
void onVehicleEnter(int vehicleId, int objectId)
Server only
Called when a unit enters a vehicle.
void onVehicleEnter(int vehicleId, int objectId)
{
print(getDisplayName(objectId) + " got in vehicle " + getDisplayName(vehicleId));
}
void onVehicleExit(int vehicleId, int objectId)
Server only
Called when a unit exits a vehicle.
void onVehicleExit(int vehicleId, int objectId)
{
print(getDisplayName(objectId) + " got out of vehicle " + getDisplayName(vehicleId));
}
void onPickupItem(int playerID, string itemName, int itemAmount, string powerupName)
Server only
Called when any player picks up an item.
void onPickupItem(int playerID, string itemName, int itemAmount, string powerupName)
{
print(getDisplayName(playerID) + " picked up " + itemAmount + "x " + itemName + " from the " + powerupName);
}
void onGameSave()
Single player only
Called while the game is being saved.
vector2 triggerPos = vector2(100, 100);
int someInt;
vector2 someVec1;
void onGameSave()
{
saveGameVar("someInt", someInt);
saveGameVar("someVec1", someVec1);
}
Use onGameSave to save global script variables.
void onGameLoad()
Single player only
Called while the game is being loaded.
vector2 triggerPos = vector2(100, 100);
int someInt;
vector2 someVec1;
void onGameLoad()
{
someInt = loadGameVar("someInt", 0);
someVec1 = loadGameVar("someVec1", vector2(0,0));
}
void onInitHud()
Local only
Called when the HUD is initialised (also when player changes vehicle).
int hudArrowSprite = 0;
void onInitHud()
{
hudArrowSprite = getSpriteNumber("objects\\arrow.spr");
}
void onBeforeDrawHud(float deltaTime)
Local only
Called just before the HUD is drawn.
void onBeforeDrawHud(float deltaTime)
{
drawText(vector2(100,100), "onBeforeDrawHud", "#FFFFFF", true, FONT_STANDARD, 20);
}
void onAfterDrawHud(float deltaTime)
Local only
Called just after the HUD is drawn.
void onAfterDrawHud(float deltaTime)
{
drawText(vector2(100,150), "onAfterDrawHud", "#00FF00", true, FONT_STANDARD, 20);
}
void onInitAmbientWildlife()
Local only
Called just after local ambient widlife system is initialised.
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.
void onTickSpawnAmbientWildlife(float tickDelta, vector2 ambientPos)
Local only
Called to spawn ambient wildlife via script.
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.
void onInitAmbientPlants()
Local only
Called just after local ambient plants system is initialised.
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.
void onTickSpawnAmbientPlants(float tickDelta, vector2 ambientPos, float plantsDistance, vector2 lastPlantsUpdatedPos, bool plantsFirstGenerated)
Local only
Called to spawn ambient plants via script.
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.
Index