RuneScript

From the RuneScape Wiki, the wiki for all things RuneScape
(Redirected from Max stack)
Jump to navigation Jump to search

RuneScript is a scripting language that Jagex uses to create content for RuneScape. The game engine is not written in RuneScript, instead using Java, while both the desktop and mobile clients are written in C++. RuneScript was developed by Jagex Ltd. to allow their other staff that do not know Java to add and edit content for the game. The game engine cannot read the RuneScript source files directly, they first need to be translated into a more computer-friendly form known as bytecode.

We write in a scripting language called RuneScript, which our Game Engine team has created specifically for making RuneScape content. The Java-based game engine then reads this RuneScript code and makes it all work. RuneScript is constantly being changed and expanded as we add new features to it to allow it to do new things."
Mod John A, New Dwarf Quest: Coding and Writing[1]
Hmm, syntax wise it's similar to any C-style language, except variable names are prefixed with their type (eg. %varname is an integer). We also lack full array support. Other than that, it'd do pretty much anything you could do in C or Java.
Mod Chris E, Game Engine Q&A[2]

The minor updates are usually for introducing a new map and adding new NPCs, and for these updates, a RuneScript file is added into the program. The major updates are for the source code, which is usually for making large changes such as introducing new areas in RuneScape, new skills, or for bug fixes.

Syntax

[edit | edit source]

The syntax of RuneScript is very simple and meant to be understandable by people who are not very familiar with programming.

Declarations

[edit | edit source]

A script or a configuration can be declared using the brackets (example: [declaration_name])

Triggers

[edit | edit source]

Triggers indicate when a script will be called by the game engine. In-order to add a trigger to a script, it has to be append at the start of the declaration name followed by a comma (example: [trigger,declaration_name]).

Below is a list of the most common triggers:

Common Triggers
Name Description
clientscript Can only be triggered by the client game engine or using "runclientscript" command.
proc Can only be triggered manually using the "~" operator.
label Can only be triggered manually using the "@" operator.
if_button[1..10] Can be triggered when clicking on an interface button.
opheld[1..5] Can be triggered when using an item option in inventory such as "Wear" or "Equip".
opheldu Can be triggered when an item is used on another item.
opnpc[1..5] Can be triggered when operating an NPC option such as "Talk-to".
apnpc[1..5] Can be triggered when approaching an NPC after clicking one of its options.
opnpcu Can be triggered when an item is used on an NPC.
oploc[1..5] Can be triggered when using an object option such as "Cut".
aploc[1..5] Can be triggered when approaching an object after clicking one of its options.

(Example usage would be the bank booth, it opens before the player is next to it)

ai_queue3 Can be triggered when an NPC dies. Usually used for drop scripts.

Variables

[edit | edit source]

There are three kind of variables in RuneScript:

  • A constant which can be identified using the caret sign (example: ^total_bank_slots) this can be accessed anywhere.
  • A local variable which can be identified using the dollar sign (example: $pagecount) this can be accessed only from the same scope.
  • A player or npc variable which can be identified using the modulo sign (example: %varname) this can be accessed anywhere from scripts.

Commands

[edit | edit source]

Commands are subroutines that are defined in the game engine, which don't need any special operator to call them for example map_members is a command.

Subroutines

[edit | edit source]

Subroutines are scripts that are defined in RuneScript, they can be called by either one of the four:

  • a jump operator (@) (example: @bronze_arrowheads)
  • a gosub operator ( ~) (example: ~arceuus_door_forbid)
  • a jump keyword (example: jump(bronze_arrowheads))
  • a gosub keyword (example: gosub(arceuus_door_forbid))

Commands

[edit | edit source]

Below is a list of the common commands that are used by the drop table scripts:

Special Commands
Syntax Meaning
add(x,y) Add both values (x and y) together (x + y)
sub(x,y) Subtract both values (x and y) from each other (x - y)
gosub(x) Execute the (x) subroutine then returning to the calling subroutine
jump(x) Execute the (x) subroutine without returning to the calling subroutine
npc_coord Return the current NPC coordinate
map_members Return (1) if the current world is a member world
find_uid(id) Return true if finds uid
npc_findhero Return true if the killing player (hero) is found
obj_add(coord,item_name,quantity,ticks_before_despawning) Spawn an item on the ground
npc_param(param) Return a parameter value from the NPC definition (e.g: death_drop return the 100% drop for an npc)

Subroutines

[edit | edit source]

Below is a list of the common subroutines that are used by the drop table scripts:

General Subroutines
Name Meaning
npc_death Handles the default NPC death procedure
ultrarare Possibly the rare drop table subroutine
kill4jewel Possibly the gem drop table subroutine
randomjewel Return an item name
randomherb Return an item name
loot_choosehero Return UID of killing player
dagannoth_droptalisman Returns an item name
lootdrop_forbroadcast(item,coord,bool(?),broadcast_map_chunk,int,int) Generate a drop broadcast at the same time as dropping loot (for boss monsters)
lootdrop(coord,item,quantity,ticks_before_despawning) Generate an item dropped as loot

Effects on the game

[edit | edit source]

Like all programming languages, Runescript has a number of limitations, some of which are inherited from Java.

Maximum values

[edit | edit source]

Items

[edit | edit source]
The maximum number of items that may be carried in one stack
The maximum number of items that may be carried in one stack

RuneScape stores the amount of items in a stack using a signed 32-bit integer, which has a maximum value of 231-1, which is equal to 2,147,483,647 (2.1 billion). Consequently, this is the maximum amount that can be stored as one stack (most often seen with coins). If a player attempts to withdraw or pick-up an item while carrying the maximum amount, it is stated that there is not enough inventory space. This limitation applies separately to every single inventory, such as the backpack, bank, reward interfaces, alchemiser machines, etc.

The limit of coins stored in the money pouch, Grand Exchange offers, and trade window is substantially higher at 2,147,483,649,147,483,647 (2.1 quintillion), which is approximately equivalent to 2.1 billion times 1 billion plus 2.1 billion (the exact formula is (2311)×109+(2311)).

Weights

[edit | edit source]

Weight is stored as a signed 16-bit integer, in grams. The maximum possible weight of a single item is thus 32.767 kg (equal to 215-1).

Counters

[edit | edit source]

Killcount in the Beasts tab is stored in a signed 32-bit integer. Two killcounts are stored in a single integer by bit-shifting the values.[3] The maximum killcount that can be tracked in-game is capped at 60,000.

Skills

[edit | edit source]

Skill experience is stored as a signed 32-bit integer. Since experience is tracked to the tenths place, the maximum value is reduced by a factor of ten, giving experience a maximum of 214,748,364.7. However, this value is capped; thus, the maximum amount of experience that can be obtained in-game is 200 million.

Skill levels are sent as an unsigned 8-bit integer, meaning their maximum value is 255. This can be seen when touching the Stone of Jas during While Guthix Sleeps quest.

Combat

[edit | edit source]

The damage for a hit is stored as a signed 16-bit integer, meaning the maximum that could be dealt in one hit is 32,767 (equal to 215-1). This applies to all hitsplats.

[edit | edit source]

References

[edit | edit source]
  1. ^ Mod John A. "Coding and Writing." 28 May 2009. (Archived from the original on 12 May 2012.) Developers' Blogs.
  2. ^ Mod Chris E. Game Engine & CM Answers!. RuneScape Forums. 13 April 2012. (Archived from the original on 13 May 2012.)
  3. ^ Mod Ana. "Why do slayer monsters cap at 60 thousand?". Reddit. 2 March 2015. (Archived from the original on 20 August 2021.)