Starting off a script
What is a script
A script is code that runs on top of the Inubot client that manipulates the actual game using our SDK. The Inubot client provides hooks into the game and API functions which you can leverage to write code that can interface with the game.
Basic script structure
A Script at it's lowest level is just a loop that's called on repeat. The return value is the milliseconds of which to sleep after each call.
@ScriptMeta(name = "My Script", developer = "Doga", version = 1.0, desc = "My first script!")
public class MyScript extends Script {
@Override
public int loop() {
return 300;
}
}
The script loop is executed until the script is stopped. This can either be done by the user, or programatically by returning -1
. The ScriptMeta annotation is a requirement for all scripts. It contains meta data that is used to display the script in the script selector, so you should fill in the fields accordingly. This should always go above your main script class declaration.
TaskScript
The looping script model is the lowest level of script, but for the sake of this tutorial and good practices, we will be covering TaskScript specifically. The main difference with TaskScript
is that it is broken into Task's rather than a single loop, while at the same time being synchronized with the game tick. The game tick is the core at which RuneScape operates and as such, we should be building our scripts around that!
@ScriptMeta(name = "My Script", developer = "Doga", version = 1.0, desc = "My first script!")
public class MyScript extends TaskScript {
@Override
public void initialize() {
Log.info("Starting script!");
}
@Override
public void shutdown() {
Log.info("Stopping script!");
}
@Override
public Class<? extends Task>[] tasks() {
return ArrayUtils.getTypeSafeArray(
);
}
}
In a TaskScript
, the initialize()
and shutdown()
methods are optional. You don't need them, but they do exist and are called on script start and end, so if you have a use for them, feel free to implement them! The tasks()
method is required, this is where you list tasks that your script should execute.
Task
We will now be covering Task
and how to implement them.
@TaskDescriptor(name = "Task 1")
public class MyTask1 extends Task {
@Override
public boolean execute() {
return true;
}
}
Above is the simplest possible Task you can have. Firstly, each Task requires a TaskDescriptor. The TaskDescriptor
provides 2 things. First is meta data, such as the name of the task. This is used in debug information. Next is how the task should be executed.
Looking at the Javadocs, you'll see multiple possible attributes that you can define.
priority()
is a value defining the priority of execution for this task. A higher priority means that the task will be executed first. If priorities are the same/undefined, then the execution order is simply the order you add the tasks in thetasks()
method.blocking()
is a boolean indicating if further execution of tasks should continue. If a blocking task is ran and theexecute()
method also returned true, then no further tasks will be executed in that tick.blockIfSleeping()
works together withblocking()
. By default, if a blocking task sleeps, it won't continue to block other tasks. Using this property changes that.register()
simply registers the task to the event registry, so that it can receive events such asChatMessageEvent
.stoppable()
should be used if you want the task to stop the script. If a stoppable tasksexecute()
returns true, the script will be stopped.executeWhilePaused()
is something you should use if you want the task to continue executing even if the user pauses the script. This can be useful when users are recording mouse data. For example, we can't expect users to perfectly handle boss mechanics, so we can at least give them a little hand!