Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomm0017 committed Mar 21, 2019
1 parent db75dc7 commit cd190ad
Showing 1 changed file with 84 additions and 19 deletions.
103 changes: 84 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,110 @@ and it'll automatically load on the next server startup!
## Configuring The Project
- TODO

## Creating Your First Script
## Creating Your First Plugin

- Creating your first script is super simple! Scripts are written in **KotlinScript**.
Here are the instructions for how you would create a few different scripts.
- Creating your first plugin is super simple! Scripts are written in **KotlinScript**.
Here are the instructions for how you would create a few different plugins.

Before we begin...
-
A plugin must be created in a **KotlinScript** file, notated by the .kts extension.
Plugin files **should always** be defined in lowercase with underscores for separation.
For example if we want to create a food command, we may make a file named ``food_command.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`.
prefixed with `::`. For example `::food`. We would create a file named (including its extension)
``food_command.kts``. It would contain the following code:

package gg.rsmod.plugins.content.test // 1

TODO: add code example for new kotlin script plugins
on_command("food") { // 2
player.inventory.add(391, 28) // 3
player.message("You have spawned some food.") // 4
}

This is a pretty simple script. Let's go over the lines of code that are
labelled
This is a pretty simple plugin. Let's go over the lines of code that are
labelled.

I want to create a Scheduled Task
1. The package in which the file is located. It's 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 ``.kts`` file
can call it without needing to define it anywhere in the file. We then use ``Player.inventory``
and 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 "Scheduled" Task
-
A scheduled task is logic that can take more than a single tick to complete.
Some examples are skills that are continuous, dialogs that wait for input,
or cutscenes.

TODO: add code example for new kotlin script plugins

This script is pretty similar to the last, except we have a new piece of
important code. When you want to create a piece of code that will be
scheduled at a certain point, you want to surround the code with `Plugin.suspendable`
(in this case, `suspendable { ... }`).
package gg.rsmod.plugins.content.test
And that's it! You're on your way to creating all sorts of crazy scripts now.
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``.
3. We make our player perform animation ``879``.
4. The code is then signalled to wait for 2 **game cycles** (a game cycle is 600 milliseconds).
5. After the specified amount of ticks have gone by (in this case, 2 ticks), 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!

And that's it! You're on your way to creating all sorts of crazy plugins now.

I want to create a Dialog
-
Creating a dialog script is similar to that of the `scheduled task` script.
We will use the `npcDialog` functionality in this example, which is targeted
Creating a dialog plugin is similar to that of the `scheduled task` plugin.
We will use the `chatNpc` functionality in this example, which is targeted
for the `OSRS` version of `RS Mod`.

TODO: add code example for new kotlin script plugins
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.
Short and sweet! That's all you need for a basic dialog script.
Short and sweet! That's all you need for a basic dialog plugin.

## FAQ

Expand Down

0 comments on commit cd190ad

Please sign in to comment.