Meteor Scripting Functions
Player
bool isPlayer(int objectID)
Determine if an objectID is a player.

Example
// is player a player
int playerID = getPlayer();
print(isPlayer(playerID));

Comments
Returns false if objectID was not found.

int getPlayer()
Get the local player ID.

Example
print("Your name is " + getUnitDisplayName(getPlayer()));

Comments
Returns -1 if there is no player.

See also
getServerPlayer getPlayerAtIndex getPlayersCount

int getServerPlayer()
Get the server player ID.

Example
print("Your name is " + getUnitDisplayName(getPlayer()));

Comments
In single player this function returns the local player and is identical to calling getPlayer().
Returns -1 if there is no player.

See also
getPlayer getPlayerAtIndex getPlayersCount

int getPlayerAtIndex(int localIndex)
Get the player ID of another player by index.

Example
// list players
for(int i=0; i<getPlayersCount(); i++)
{
    int playerID = getPlayerAtIndex(i);
    print("" + i + ": " + getUnitDisplayName(playerID) + " (" + playerID + ")");
}

Comments
Returns -1 if there is no player at that index.
Player lists are stored differently on each player's computer.
Player IDs are network synced.

See also
getPlayer getPlayersCount

int getPlayersCount()
Get the number of players in the game.

Example
print("Players count: " + getPlayersCount());

See also
getPlayer getPlayerAtIndex

int getPlayerState(int playerID)
Get a player's current state.

Example
if(getPlayerState(getPlayer()) == STATE_PLAYING)
{
    print("Your state is STATE_PLAYING");
}

Comments
Possible return values are STATE_PLAYING, STATE_WASTED, STATE_WAITING_TO_SPAWN and STATE_VIEWING.
If no player was found then STATE_WAITING_TO_SPAWN is returned.

int getNearestPlayer(vector2 pos)
Get the nearest spawned player to a position.

Example
int playerID = getNearestPlayer(vector2(0,0));
if(playerID != -1)
    print(getUnitDisplayName(playerID));
else
    print("No players");

Comments
If no active player was found -1 is returned.

See also
getNearestPlayerDistance

float getNearestPlayerDistance(vector2 pos, float defaultValue=-1)
Get the distance to the nearest spawned player from a position.

Example
print(getNearestPlayerDistance(vector2(0,0)));

Comments
defaultValue is the return value if no active players were found. If no defaultValue is specified then -1 is used.

See also
getNearestPlayer

vector2 getPlayerLastKilledPos(int objectID)
Get a player's last killed position.

Example
print("Last killed pos: " + getPlayerLastKilledPos(getPlayer()));

int getPlayerWeapon(int objectID)
Get the specified player weapon slot index.

Example
// show player current weapon slot index
print(getPlayerWeapon(getPlayer()));

Comments
If the player was not found 0 is returned.

See also
setPlayerWeapon clampPlayerWeapon playerHasWeapon getPlayerWeaponSlotItemNumber getPlayerWeaponSlotItemName getPlayerWeaponSlotsCount

void setPlayerWeapon(int objectID, int slotIndex)
Set the specified player weapon slot index (local player or server only).

Example
// select weapon slot 1 (Shotgun)
setPlayerWeapon(getPlayer(), 1);

See also
getPlayerWeapon clampPlayerWeapon playerHasWeapon getPlayerWeaponSlotItemNumber getPlayerWeaponSlotItemName getPlayerWeaponSlotsCount

void clampPlayerWeapon(int objectID)
Clamp the player weapon index to a valid/owned weapon slot (local player or server only).

Example
// take away Uzi
giveItem(getPlayer(), "Uzi", -1);

// ensure player's current weapon is valid
clampPlayerWeapon(getPlayer());

Comments
Use this function to ensure the player's current weapon is valid after removing player weapons.

See also
getPlayerWeapon setPlayerWeapon playerHasWeapon getPlayerWeaponSlotItemNumber getPlayerWeaponSlotItemName getPlayerWeaponSlotsCount

bool playerHasWeapon(int objectID, weaponItemName string)
Determine if a player has a weapon.

Example
// does player have an Uzi?
print("Player has Uzi: " + playerHasWeapon(getPlayer(), "Uzi"));

Comments
No playerID is required because the slots count is the same for all players.

See also
getPlayerWeapon setPlayerWeapon clampPlayerWeapon getPlayerWeaponSlotItemNumber getPlayerWeaponSlotItemName getPlayerWeaponSlotsCount

int getPlayerWeaponSlotItemNumber(int slotIndex)
Get the item type index for a player weapon slot.

Example
// print slot 0 (Pistol) item number
print(getPlayerWeaponSlotItemNumber(0));

Comments
No playerID is required because the slot item types are the same for all players.
Returns -1 if the slot is invalid.

See also
getPlayerWeapon setPlayerWeapon clampPlayerWeapon playerHasWeapon getPlayerWeaponSlotItemName getPlayerWeaponSlotsCount

string getPlayerWeaponSlotItemName(int slotIndex)
Get the item type name for a player weapon slot.

Example
// print weapon item name for slot 0 (Pistol)
print(getPlayerWeaponSlotItemName(0));

Comments
No playerID is required because the slot item names are the same for all players.
Returns empty string if the slot is invalid.

See also
getPlayerWeapon setPlayerWeapon clampPlayerWeapon playerHasWeapon getPlayerWeaponSlotItemNumber getPlayerWeaponSlotsCount

int getPlayerWeaponSlotsCount()
Get the number of player weapon slots.

Example 1
// show number of player weapon slots
print("Player has " + getPlayerWeaponSlotsCount() + " weapon slots");

Example 2
// loop through weapon slots and display information
for(int i=0; i<getPlayerWeaponSlotsCount(); i++)
{
    print(i + ": " + getPlayerWeaponSlotItemName(i));
}

Comments
No playerID is required because the slots count is the same for all players.

See also
getPlayerWeapon setPlayerWeapon clampPlayerWeapon playerHasWeapon getPlayerWeaponSlotItemNumber getPlayerWeaponSlotItemName

bool getPlayerNoTarget(int objectID)
Get whether enemies can target a player.

Example
print("Player no target: " + getPlayerNoTarget(getPlayer()));

See also
setPlayerNoTarget

void setPlayerNoTarget(int objectID, bool noTargetEnabled)
Set whether enemies can target a player. (server only)

Example
// prevents player from taking damage and being targetted by enemies
setPlayerNoTarget(getPlayer(), true);

Comments
No target also prevents the player from taking any damage, similar to god mode.

See also
getPlayerNoTarget


Index