Runescript

From RuneScape Classic Wiki
(Redirected from RuneScript)
Jump to navigation Jump to search

Runescript is the programming language used for the implementation of most server-side content in RuneScape Classic, such as quests and the mining skill.

Effects on gameplay

[edit | edit source]
  • Runescript uses random probabilities from 1 to 256, making this a visible number in the probability of a lot of RuneScape Classic content.
  • Most potions and drinks (e.g. strength potions and beer) provide a constant stat boost or drain as well as a percentage boost and drain due to the implementation of the addstat and substat functions.
  • Delays in runescript use discrete game ticks, not milliseconds. There can be no delay that is not some multiple of a tick-length.

Syntax

[edit | edit source]

Unlike later versions of RuneScape, Classic Runescript is not a C-like language. Lines starting with = indicate a "trigger" (entry point or label), while lines starting with + are to be executed if a previously-set condition was positive, and - the inverse. * is used at the beginning of lines that are executed regardless of the condition bit.

Example script

[edit | edit source]

Here is an example script for a fictional NPC internally named "RSCWiki". There are some comments starting with //, which are allowed to be either inline or at the beginning of a line.

  =TalkNpc,RSCWiki
    *ifvar(WasRude,1);
    +jump(MetBeforeAndWasRude); // "jump" is similar to GOTO in BASIC. It finds the label given as its argument, and resumes execution at that label.
    -jump(HelloWorld);
  =Label,HelloWorld
    *npcsay("Hello world!");
    *multi2("My name is not world, shove off",NotNamedWorld,"Hi RSC Wiki!",SayHiBack); // Displays the cyan text menu at the top left with two options
  =Label,NotNamedWorld
    // Take 10 coins if the player has them, else be rude back
    *ifheld(coins,10);
    +npcsay("That's rather rude, i'll be mugging you then.");
    +remove(coins,10);
    -npcsay("You're lucky I don't mug you for being so rude.");
    -npcsay("It's common decency to say hello back");
    *say("Wow I didn't like that."); // regardless of if the player had 10 coins or not, this is said.
    *setvar(WasRude,1); // Game will remember that this happened for next time the player talks to the NPC.
  =Label,SayHiBack
    *npcsay("You're a bit presumptious");
    *npcsay("I was clearly talking to the world, not you");
    *say("Ok");
  =Label,MetBeforeAndWasRude
    *npcsay("Oh, it's you.");
    *npcsay("I had hoped not to encounter you again.");
    *say("I'm sorry i was so rude to you earlier");
    *say("there was no way for you to know");
    *say("my name wasn't world");
    *ifrandom(64); // 25% chance of forgiveness; number is between 0 and 256 with 0 impossible & 256 certain.
    +npcsay("...");
    +delay(2); // delays 2 game ticks, about 1.2 or 1.3 seconds.
    +npcsay("Okay I forgive you");
    +setvar(WasRude,0); // deletes the WasRude variable
    -npcsay("I do not forgive you.");

If you have trouble following this example, you can read a wiki transcript here:

  • Scripts can be terminated mid-execution by a player logging out, an example of this being abused is the widely known crystal chest bug.
[edit | edit source]
  • Runescript guide. It can be determined from the mention of showeffect(type); that this document should date from at least 24 January 2002, which is when support for spell effect bubbles was first added to the client. However, it is possible that some parts of the RuneScript documentation were not fully updated, since it mentions displaybalance(); "Displays the players[sic] current bank balance", which wouldn't be an accurate description of the way the bank worked once it became possible to store items in the bank (not just coins), on 26 July 2001.