-
Notifications
You must be signed in to change notification settings - Fork 101
Creating Plugins
- Plugins must be created in KotlinScript files, notated by the
.plugin.kts
extension. - Plugin files should always be defined in lowercase with underscores for separation. For example if we want to create a slayer shop plugin, we may make a file named
slayer_shop.plugin.kts
A command is an input received when a player types something in their chatbox, prefixed with ::
. For example ::food
. We would create a file named (including its extension) food_command.plugin.kts
. It would contain the following code:
package gg.rsmod.plugins.content.test // 1
on_command("food") { // 2
player.inventory.add(391, 28) // 3
player.message("You have spawned some food.") // 4
}
This is a pretty simple plugin. Let's go over the lines of code that are labeled.
- The package in which the file is located. It is valid to not include a package, however if any other plugin uses the same name and doesn't specify a package in a similar fashion, there will be conflicting issues, which is why it's good to define the package.
- There are loads of
on_xxx
methods which you can use to define what your plugin does under certain circumstances. These methods can be found in the filegg.rsmod.game.plugin.KotlinPlugin
. -
player
is defined automagically (behind-the-scenes) in a way that ourKotlinScript
file can call it without needing to define it anywhere in the file. We then usePlayer.inventory
and add the item391
with an amount of28
. This command will spawn 28 manta rays in your inventory. -
player.message
will send a message to the player's chatbox.
A "timed" task is logic that can take more than a single game-cycle to complete. Some examples are skills that are continuous, dialogs that wait for input, or cutscenes.
package gg.rsmod.plugins.content.test
on_obj_option(obj = 1278, option = "cut") { // 1
player.queue { // 2
player.animate(879) // 3
player.message("You swing your axe at the tree.")
wait(2) // 4
player.animate(-1) // 5
player.message("You get some logs.")
}
}
This plugin is a bit more tedious to understand, but it's mostly just because you'll need some time to learn the method names for certain features. Let's go over the labeled code:
- This is another one of those
on_xxx
methods which we spoke of on the last example. This one specifically is to give an action when a player clicks on an object. We specify theobj
(object id) and theoption
which automagically binds our action to said option. If the option is not found on the object, it will throw an error when you start the server. - To use the 'scheduler' we have to wrap the code in
Player.queue
(gives the ability to use thewait
method in this case). - We make our player perform animation
879
. - Signal the code to wait for 2 game cycles (a single game cycle is 600 milliseconds).
- After the specified amount of cycles have gone by (in this case, 2 cycles), the rest of the code is executed, this includes
player.animate(-1)
which will reset the player's animation since they have already chopped down the logs!
Creating a dialog plugin is similar to that of the timed task
plugin. We will use the chatNpc
functionality in this example.
package gg.rsmod.plugins.content.test
on_npc_option(npc = 401, option = "talk-to") {
player.queue { // 1
chatNpc("Hello, adventurer.") // 2
chatPlayer("Good day, Turael!")
}
}
- Again, we need
player.queue
since dialogs require to wait until the player clicks on the 'continue' option in the dialog box. - There's several dialog methods we can use, these are some of them:
chatNpc(String message)
chatPlayer(String message)
-
messageBox(String message)
an empty dialog box with a message -
itemMessageBox(String message, Int itemId)
a dialog that shows an item next to it -
options(String... options)
returns an Int in respect to the option the player chooses from this dialog. If a player clicks on the first option, this method returns1
.
Each call to one of the dialog methods will wait until the player 'continues' the dialog before the code below it will resume.
Join the Discord if you have any questions or want to chat with the community
- User Guide