Skip to content

Creating Plugins

Tomm edited this page Apr 29, 2019 · 13 revisions
  • 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

I want to create a Command

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.

  1. 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.
  2. 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 file gg.rsmod.game.plugin.KotlinPlugin.
  3. player is defined automagically (behind-the-scenes) in a way that our KotlinScript file can call it without needing to define it anywhere in the file. We then use Player.inventoryand add the item 391 with an amount of 28. This command will spawn 28 manta rays in your inventory.
  4. player.message will send a message to the player's chatbox.

I want to create a "Timed" Task

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:

  1. 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 the obj (object id) and the option 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.
  2. To use the 'scheduler' we have to wrap the code in Player.queue (gives the ability to use the wait method in this case).
  3. We make our player perform animation 879.
  4. Signal the code to wait for 2 game cycles (a single game cycle is 600 milliseconds).
  5. 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!

I want to create a Dialog

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!")
    }
}
  1. Again, we need player.queue since dialogs require to wait until the player clicks on the 'continue' option in the dialog box.
  2. 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 returns 1.

Each call to one of the dialog methods will wait until the player 'continues' the dialog before the code below it will resume.

Table of Contents

Clone this wiki locally