Meteor 2 Scripting Functions
Network
bool isSinglePlayer()
Is game single player?

Example
if(isSinglePlayer())
{
    print("Game is single player");            
}
else
{
    print("Game is multiplayer");
}

Comments
Same as using !isMultiplayer()

See also
isMultiplayer

bool isMultiplayer()
Is game multiplayer?

Example
if(isMultiplayer())
{
    print("Game is multiplayer");
}
else
{
    print("Game is single player");
}

See also
isSinglePlayer isServer isMultiplayerServer isClient isCoop isHeadToHead

bool isServer()
Is local computer a server or single player?

Example
if(isServer())
{
    print("Local computer is server or single player");
}
else
{
    print("Local computer is a multiplayer client");
}

Comments
Use to determine if the local computer has game authority.

See also
isMultiplayerServer isMultiplayer isClient isCoop isHeadToHead

bool isMultiplayerServer()
Is local computer a multiplayer server?

Example
if(isMultiplayerServer())
{
    print("Local computer is multiplayer server");
}
else
{
    print("Local computer is not a multiplayer server");
}

Comments
Similar to isServer() except returns false in single player.

See also
isMultiplayerServer isMultiplayer isClient isCoop isHeadToHead

bool isClient()
Is local computer network client?

Example
if(isClient())
{
    print("Local computer is a multiplayer client");
}
else
{
    print("Local computer is server or single player");
}

See also
isMultiplayerServer isMultiplayer isServer isCoop isHeadToHead

bool isCoop()
Is game cooperative?

Example
if(isCoop())
{
    print("Play nice");
}
else
{
    print("The gloves are off");
}

See also
isMultiplayer isServer isMultiplayerServer isClient isHeadToHead

bool isHeadToHead()
Is game head to head (aka deathmatch)?

Example
if(isHeadToHead())
{
    print("The gloves are off");            
}
else
{
    print("Play nice");
}

See also
isMultiplayer isServer isMultiplayerServer isClient isCoop

void syncVar(string variableName)
Syncs a variable to all players.

Example
// global variable outside all functions
bool someVar = false;

void onWorldStart()
{
    // if server or single player
    if(isServer())
    {
        someVar = true;
        syncVar("someVar");
    }
}

Comments
The variable must be a global variable, which is defined outside of any functions.
The variable must be a float, int, bool, string or vector2, other types cannot be synced.
Synced variables are synced to players who join mid-game.
Variables can be synced at any time by any player.
In singleplayer, the function has no effect.

See also
netExec

void netExec(int destPlayerID, string codeString)
Execute a string of code on a remote computer.

Example 1
// display message on server only
netExec(NET_EXEC_DEST_SERVER, "print(\"Hello Server!\");");

Example 2
// display message on all computers (includes local computer)
netExec(NET_EXEC_DEST_ALL, "print(\"Hello All!\");");

Example 3
// display message on all computers except local computer
netExec(NET_EXEC_DEST_ALL_REMOTE, "print(\"Hello All!\");");

Example 4
// display message on clients only
netExec(NET_EXEC_DEST_ALL_CLIENTS, "print(\"Hello Clients!\");");

Example 5
// display message on a specific computer
int destPlayerID = getServerPlayer();
netExec(destPlayerID, "print(\"Hello player ID " + destPlayerID + "!\");");

Comments
The netExec function is disabled by default for security reasons, use setNetExecEnabled to enable.
netExec can be used from any computer (server or clients can exec code anywhere else).

See also
getNetExecEnabled setNetExecEnabled

bool getNetExecEnabled()
Get netExec function enabled status.

Example
print("netExec enabled: " + getNetExecEnabled());

Comments
Always returns false in single player.

See also
setNetExecEnabled netExec

void setNetExecEnabled(bool enable)
Enable netExec function on all computers (server only).

Example
void onWorldStart()
{
    if(isMultiplayerServer())
    {
        // enable netExec globally
        setNetExecEnabled(true);
    }
}

Comments
Has no effect in single player.

See also
getNetExecEnabled netExec


Index

Generated on the 23 November 2024 at 08:20:42 (UK Time)