Meteor 2 Scripting Functions
UI
vector2 getScreenSize()
Get the screen size in pixels

Example
// Example 1:
print("Screen size is " + getScreenSize().x + " by " + getScreenSize().y);

// Example 2 (see comments):
print("Screen size is " + SCREEN_W + " by " + SCREEN_H);

Comments
Two static float variables SCREEN_W and SCREEN_H are also available.

void screenToWorld(vector2 screenPos)
Convert screen pixel coordinates to a world position.

Example
// print world position at middle of screen
print(screenToWorld(vector2(SCREEN_W * 0.5, SCREEN_H * 0.5)));

Comments
Result may be outside of world/map bounds.

See also
worldToScreen getScreenSize getWorldRenderScale

void worldToScreen(vector2 screenPos)
Convert a world position to screen pixel coordinates.

Example
// print screen position of player
print(worldToScreen(getPos(PLAYER_OBJECT)));

Comments
Result may be outside of screen bounds.

See also
screenToWorld getScreenSize getWorldRenderScale

vector2 getWorldWindowStart()
Get the world window start position (world position under top-left pixel).

Example
// print top left of window world position
print(getWorldWindowStart());

See also
getWorldWindowSize posInWorldWindow

vector2 getWorldWindowSize()
Get the world window size in world pixels (not metres or screen pixels).

Example
// print window world size
print(getWorldWindowSize());

See also
getWorldWindowStart posInWorldWindow

bool posInWorldWindow()
Determine is a world position (in world pixels) is within the world window.

Example
// print whether object ID 1 is currenly on the screen
print(posInWorldWindow(1));

See also
getWorldWindowStart getWorldWindowSize

float getWorldRenderScale()
Get the current world render scale (zoom level).

Example
// print screen position of player
print(getWorldRenderScale());

See also
screenToWorld getScreenSize

string colToHTML(uint8 r, uint8 g, uint8 b, uint8 a)
Convert a unsigned byte colour in the format RGBA to HTML style string.

Example
// #ffffffff (white)
print(colToHTML(255,255,255,255));

// #ffffffc0 (transparent white)
print(colToHTML(255,255,255,128));

// #ff0000ff (red)
print(colToHTML(255,0,0,255));

// #00ff00ff (green)
print(colToHTML(0,255,0,128));

// #0000ffff (blue)
print(colToHTML(0,0,255,255));

See also
htmlToColR htmlToColG htmlToColB htmlToColA

uint8 htmlToColR(string html)
Get the red value from HTML style colour string (0-255).

Example
// 255
print(htmlToColR("FF80C0"));

See also
htmlToColG htmlToColB htmlToColA colToHTML

uint8 htmlToColG(string html)
Get the green value from HTML style colour string (0-255).

Example
// 128
print(htmlToColG("FF80C0"));

See also
htmlToColR htmlToColB htmlToColA colToHTML

uint8 htmlToColB(string html)
Get the blue value from HTML style colour string (0-255).

Example
// 192
print(htmlToColB("FF80C0"));

See also
htmlToColR htmlToColG htmlToColA colToHTML

uint8 htmlToColA(string html)
Get the alpha value from HTML style colour string (0-255).

Example
// 224
print(htmlToColA("FF80C0E0"));

See also
htmlToColR htmlToColG htmlToColB colToHTML

void gameMessage(string text, int destPlayerID=NET_EXEC_DEST_LOCAL)
Display a game message either locally (default) or on other computers.

Example 1
// local game message
gameMessage("This is a local game message");

Example 2
// also local game message
gameMessage("This is a local game message", NET_EXEC_DEST_LOCAL);

Example 3
// game message on server only
gameMessage("Hello server", NET_EXEC_DEST_SERVER);

Example 4
// game message everywhere
gameMessage("Hello all", NET_EXEC_DEST_ALL);

Example 5
// game message everywhere except this computer
gameMessage("Hello everyone else", NET_EXEC_DEST_ALL_REMOTE);

Example 6
// game message on all clients but not on server
gameMessage("Hello all clients", NET_EXEC_DEST_ALL_CLIENTS);

Example 7
// game message on computer that initiated this script code
gameMessage("Hello calling player", getScriptPlayerID());

Example 8
// game message on computer with player ID of 2
gameMessage("Hello specific player", 2);

See also
gameMessageObject gameMessageNear introMessage messageBox print logPrint getScriptPlayerID

void gameMessageObject(string text, int objectID)
Display a game message to the player with the specified object ID.

Example 1
// game message to local player
gameMessageObject("Hello me", PLAYER_OBJECT);

Example 2
// game message to player who is object 10
gameMessageObject("Hello object ID 10", 10);

Comments
Useful function to show a message to a player by object ID instead of player ID.
If the object is a vehicle containing multiple players then all players in the vehicle will get the message.

See also
gameMessage gameMessageNear

void gameMessageNear(string text, int objectID, float radius=500.0)
Display a game message to players near the specified object ID.

Example 1
// game message to players near local player
gameMessageNear("Hello nearby people!", PLAYER_OBJECT);

Example 2
// game message to players near object 10
gameMessageNear("Hello players near object 10", 10);

Example 3
// game message to players within 1000 pixels of object 10
gameMessageNear("Hello players within 1000 pixels of object 10", 10, 1000);

Comments
radius is in pixels and defaults to 500 pixels if not specified.

See also
gameMessage gameMessageObject

void gameMessageNear(string text, vector2 pos, float radius=500.0)
Display a game message to players near the specified position.

Example
// game message to players near sector 2
gameMessageNear("Hello players near sector 2!", getSectorPos(2));

Comments
radius is in pixels and defaults to 500 pixels if not specified.

See also
gameMessage gameMessageObject

void introMessage(string text)
Display an intro message (local only).

Example
introMessage("This is a intro message");

Comments
Intro messages are displayed near the bottom of the screen and fade out after around 8 seconds.

See also
gameMessage messageBox print logPrint

void messageBox(string text)
Display a message box (local only).

Example
messageBox("This is a message box");

Comments
none

See also
gameMessage confirmBox

bool confirmBox(string text)
Display a confirmation box with message (local only).

Example
if(confirmBox("Are you sure?"))
{
    print("You are sure");
}

Comments
none

See also
messageBox stringInputBox

bool stringInputBox(string str, int maxLen, string message)
Display a string input box with message (local only).

Example
string name = "";
if(stringInputBox(name, 32, "Enter your name"))
{
    print("Your name is " + name);
}

Comments
none

See also
messageBox

bool createToolbar(int toolbarNumber, string title, vector2 screenPos, bool docked)
Create a toolbar (local only).

Example
createToolbar(0, "Test Toolbar", vector2(10, 10), false);

Comments
toolbarNumber should simply be unique number that refers to this toolbar.
docked toolbars cannot be moved.
See base\maps\examples\Text_Toolbar.as for a working example.

See also
deleteToolbar addToolbarButton

void deleteToolbar(int toolbarNumber, bool localOnly)
Delete a toolbar and all associated buttons (local only).

Example
deleteToolbar(0);

See also
createToolbar addToolbarButton

void addToolbarButton(int toolbarNumber, string caption, string imageFilename, string triggerText)
Add a button to an existing toolbar (local only).

Example
addToolbarButton(0, "Sheep", "objects\\sheep01_01.png", "print(\"You pressed the sheep button\");");

Comments
toolbarNumber is the unique toolbar number to add the button to.
imageFilename must be image filename from within an INI file from the images folder.

See also
addToolbarSeparator createToolbar

void addToolbarSeparator(int toolbarNumber)
Add a separator to an existing toolbar (local only).

Example
addToolbarSeparator(0);

See also
addToolbarButton createToolbar

int addMenu(string name)
Add an interaction menu.

Example
int menuId = addMenu("Test Menu");

See also
removeMenu addMenuItem openInteractionMenu

void removeMenu(int menuId)
Remove an interaction menu.

Example
int menuId = addMenu("Test Menu");
removeMenu(menuId);

See also
addMenu addMenuItem openInteractionMenu

int addMenuItem(int menuId, string name, string code, bool autoClose=true)
Add an interaction menu item.

Example
int menuId = addMenu("Test Menu");
int menuItemId = addMenuItem(menuId, "Test Item", "print(\"Hello!\");");

// Use 0 to add to the root menu.
int rootMenuItemId = addMenuItem(0, "Test Menu >", "openInteractionMenu(" + menuId + ");", false);

Comments
Use a menu id of 0 to add to the root menu.
Returns -1 if the menu item could not be added.
Interaction menu items are best suited for general tasks and actions. For object specific actions use addAction() instead.

See also
removeMenuItem addMenu addAction

void removeMenuItem(int menuId, int menuItemId)
Remove an interaction menu item.

Example
int menuId = addMenu("Test Menu");
int menuItemId = addMenuItem(menuId, "Test Item", "print(\"Hello!\");");

removeMenuItem(menuId, menuItemId);

See also
addMenuItem addMenu

Determine if an interaction menu item exists.

See also
addMenuItem removeMenuItem getMenuItemHidden setMenuItemHidden

bool getMenuItemHidden(int menuId, int menuItemId)
Get if an interaction menu item is hidden.

Example
int menuId = addMenu("Test Menu");
int menuItemId = addMenuItem(menuId, "Test Item", "print(\"Hello!\");");

if (getMenuItemHidden(menuId, menuItemId))
{
    print("Item is hidden");
}
else
{
    print("Item is not hidden");
}

See also
setMenuItemHidden addMenuItem

void setMenuItemHidden(int menuId, int menuItemId, bool hidden)
Set if an interaction menu item is hidden.

Example
int menuId = addMenu("Test Menu");
int menuItemId = addMenuItem(menuId, "Test Item", "print(\"Hello!\");");
setMenuItemHidden(menuId, menuItemId, true);

See also
getMenuItemHidden addMenuItem

void openInteractionMenu(int menuId)
Open specified interaction menu.

Example
// open root interaction menu
openInteractionMenu(0);

// open custom menu
int menuId = addMenu("Test Menu");
openInteractionMenu(menuId);

// close interaction menu
openInteractionMenu(-1);

Comments
Use -1 to close the interaction menu.

See also
showInteractionMenu getInteractionMenuOpen addMenu

void showInteractionMenu(string name, array items)
Show an interaction menu from an array of items.

Example
array<InteractionMenuItem> menuData;
menuData.insertLast({ "Root >", "openInteractionMenu(0);", false });
menuData.insertLast({ "Item 1", "print(\"Item 1\");" });
menuData.insertLast({ "Item 2", "print(\"Item 2\");" });
showInteractionMenu("Test Menu", menuData);

See also
openInteractionMenu getInteractionMenuOpen

bool getInteractionMenuOpen()
Determine if any interaction menu is currently open.

See also
openInteractionMenu showInteractionMenu addMenu

bool getMissileAlarmEnabled()
Determine if the "Missile alarm" option is enabled in the local options.


Index