Skip to content
Sundays211 edited this page Jun 23, 2017 · 3 revisions

There are a handful of core modules you can require in your module to perform useful functions. Doing so is preferable to interacting directly with the game engine.

Variables (engine/var/...)

To get or set a variable (player, client, bit), you should require one of these modules in your script. For example:

var varp = requre('engine/var/player');

var example = varp(player, 100);//Get a variable value
varp(player, 100, example+1);//Set a variable value

Animations (anim)

To run or stop animations, or to add/clear spotanims, you should use this module:

var anim = require('anim`);

anim.run(player, 200, function () {
//Play animation 200 on "player" and run this function after it's finished
});

anim.stop(player);//Stop any animation currently running on the player

Config (engine/config)

To get configuration information (object names, descriptions, stackability, etc), include this module:

var config = require('engine/config');

var objName = config.objName(200);//Gets the object name for object with id=200
var enumValue = config.enumValue(392, 1);//Gets the value at slot 1 of enum 392

Constants (const)

Contains useful constants for use in scripts (eg max integer value)

var CONST = require('const');

amount = Math.min(amount, CONST.INTEGER_MAX);

Dialog (dialog)

Contains dialog-related functions, such as requesting a number from the player or showing NPC/Player chat:

var dialog = require('dialog');

dialog.chatnpc(300, "Some text", function () {
  //Show the chatbox for npc 300 then run this function
});

NOTE: This module is scheduled for major changes to make nested functions for multiple chat lines unnecessary

Chat (chat)

Chat-related functions. At this stage, mainly for sending messages to the player:

var chat = require('chat');

chat.sendMessage(player, "A message!");
chat.sendSpamMessage(player, "A message which will be hidden if the player has the 'game' chat filter on");

Inventory (inv)

Functions for managing inventories, including checking if a player has room for an item, giving an item to a player, taking an item from a player, etc:

var inv = require('inv');

if (inv.has(player, 200)) {
  //Deposit item 200 in the player's bank
  inv.take(player, 200, 1, Inv.BACKPACK);
  inv.give(player, 200, 1, Inv.BANK);
}

Interface/Widget (widget)

Displaying, closing, and managing interfaces/widgets:

var widget = require('widget');

widget.openCentral(player, 1022);//Opens interface 1022 in the central frame
widget.setText(player, 1022, 20, "Test text");//Sets the text of component 20 to "Test text"
widget.hide(player, 1022, 22, true);//Hides component 22 of widget 1022

Utility functions (util)

Utility functions which don't fit into any other category. Includes the delay function, random number generators, formatters, etc:

var util = require('util`);

var rand = util.randomValue(1, 11);//Picks a random value between 1 and 10 inclusive

util.defaultHandler(ctx, "test module");//Prints debug messages for when the event handler cannot handle the given event