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

Example
// is player a player
int objectID = getLocalPlayerObject();
print(isPlayer(objectID));

Comments
Returns false if objectID was not found.

bool getLocalPlayerObject()
Get local player game object. Same as using PLAYER_OBJECT global variable.

Example
print(getLocalPlayerObject());
// or
print(PLAYER_OBJECT);

Comments
Returns -1 if no local player.
A global read-only variable simply called PLAYER_OBJECT always contains the current local player object ID.

See also
getPlayerObject

bool getPlayerObject(int playerID)
Get a player game object from a playerID.

Example
int playerID = getLocalPlayer();
print(getPlayerObject(playerID));

Comments
Returns -1 if player was not found.

See also
getLocalPlayerObject

void setPlayerObject(int playerID, int objectID)
Set a player object ID (player becomes that object) (local player and server only).

Example
setPlayerObject(getLocalPlayer(), 0);

See also
getPlayer

int getLocalPlayer()
Get the local playerID (not objectID).

Example
print(getLocalPlayer());

Comments
Returns -1 if there is no local player.

See also
getPlayerAtIndex getPlayersCount

int getServerPlayer()
Get the server player's object ID.

Example
print(getServerPlayer());

Comments
In single player this function returns the local player and is identical to calling getLocalPlayer().
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("" + playerID + ": " + getPlayerName(playerID) + " (" + getPlayerObject(playerID) + ")");
}

Comments
Returns -1 if there is no player at that index.
Player lists are ordered 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

string getPlayerName(int playerID)
Get a player's profile name.

Example
print(getPlayerName(getLocalPlayer()));

See also
getDisplayName

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

Example
if(getPlayerState(getLocalPlayer()) == 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.

bool getPlayerInteractionEnabled()
Get local player interaction enabled status.

Example
print(getPlayerInteractionEnabled());

See also
setPlayerInteractionEnabled

void setPlayerInteractionEnabled(bool enabled)
Enable or disable local player interaction/E key (local only)

Example
setPlayerInteractionEnabled(false);

See also
getPlayerInteractionEnabled

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

Example
int playerID = getNearestPlayer(vector2(0,0));
if(playerID != -1)
{
    int playerObjectID = getPlayerObject(playerID);
    print(getPlayerName(playerID) + " " + getPos(playerObjectID));
}
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


Index

Generated on the 24 June 2024 at 06:55:37 (UK Time)