Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Scriptref Triggers: Difference between revisions

From Lost City Wiki
Branon (talk | contribs)
No edit summary
Branon (talk | contribs)
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 18: Line 18:
There are several dozen different triggers but they can be divided up into three main types:
There are several dozen different triggers but they can be divided up into three main types:


'''Specific''' triggers fire when the player interacts with a single subject, and use the syntax <code>[trigger,subject]</code>
* '''Specific''' triggers fire when the player interacts with a single subject, and use the syntax <code>[trigger,subject]</code>
 
* '''Category''' triggers fire when the player interacts with any subjects in a particular category. Categories are prefixed with an underscore so the syntax looks like <code>[trigger,_category]</code>
'''Category''' triggers fire when the player interacts with any subjects in a particular category. Categories are prefixed with an underscore so the syntax looks like <code>[trigger,_category]</code>
* The '''global''' trigger acts as a fallback and fires if no other triggers exist for that subject ("''Nothing interesting happens''"). The global trigger actually uses a category so the syntax is <code>[trigger,_]</code>
 
<nowiki>*</nowiki> The '''global''' trigger acts as a fallback and fires if no other triggers exist for that subject ("''Nothing interesting happens''"). The global trigger actually uses a category so the syntax is <code>[trigger,_]</code>


=== Triggers: <code>op</code> versus <code>ap</code> ===
=== Triggers: <code>op</code> versus <code>ap</code> ===
Most triggers you will encounter in everyday use are prefixed with either <code>op</code> or <code>ap</code>:
Most triggers you will encounter in everyday use are prefixed with either <code>op</code> or <code>ap</code>:


<nowiki>*</nowiki> <code>op</code>: '''Operable''' within one tile, requires line of walk, restricted to cardinal directions  
* <code>op</code>: '''Operable''' within one tile, requires line of walk, restricted to cardinal directions  
 
* <code>ap</code>: '''Approachable''' within 10 tiles, requires line of sight
<nowiki>*</nowiki> <code>ap</code>: '''Approachable''' within 10 tiles, requires line of sight


Remember that <code>op</code> triggers are used for interactions within melee distance (one tile away) and <code>ap</code> triggers are used for interactions at range (between two and ten tiles away).
Remember that <code>op</code> triggers are used for interactions within melee distance (one tile away) and <code>ap</code> triggers are used for interactions at range (between two and ten tiles away).
Line 36: Line 33:
Breaking down a bit further, triggers can be categorized by subject type. Different triggers are intended to fire upon interaction with different types of subjects:
Breaking down a bit further, triggers can be categorized by subject type. Different triggers are intended to fire upon interaction with different types of subjects:


<nowiki>*</nowiki> Player subjects: <code>opplayer1-5</code> / <code>applayer1-5</code>
* Player subjects: <code>opplayer1-5</code> / <code>applayer1-5</code>
 
* NPC subjects: <code>opnpc1-5</code> / <code>apnpc1-5</code>
<nowiki>*</nowiki> NPC subjects: <code>opnpc1-5</code> / <code>apnpc1-5</code>
* Loc subjects: <code>oploc1-5</code> / <code>aploc1-5</code>
 
** "Loc" (or ''location'') is the Jagex term which refers to any interactable (clickable) scenery found in the game.
<nowiki>*</nowiki> Loc subjects: <code>oploc1-5</code> / <code>aploc1-5</code>
* Objects on the ground: <code>opobj</code> / <code>apobj</code>
 
** "Object" refers to items, either on the ground or held in the inventory
  * "Loc" (or ''location'') is the Jagex term which refers to any interactable (clickable) scenery found in the game.
* Objects held in the inventory: <code>opheld1-5</code> / <code>opheldu</code> (held objects cannot be <code>ap</code>proached)
 
<nowiki>*</nowiki> Objects on the ground: <code>opobj</code> / <code>apobj</code>
 
  * "Object" refers to items, either on the ground or held in the inventory
 
<nowiki>*</nowiki> Objects held in the inventory: <code>opheld1-5</code> / <code>opheldu</code> (held objects cannot be <code>ap</code>proached)


There are more triggers but this gives you an idea of how the naming convention works.
There are more triggers but this gives you an idea of how the naming convention works.
Line 60: Line 51:
** Operation 1 for the border guard is <code>Talk-to</code>.
** Operation 1 for the border guard is <code>Talk-to</code>.


<nowiki>*</nowiki> <code>[oploc1,_door_closed]</code>
* <code>[oploc1,_door_closed]</code>
** This trigger fires when the player clicks any door in the <code>door_closed</code> category within melee distance. This is a '''category''' trigger because its subject is prefixed with <code>_</code>.
* This is a '''loc''' trigger because a door is clickable/interactable scenery and is therefore referred to as a loc.
* The trigger used is <code>oploc1</code>, and operation 1 on closed doors of this category is <code>Open</code>.


  * This trigger fires when the player clicks any door in the `door_closed` category within melee distance. This is a **category** trigger because its subject is prefixed with `_`.
* <code>[applayeru,rotten_tomato]</code>
** This trigger fires when the player uses a rotten tomato on another player from <code>ap</code>roachable distance (at a range of between 2 and 10 tiles).
* This is a '''specific''' trigger because it will only fire when the used item is a rotten tomato.
* This trigger only applies to players, so it will not fire if the rotten tomato is used on an NPC (that would be <code>apnpcu</code>).


  * This is a **loc** trigger because a door is clickable/interactable scenery and is therefore referred to as a loc.
Now you understand how to set triggers in RuneScript. The syntax is fairly simple: your desired trigger and its subject, separated by a comma, and enclosed in brackets.
 
    * The trigger used is `oploc1`, and operation 1 on closed doors of this category is `Open`.
 
<nowiki>*</nowiki> `[applayeru,rotten_tomato]`
 
  * This trigger fires when the player uses a rotten tomato on another player from `ap`roachable distance (at a range of between 2 and 10 tiles).
 
  * This is a **specific** trigger because it will only fire when the used item is a rotten tomato.
 
    * It is also a `player` trigger so it will not fire if e.g. a player uses the rotten tomato on an NPC (that would be `apnpcu`).


Now you understand how to set triggers in RuneScript. The syntax is fairly simple: your desired trigger and its subject, separated by a comma, and enclosed in brackets.
'''[[Scriptref Procs|Next Page]] || [[:Category:Scriptref|Browse all Scriptref pages]]'''

Latest revision as of 16:39, 22 August 2025

Previous Page || Browse all Scriptref pages

Triggers

RuneScript operates primarily via triggers, which describe how and when to execute functions. Triggers consist of two parts: the trigger itself, and a subject.

Triggers will fire when a player interacts with the game world (typically by clicking) and the functions executed by the trigger are responsible for what actions the game engine will take after the player clicks.

Nearly everything a player does in-game will fire some sort of trigger. Likewise almost all RuneScript is written to execute in response to a fired trigger.

Triggers can be placed in any RuneScript file and the order of triggers does not matter, however it still pays to stay organized!

Types of Triggers

There are several dozen different triggers but they can be divided up into three main types:

  • Specific triggers fire when the player interacts with a single subject, and use the syntax [trigger,subject]
  • Category triggers fire when the player interacts with any subjects in a particular category. Categories are prefixed with an underscore so the syntax looks like [trigger,_category]
  • The global trigger acts as a fallback and fires if no other triggers exist for that subject ("Nothing interesting happens"). The global trigger actually uses a category so the syntax is [trigger,_]

Triggers: op versus ap

Most triggers you will encounter in everyday use are prefixed with either op or ap:

  • op: Operable within one tile, requires line of walk, restricted to cardinal directions  
  • ap: Approachable within 10 tiles, requires line of sight

Remember that op triggers are used for interactions within melee distance (one tile away) and ap triggers are used for interactions at range (between two and ten tiles away).

Trigger Naming Convention

Breaking down a bit further, triggers can be categorized by subject type. Different triggers are intended to fire upon interaction with different types of subjects:

  • Player subjects: opplayer1-5 / applayer1-5
  • NPC subjects: opnpc1-5 / apnpc1-5
  • Loc subjects: oploc1-5 / aploc1-5
    • "Loc" (or location) is the Jagex term which refers to any interactable (clickable) scenery found in the game.
  • Objects on the ground: opobj / apobj
    • "Object" refers to items, either on the ground or held in the inventory
  • Objects held in the inventory: opheld1-5 / opheldu (held objects cannot be approached)

There are more triggers but this gives you an idea of how the naming convention works.

Examples of Common Triggers

Here are some real-world examples of common triggers you will encounter:

  • [opnpc1,border_guard_lumby]
    • This is the trigger that fires when a player clicks on a Lumbridge border guard within melee distance. It is a specific trigger because its subject is not prefixed by an underscore.
  • The trigger being used here is opnpc1 which is shorthand for performing operation 1 on an npc.
    • Operation 1 for the border guard is Talk-to.
  • [oploc1,_door_closed]
    • This trigger fires when the player clicks any door in the door_closed category within melee distance. This is a category trigger because its subject is prefixed with _.
  • This is a loc trigger because a door is clickable/interactable scenery and is therefore referred to as a loc.
  • The trigger used is oploc1, and operation 1 on closed doors of this category is Open.
  • [applayeru,rotten_tomato]
    • This trigger fires when the player uses a rotten tomato on another player from aproachable distance (at a range of between 2 and 10 tiles).
  • This is a specific trigger because it will only fire when the used item is a rotten tomato.
  • This trigger only applies to players, so it will not fire if the rotten tomato is used on an NPC (that would be apnpcu).

Now you understand how to set triggers in RuneScript. The syntax is fairly simple: your desired trigger and its subject, separated by a comma, and enclosed in brackets.

Next Page || Browse all Scriptref pages