Global

Methods

accept_party_invite(name)

Accept party invite from player
Parameters:
Name Type Description
name string
Source:

accept_party_request(name)

Accept party request from player.
Parameters:
Name Type Description
name string
Source:

activate(num)

Activates an item, likely a booster, in the num-th inventory slot
Parameters:
Name Type Description
num number number of Inventory slot
Source:

add_bottom_button(id, valueopt, fnopt)

Adds a button to the bottom bar.
Parameters:
Name Type Attributes Description
id string the id of the new button
value string <optional>
the text to display
fn function <optional>
the function to run when clicked
Source:

add_top_button(id, valueopt, fnopt)

Adds a button to the top bar.
Parameters:
Name Type Attributes Description
id string the id of the new button
value string <optional>
the text to display
fn function <optional>
the function to run when clicked
Source:

attack(target)

Tries to attack the target
Parameters:
Name Type Description
target Player | Monster Target to attack
Source:

auto_reload(value)

Configures the game to auto reload in case you disconnect due to rare network issues. (FIXME: Document differences of "on" and "auto")
Parameters:
Name Type Description
value string valid values are "on", "off", and "auto"
Source:

bank_deposit(gold)

Deposits gold into the bank.
Parameters:
Name Type Description
gold number The amount of gold to deposit.
Source:

bank_store(num, packopt, pack_slotopt)

Stores/swaps an item in the bank.
Parameters:
Name Type Attributes Default Description
num number The inventory slot to store/swap (-1 to store to first slot available).
pack string <optional>
The bank to use, valid values are one of ["items0","items1","items2","items3","items4","items5","items6","items7"].
pack_slot number <optional>
-1 The slot in the bank to use (-1 to store to first available).
Source:
Example
bank_store(0); // Stores the first item in inventory in the first/best spot in bank.
bank_store(-1, "items0", 0); // Withdraws the first item in the first bank to the first available inventory slot.

bank_withdraw(gold)

Withdraws gold from the bank.
Parameters:
Name Type Description
gold number The amount of gold to withdraw.
Source:

buy(name, quantity)

Buys items from NPC. The NPC has to be near enough to be able to buy from him. Usually 400px
Parameters:
Name Type Description
name String Name of the Item
quantity number Quantity
Source:

buy_with_gold(name, quantity)

Same as buy, but will only ever use gold.
Parameters:
Name Type Description
name String Name of the Item
quantity number Quantity
Source:

buy_with_shells(name, quantity)

Same as buy, but will only ever use shells.
Parameters:
Name Type Description
name String Name of the Item
quantity number Quantity
Source:

can_attack(target) → {boolean}

Checks if the character is able to attack the target
Parameters:
Name Type Description
target Monster | Player the Entity for which to check
Source:
Returns:
True if the target can be healed
Type
boolean

can_heal(target) → {boolean}

Checks if the character is able to heal the target Same as can_attack but with a more intuitive name
Parameters:
Name Type Description
target Monster | Player the Entity for which to check
Source:
Returns:
True if the target can be healed
Type
boolean

can_move_to(x, yopt) → {boolean}

Checks if there is a clear path to the coordinates or the entity. For an entity you don't have to supply the second argument
Parameters:
Name Type Attributes Description
x Monster | Player | number This can be either be a number or an entity. When this is an entity the function will check if there is a clear path to that entity. When this a number the function also expects the y coordinate to be given.
y number <optional>
The y coordinate of the position
Source:
Returns:
Whether or not there is a clear path the the coordinates
Type
boolean

can_use(name) → {boolean}

(WIP) Check if the cooldown of a class skill has passed
Parameters:
Name Type Description
name string name of skill
Source:
Returns:
- true of cooldown has passed
Type
boolean

change_target(target, sendopt)

Change the targeted entity
Parameters:
Name Type Attributes Default Description
target Monster the new target
send boolean <optional>
false send change target to server
Source:

clear_buttons()

Strips all the buttons of their HTML and data.
Source:

clear_drawings()

Clears drawings added with draw_circle and draw_line functions from the screen.
Source:

command_character(name, code_snippet)

Commands the character in [CODE] mode (doesn't work with multiple windows).
Parameters:
Name Type Description
name string The name of the character to command.
code_snippet string The code to run.
Source:
Example
command_character("Me", "say('OMG')");

compound(item0, item1, item2, scroll_num, offering_numopt)

Uses the upgrade npc to combine jewelery Combining works by taking 3 jewelery items of the same type and a scroll for example -> compound(0,1,2,6) -> 3 items in the first 3 slots, scroll at the 6th spot On the normal Server you have to be close to the npc for it to work.
Parameters:
Name Type Attributes Description
item0 number Item one
item1 number Item two
item2 number Item three
scroll_num number
offering_num number <optional>
Source:

continue_pathfinding()

Internal smart_move function
Source:

destroy_item(num)

Destroys an item in the num-th Inventory slot
Parameters:
Name Type Description
num number The Inventory slot of the Item [0,41].
Source:

draw_circle(x, y, radius, size, color) → {PIXI.Graphics}

Documentation: https://pixijs.github.io/docs/PIXI.Graphics.html Example: draw_circle(character.real_x,character.real_y,character.range) :) [22/10/16]
Parameters:
Name Type Description
x number
y number
radius number
size number
color color
Source:
Returns:
Type
PIXI.Graphics

draw_line(x, y, x2, y2, size, color) → {PIXI.Graphics}

Documentation: https://pixijs.github.io/docs/PIXI.Graphics.html keep in mind that drawings could significantly slow redraws, especially if you don't .destroy() them
Parameters:
Name Type Description
x number
y number
x2 number
y2 number
size number
color color
Source:
Returns:
Type
PIXI.Graphics

equip(num, slotopt)

Equips the Item in the num-th inventory Slot starting from 0.
Parameters:
Name Type Attributes Description
num number The slot the items is currently in
slot number <optional>
Optional - The slot in which to put the item
Source:
Example
equip(1);
equip(0, "mainhand"); // show_json(character.slots) => to see slot options

exchange(item_num)

Tries to exchange an item in a specific inventory slot. This function also works with quest items and when multiple items are exchanged at once e.g. seashells.
Parameters:
Name Type Description
item_num number Inventory slot
Source:

game_log(message, coloropt)

Uses the game log to print out a message
Parameters:
Name Type Attributes Default Description
message string the message to print
color string <optional>
#51D2E1 the color in which to display the message
Source:

get_active_characters() → {Object.<string, string>}

Returns active characters and their state. States: "self", "starting","loading", "active", "code".
Source:
Returns:
Example return: {"Me":"self","Protector":"loading"}
Type
Object.<string, string>

get_map() → {Map}

Returns current map the player is on
Source:
Returns:
current map the player is on
Type
Map

get_nearest_hostile(args) → {Player}

Get nearest Hostile. This function is mainly for finding hostile players in your proximity
Parameters:
Name Type Description
args Object
Properties
Name Type Attributes Default Description
exclude Array.<string> <optional>
An array of Player names which will not be considered hostile
friendship boolean <optional>
true Should friends be considered friendly
Source:
Returns:
Type
Player

get_nearest_monster(args) → {Monster}

Get nearest Monster out of the entities array that meets certain criteria and returns it.
Parameters:
Name Type Description
args Object
Properties
Name Type Description
type string the monster type of Monster
min_xp number Minimum xp that the Monster should give
max_att number The Maximum attack value a Monster should have
no_target boolean Attack only targets that have no target
path_check boolean Check If you can walk straight to the target
Source:
Returns:
Type
Monster

get_player(name) → {Player}

The entity of a player, only works when the player is visible.
Parameters:
Name Type Description
name String The name of the character
Source:
Returns:
- The Player Object
Type
Player

get_socket() → {socket}

Return Socket.IO socket, this is the Object which the game uses to communicate with the server
Source:
Returns:
Type
socket

get_target() → {Monster|Player|null}

The current target Entity of the character without checks
Source:
Returns:
- The current target Entity of the character
Type
Monster | Player | null

get_target_of(entity) → {Monster|null}

Returns Entity which the Entity is targeting
Parameters:
Name Type Description
entity Monster The Entity of which to fetch the target
Source:
Returns:
the target entity or null if the entity has no target
Type
Monster | null

get_targeted_monster() → {Monster|null}

The current target Entity of the character but with additional checks. This prevents the targeting of already dead targets or players
Source:
Returns:
- The current target Entity of the character
Type
Monster | null

handle_command(command, args) → {number}

You can implement your own chat commands with this function.
Parameters:
Name Type Description
command string
args string
Source:
Returns:
Type
number

handle_death()

When a character dies, character.rip is true, you can override handle_death and manually respawn IDEA: A Resident PVP-Dweller, with an evasive Code + irregular respawning NOTE: Add `if(character.rip) {respawn(); return;}` to your main loop/interval too, just in case
Source:
Example
function handle_death() {
  setTimeout(respawn,15000); // respawn current has a 12 second cooldown, best wait 15 seconds before respawning [24/11/16]
  return true;
}

heal(target)

Tries to heal the targeted Character
Parameters:
Name Type Description
target Player The target to heal
Source:

in_attack_range(target) → {boolean}

Checks if the Entity is in attack range
Parameters:
Name Type Description
target Player | Monster The entity to check
Source:
Returns:
True if the entity is in range
Type
boolean

is_character(entity) → {boolean}

Checks if the Entity if is a character or not.
Parameters:
Name Type Description
entity Entity The entity to check.
Source:
Returns:
True if the Entity is a character.
Type
boolean

is_monster(entity) → {boolean}

Checks if the Entity if is a monster or not.
Parameters:
Name Type Description
entity Entity The entity to check.
Source:
Returns:
True if the Entity is a monster.
Type
boolean

is_moving(entity) → {boolean}

return true if the entity is moving
Parameters:
Name Type Description
entity Player | Character | Monster The entity in question
Source:
Returns:
True if the entity is moving
Type
boolean

is_npc(entity) → {boolean}

Checks if the Entity if is an NPC or not.
Parameters:
Name Type Description
entity Entity The entity to check.
Source:
Returns:
True if the Entity is an NPC.
Type
boolean

is_player(e) → {boolean}

Same as is_character.
Parameters:
Name Type Description
e Entity The entity to check.
Source:
Returns:
True if the Entity is a character.
Type
boolean

is_pvp() → {boolean}

Checks if you're in a PVP zone.
Source:
Returns:
True if you're in a PVP zone.
Type
boolean

is_transporting(entity) → {boolean}

Is the entity using the town teleportation skill
Parameters:
Name Type Description
entity Player | Character | Monster The entity in question
Source:
Returns:
True if the entity using the teleport skill
Type
boolean

item_grade(item) → {number}

The item Grade in Number format. -1: Invalid Input 0 : Normal 1 : High 2 : Rare
Parameters:
Name Type Description
item Object
Properties
Name Type Description
name string
Source:
Returns:
- {-1:Something went wrong, 0:Normal, 1:High, 2:Rare}
Type
number

item_properties(item) → {ItemStats|null}

Returns an object containing all the stat properties of an item
Parameters:
Name Type Description
item Gear The Item in question
Source:
Returns:
- An Object containing all stats and there number or null on error
Type
ItemStats | null

item_value(item) → {number}

Returns how much the item is worth in gold
Parameters:
Name Type Description
item Gear | Consumables
Source:
Returns:
- How the item is worth in gold when sold to an npc
Type
number
Example
item_value(character.items[0]);

load_code(name, onerror)

Loads saved code with the specified name into CODE.
Parameters:
Name Type Description
name string
onerror function A function that gets executed when the code errors
Source:

loot(commander)

Find the first 2 chests and opens them
Parameters:
Name Type Description
commander boolean allows code characters to make their commanders' loot instead, extremely useful
Source:

map_key(key, skill, codeopt)

Maps a skill or code to key.
Parameters:
Name Type Attributes Description
key string The key which will be bound.
skill string The skill to bind to the key.
code string <optional>
The code to bind to the key (overrides skill).
Source:
Example
map_key("1","use_hp");
map_key("2","snippet","say('OMG')");
map_key("1","esc");
map_key("ESC","up");

on_cm(name, data)

Parameters:
Name Type Description
name string Sender of Code Message
data Object An Object containing the information send
Source:

on_combined_damage()

When multiple characters stay in the same spot, they receive combined damage, this function gets called whenever a monster deals combined damage. Override this function in CODE to react to it
Source:

on_destroy()

Called just before the CODE is destroyed. Can be used to remove event listeners or revert states.
Source:

on_disappear(entity, data)

This function gets called whenever an entity disappears
Parameters:
Name Type Description
entity Player | Monster
data
Source:

on_draw()

The game calls this function at the best place in each game draw frame, so if you are playing the game at 60fps, this function gets called 60 times per second.
Source:

on_party_invite(name)

Someone is inviting you to a party
Parameters:
Name Type Description
name string The name of the inviting player
Source:

on_party_request(name)

Someone requesting to join your existing party
Parameters:
Name Type Description
name string The name of the player
Source:

pget(name) → {*}

Retrieves data from local storage.
Parameters:
Name Type Description
name string The name of the data store.
Source:
Returns:
The data stored in "name".
Type
*

plot(index)

Parameters:
Name Type Description
index number
Source:

pm(x, y)

Sets the character moving to specific coordinates, before using this you should check if you can actually walk to your target or else you might end up somewhere else.
Parameters:
Name Type Description
x number X coordinate
y number Y coordinate
Source:

preview_item(def, args)

Pops up a window showing what an item would look like with the specified parameters. (FIXME: Document arguments better, example)
Parameters:
Name Type Description
def string The item's id.
args Object The item's data.
Source:

pset(name, value) → {*}

Saves data into local storage.
Parameters:
Name Type Description
name string The name of the data store.
value * The data to store.
Source:
Returns:
Returns from "parent.storage_set(name, value)" (FIXME, define return value)
Type
*

qpush(node)

Parameters:
Name Type Description
node
Source:

quantity(name) → {number}

The quantity of items named "name" in the inventory.
Parameters:
Name Type Description
name string The name of the item to count.
Source:
Returns:
- The number of times the item name was found in the inventory.
Type
number

reset_mappings()

Resets your key mappings.
Source:

respawn()

Lets the character respawn
Source:

say(message)

Acts as if the player had typed the message into the chat and then send it. This also allows for the use of commands.
Parameters:
Name Type Description
message string The message to send
Source:

sell(num, quantity)

Tries to sell the Item in the num-th inventory slot to an npc.
Parameters:
Name Type Description
num number Inventory slot
quantity number Quantity
Source:

send_cm(to, data)

Send CODE messages to the characters, of course it only works if both characters have CODE active.
Parameters:
Name Type Description
to Array | string Either an Array of names or just a name
data Object The data to be sent in object form
Source:

send_gold(receiver, gold)

Send gold to another player
Parameters:
Name Type Description
receiver Player | string Either a character name or a OtherCharacter Object
gold number The amount of gold to send
Source:

send_item(receiver, num, quantityopt)

Send item to another player
Parameters:
Name Type Attributes Default Description
receiver Player | string Either a character name or a OtherCharacter Object
num number Inventory slot starting from 0
quantity number <optional>
1 Quantity
Source:

send_party_invite(name, is_request)

Sends a party Invite to another character
Parameters:
Name Type Description
name Player | string name ca be a player object, a player name, or an id
is_request boolean Is requesting to be invited
Source:

send_party_request(name)

Request to be invited into a party
Parameters:
Name Type Description
name Player | string name ca be a player object, a player name, or an id
Source:

set_button_color(id, color)

Sets a function to run when clicked.
Parameters:
Name Type Description
id string the button to modify
color string the colour to set the button to
Source:
Example
set_button_color("myButton", "#FFFFFF"); // sets myButton to white

set_button_onclick(id, fn)

Sets a function to run when clicked.
Parameters:
Name Type Description
id string the button to modify
fn function the function to run
Source:

set_button_value(id, value)

Sets the displayed text of a button.
Parameters:
Name Type Description
id string the button to modify
value string the text to display
Source:

set_keymap(keymap)

Replaces your current keymap with "keymap".
Parameters:
Name Type Description
keymap Object.<string, Object.<string, string>> | Object.<string, {code: string, name: string}> A dictionary of keys to map.
Source:
Example
set_keymap({"1":{"name":"use_mp"},"2":{"name":"use_hp"}}); // Set key 1 to use health potion, and key 2 to use mana potion.
set_keymap({"1":{name: "snippet", code: "say('OMG')"}}); // Set key 1 to say "OMG".

// Set key 1 to use health potion, and key 2 to say "OMG".
var skillkey = {"name":"use_mp"};
var codekey = {name: "snippet", code: "say('OMG')"};
set_keymap({"1": skillkey, "2": codekey});

set_message(text, coloropt)

When CODE is active uses a window in the bottom right hand corner to display a status messages The window is pretty small so keep it short.
Parameters:
Name Type Attributes Description
text string the text that should be displayed
color string <optional>
the color in which the text should be displayed
Source:

set_skillbar(arguments)

Replaces your skillbar keys.
Parameters:
Name Type Description
arguments string | Array.<string> The keys to bind.
Source:
Example
set_skillbar("1","2","3","4","R");
set_skillbar(["1","2","3","4","R"]);

shift(num, name)

Shifts an item, likely a booster, in the num-th inventory slot to s pecific mode shift(0,'goldbooster'); would set the booster int the first inventory slot to gold mode Other modes are "xpbooster" and "luckbooster"
Parameters:
Name Type Description
num number Position of Inventory Slot starting from 0
name string name of the Item
Source:

show_json(e)

A debug Command which opens a Window and shows the json representation of the Object.
Parameters:
Name Type Description
e Object The Object you like to inspect
Source:

smart_move(destination, on_done)

Uses a Breadth-first search path finding algorithm to find the shortest path despite the name, smart_move isn't very smart or efficient, it's up to the players to implement a better movement method.
Parameters:
Name Type Description
destination Object
Properties
Name Type Description
to string Can be of multiple values. If destination.to is a monster name we will find where they spawn and set the target destination. Monsters like the phoenix or mvampire have random spawn locations we want to check for the accordingly Every time we search for the phoenix we will try a different location so if nobody kill it we will eventually find it If destination to is one of "upgrade", "exchange", "potions", "scrolls" we will find the path to the closest shop that sells the items.
map string Destination map
x number Destination coordinates
y number Destination coordinates
on_done function Function that gets executed once the path finding finishes.
Source:

smart_move_logic()

Internal smart_move function
Source:

smooth_path()

Internal smart_move function Assume the path ahead is [i] [i+1] [i+2] - This routine checks whether [i+1] could be skipped The resulting path is smooth rather than rectangular and bumpy Try adding "function smooth_path(){}" or "smart.prune.smooth=false;" to your Code
Source:

start_character(name, code_slot_or_name)

Loads a character in [CODE] mode.
Parameters:
Name Type Description
name string The name of the character to load.
code_slot_or_name string | number The name or slot number of the code to run.
Source:

start_pathfinding()

Internal smart_move function
Source:

stop()

Stop path finding and moving
Source:

stop_character(name)

Stops the character from running.
Parameters:
Name Type Description
name string The name of the character to stop.
Source:

swap(a, b)

Move/swap slots in the inventory.
Parameters:
Name Type Description
a number The first slot to swap.
b number The second slot to swap.
Source:

trade(num, trade_slot, price, quantityopt)

Puts an item up for sale
Parameters:
Name Type Attributes Description
num number The slot the item is in
trade_slot number The slot in the trade window where is should appear
price number The price of the item
quantity number <optional>
The amount of items
Source:

trade_buy(target, trade_slot)

Buys an item from a player's shop.
Parameters:
Name Type Description
target Player The player entity you want to buy from
trade_slot number The trade slot in which the item is you want to buy
Source:

trigger_event(name, data)

Parameters:
Name Type Description
name string
data *
Source:

unequip(slot)

Unequips the Item in the specified character slot.
Parameters:
Name Type Description
slot string the slot in which to remove the item
Source:
Example
unequip("mainhand"); // show_json(character.slots) => to see slot options

unfriend(name)

Unfriends a player.
Parameters:
Name Type Description
name string The name of a character or owner ID of the player to unfriend.
Source:

unmap_key(key)

Removes a mapping from a key.
Parameters:
Name Type Description
key string The key which will have it's binding removed.
Source:
Example
unmap_key('1');

upgrade(item_num, scroll_num, offering_numopt)

Uses the upgrade npc to upgrade items.
Parameters:
Name Type Attributes Description
item_num number Slot number of the item you want to upgrade
scroll_num number Slot number of the scroll you want to upgrade
offering_num number <optional>
Slot number of the offering you want to use
Source:

use(name, targetopt)

if name parameter is a number, the character will try to equip the Item in the specified slot. Otherwise it will try to cast the skill with that name and Target
Parameters:
Name Type Attributes Description
name number | string skill name or item slot
target Monster <optional>
target Entity when using skill
Source:

use_hp_or_mp()

If low, regenerates MP or HP, using potions if available.
Source:

use_skill(name, targetopt)

Will use a skill on the specified target If no target is specified the current character target will be used
Parameters:
Name Type Attributes Description
name string name of skill
target Monster <optional>
target Entity
Source:

Type Definitions

ChannelingConditions

Type:
  • Object
Properties:
Name Type Description
town boolean Using the town teleportation skill
Source:

CharacterSlots

The name of the character slots, they may or may not contain Gear
Type:
  • Object
Properties:
Name Type Description
ring1 Gear
ring2 Gear
earring1 Gear
earring2 Gear
belt Gear
offhand Gear
chest Gear
pants Gear
shoes Gear
gloves Gear
amulet Gear
orb Gear
elixir Gear
cape Gear
mainhand Gear
helmet Gear
Source:

CharacterStats

Type:
  • Object
Properties:
Name Type Description
dex number Dexterity: Increases the attack speed.
int number Intelligence: Increases maximum mana, also increases resistance by a factor of 1.5 for every int point.
vit number Vitality: Increases Health points proportional to level.
str number Strength: Increases Health points and Armor.
Source:

Consumables

Type:
  • Object
Properties:
Name Type Description
name string Item name
q number quantity: how many items are on this stack.
Source:

Gear

Type:
  • Object
Properties:
Name Type Attributes Description
name string Item name
level number level of item
CharacterStats string <optional>
either dexterity, intelligence, vitality, strength.
Source:

ItemStats

Every item may or may not contain any number or combination of these attributes. It is probably a good idea to check if they exist first.
Type:
  • Object
Properties:
Name Type Description
apiercing number Subtract this number from target's armor to get the number used in damage calc.
armor number Reduces the incoming physical damage by 1% for every 10 armor points.
damage number Proportional increase in damage dealt.
attack number Depreceated.
attr0 number Reserved for items that are required to use a skill.
attr1 number Reserved for various items that modify character behavior.
crit number Chance to crit and do double damage
dreturn number Percent damage returned to melee attackers.
evasion number Chance to evade the attack and negate all damage
gold number The percent gold increase given from this item.
hp number The ammount of HP to add to the character.
level number The item level
lifesteal number Percent lifesteal. When you deal damage, you gain that percent of the damage you dealt as HP.
mp number The amount of mana to be added.
range number The range added to your character when you attack.
reflection number Chance to reflect a magic attack back at the attacker.
resistance number Reduces the incoming magical damage by 1% for every 10 resistance points.
frequency number Higher frequency means faster attack.
rpiercing number Subtracts this number from the target's resistance to get the number used for damange calc.
speed number Adds the the character speed, 1 point equals one additional pixel walked per second.
stat number Can be converted to dex, int, str or vit with the corresponding scrolls
dex number Dexterity: Increases the attack speed.
int number Intelligence: Increases maximum mana, also increases resistance by a factor of 1.5 for every int point.
vit number Vitality: Increases Health points proportional to level.
str number Strength: Increases Health points and Armor.
Source:

Map

Type:
  • Object
Properties:
Name Type Description
name string A Human readable name
on_death number
monsters Array.<Object>
compound Object
data Object
doors Array.<Array>
drop_norm number
exchange Object
items Object
key string
merchants Array.<Object>
monsters Array.<Object>
npcs Array.<Object>
quirks Array.<Array>
ref Object
u_mid Array.<number>
c_mid Array.<number>
spawns Array.<Array>
transporter Object
upgrade Object
Source:

on_game_event

Override this function to listen for game events
Source:
Example
function on_game_event(event) {
    if (event.name == "pinkgoo") {
        // start searching for the "Love Goo" of the Valentine's Day event
    }
    if (event.name == "goblin") {
        // start searching for the "Sneaky Goblin"
    }
}

StatusConditions

//TODO: describe how status effect affect the character
Type:
  • Object
Properties:
Name Type Description
stunned boolean -
cursed boolean -
poisoned boolean -
poisonous boolean -
charging boolean -
invis boolean The character is invisible
invincible boolean -
mute boolean -
Source: