This section is for all of the functions, types, and variables related to in-game events.
These commands will let you call your own functions whenever a specific in-game event occurs.
So first lets go over what an in-game event is:
An in-game event is an action that occurs while playing on the Old School RuneScape client.
When someone playing OSRS clicks on the games window with their mouse, that's a pointer press event (which is expressed as POINTER_PRESS in your Lua script).
When a new NPC starts loading into the game world, we would call that a NPC load event (expressed as ON_NPC_LOAD).
What if a player decided to press a key on their keyboard? That could be three different events.
The down press of the key, the release of the key, or the key identity itself, (expressed as KEY_DOWN, KEY_UP, or KEY_TYPE) depending on what you need for your script.
There are many different types of events that can all be utilized when creating your own plugin scripts, and all of them are listed under variables.
Each of these has explanations about what they do and how they’re used.
Next we can talk about event callbacks.
Each event has a corresponding callback, which can be found under types.
These callbacks show you exactly what information you are given for each event, along with code examples on how to use them.
Using our example above, where our player pressed a key on their keyboard, let’s decide we used that as a KEY_DOWN event.
Our KEY_DOWN event becomes attached to the KeyDownCallback, so that when the event happens (when the key is pressed by the player), this callback returns the keycode (a number id) of the key that was pressed.
When you use events these callbacks happen automatically, and you can use them to apply the extra information they give you.
Now that we have a good understanding on what events and event callbacks are, let's talk about how you can use them.
Lets say I want my plugin to print “Screen Clicked” every time a player clicks on the game window.
Because a mouse click is pressing the mouse key for the pointer, we know that we should use the POINTER_PRESS event, so we have to decide what we will call this event in our plugin.
By giving this our own function name, we can instruct the plugin when to connect it to the game event, in this case clicking on the game screen, and when it should stop being connected.
This is where the functions subscribe and unsubscribe come into play.
The function subscribe allows you to connect your own function to any in-game event, and unsubscribe allows you to disconnect them.
While a function is subscribed to an in-game event, every time that event occurs that function will run.
So by using subscribe you can connect a function that prints “Screen Clicked” every time a POINTER_PRESS event occurs until you unsubscribe the function from the event.
When you use events, callbacks, subscribe, and unsubscribe you will be able to connect your plugin to actions that are currently occurring in OSRS, opening up a world of possibilities.
This section is for all of the functions, types, and variables related to in-game events. These commands will let you call your own functions whenever a specific in-game event occurs.
So first lets go over what an in-game event is: An in-game event is an action that occurs while playing on the Old School RuneScape client. When someone playing OSRS clicks on the games window with their mouse, that's a pointer press event (which is expressed as POINTER_PRESS in your Lua script).
When a new NPC starts loading into the game world, we would call that a NPC load event (expressed as ON_NPC_LOAD). What if a player decided to press a key on their keyboard? That could be three different events. The down press of the key, the release of the key, or the key identity itself, (expressed as KEY_DOWN, KEY_UP, or KEY_TYPE) depending on what you need for your script. There are many different types of events that can all be utilized when creating your own plugin scripts, and all of them are listed under variables. Each of these has explanations about what they do and how they’re used.
Next we can talk about event callbacks. Each event has a corresponding callback, which can be found under types. These callbacks show you exactly what information you are given for each event, along with code examples on how to use them. Using our example above, where our player pressed a key on their keyboard, let’s decide we used that as a KEY_DOWN event.
Our KEY_DOWN event becomes attached to the KeyDownCallback, so that when the event happens (when the key is pressed by the player), this callback returns the keycode (a number id) of the key that was pressed. When you use events these callbacks happen automatically, and you can use them to apply the extra information they give you.
Now that we have a good understanding on what events and event callbacks are, let's talk about how you can use them. Lets say I want my plugin to print “Screen Clicked” every time a player clicks on the game window. Because a mouse click is pressing the mouse key for the pointer, we know that we should use the POINTER_PRESS event, so we have to decide what we will call this event in our plugin. By giving this our own function name, we can instruct the plugin when to connect it to the game event, in this case clicking on the game screen, and when it should stop being connected. This is where the functions subscribe and unsubscribe come into play. The function subscribe allows you to connect your own function to any in-game event, and unsubscribe allows you to disconnect them. While a function is subscribed to an in-game event, every time that event occurs that function will run. So by using subscribe you can connect a function that prints “Screen Clicked” every time a POINTER_PRESS event occurs until you unsubscribe the function from the event.
When you use events, callbacks, subscribe, and unsubscribe you will be able to connect your plugin to actions that are currently occurring in OSRS, opening up a world of possibilities.