Jump to content
Encoded

An Introduction to Script Development for TRiBot

Recommended Posts

Preface

This tutorial uses Windows 10 and IntelliJ IDEA.

Prerequisites

  • Java knowledge equivalent to someone who has passed a college level introductory Java course with complete understanding of the course.
  • Java Development Kit installed.
  • VIP or VIP-Extended on TRiBot (required to run local scripts).

Advisories

  • Experience with a Java IDE.
  • Experience programming outside of a classroom setting.

Learning Resources

TRiBot Java Documentation

https://tribot.org/doc/

Outline

  • Preface
  • Getting Started
    • IntelliJ IDEA Setup
    • Creating Your First Script
    • Uploading to the TRiBot Script Repository
  • Script Design
    • Task
    • Decision Tree
    • Variables and Constants
  • Development Tools
  • Essential Classes and Methods

Getting Started

IntelliJ Idea Setup

Download and install IntelliJ IDEA community edition from JetBrains.com.

If you have never ran the TRiBot client before, do so now and let it load Old School RuneScape all the way up to the login screen. After doing so, I would recommend restarting the TRiBot client, although this is not required.

Create and Setup the IntelliJ Project

On the IntelliJ welcome screen, select Create New Project
If you already have a project open, then select File -> New -> Project…
Select the Java verison or if none are available, press New... and locate the directory in which Java is installed.

Project SDK

Click Next skipping the project template option and you then should come to a window that allows you to set the project name and location.
Set those to whatever you want and then click Finish

Adding TRiBot.jar to Project Libraries

Select File -> Project Structure and in the window that opens select Libraries
Click the green + and select Java.

Add Java Library

You will now need to locate TRiBot’s dependencies folder.
On a standard windows installation, this folder will be located at C:\Users\REPLACE_WITH_YOUR_WINDOWS_USER\AppData\Roaming\.tribot\dependancies Yes, dependancies is mispelled.

TRiBot.jar Dependency

Once you have navigated to the dependancies folder inside IntelliJ, select TRiBot.jar and press OK

Note: AppData is a hidden folder and will not display in IntelliJ’s file explorer. You will need to type in the path at the top of the window for it to show. Do not press enter after typing the path, the file explorer will automatically refresh as you type.

On the next window you should only have one module. Make sure the module is selected and press OK

Configuring Output Path

If you have closed the Project Structure window, reopen it by selecting File -> Project Structure
Navigate to the Modules tab and make sure your only module is selected.
Select the Paths tab and then select the radio button Use module compile output path
Change both the Output path and Test output path to C:\Users\REPLACE_WITH_YOUR_WINDOWS_USER\AppData\Roaming\.tribot\bin\
Click Apply and then OK

Creating Your First Script

All of your classes will need to be in the package scripts
In your src folder, create the package scripts

scripts package

Inside the scripts package, create a new Java Class named HelloWorld

HelloWorld

Extend Script and implement the method run
Note: Make sure you import org.tribot.script.Script and not sun.font.Script

Add a ScriptManifest which will provide the TRiBot client information about your script so it can be properly categorized in the script selector.
@ScriptManifest(authors = "Encoded", name = "Hello World", category = "Script Tutorial")

Add println("Hello World"); inside the run method and the basic script skeleton is complete.
println prints to the Client Debug at the bottom of the TRiBot client. This method is inhereted from Script, but an equivalent method can be found in the General class.

Build your project (Build -> Build Project) and then press Start Script in the TRiBot client.
If your script does not show up in the script selector, then you have done something incorrect or you do not have VIP.

HelloWorld.java

package scripts;

import org.tribot.script.Script;
import org.tribot.script.ScriptManifest;

@ScriptManifest(authors = "Encoded", name = "Hello World", category = "Script Tutorial")
public class HelloWorld extends Script {

    @Override
    public void run() {
        println("Hello World");
    }
}

 

Creating Additional Modules

When developing a script that is more than one class file, creating a specific module for that script is highly recommended.
For each additional module, you will need to change the output path like you did above and add the TRiBot.jar library as a module dependency.

Removing RS3 Auto Imports

IntelliJ IDEA will auto import for you. This can lead to unwanted behavior such as importing RS3 classes when you wanted OSRS.
To fix this, go to File -> Settings... -> Editor -> General -> Auto Import
In the Exclude from Import and Completion table, add obforg.tribot.api.rs3, and sun.font.Script

Auto Import

Uploading to the TRiBot Script Repository

To upload to the TRiBot Script Repository, you will need to create a .zip file with your script’s java source files.
The zip file acts as your scripts package.
You will need to keep the same package structure you’re using in IntelliJ. If you have the package scripts.agility you will need to have the agility folder inside in the zip.
As an example using HelloWorld.java from above, create a zip file named HelloWorld.zip and place HelloWorld.javainside.
HelloWorld.zip is now ready to be uploaded to the repository, but please do not upload it in attempt to keep the repository clean of unwanted scripts.

Note: Do not place your compiled class files inside the zip file, only java source files.

Script Design

Two of the most common script design patterns will be covered:

  • Task
  • Decision Tree

Task

The task design pattern consists of a collection of tasks that have a validation and execution method. 
The collection is then iterated over and if a task’s validation method returns true, then the task is executed.
Tasks are typically stored in a Set or a List.
Here is a short tutorial for the Task Framework.

Decision Tree

The decision tree design pattern consists of a manually created decision tree that is traversed using a modified preorder depth-first search until a valid runnable node is found.
Here is a tutorial for the Decision Tree Framework.

Variables and Constants

Variables

To manage variables, I use a Vars class. The Vars class will be a singleton. A singleton is not needed, however, when managing a shared resource such as variables, a singleton is preferred. To access a variable, you will call Vars.get().variableName
Note: There might be more proper ways to manage variables, but this has proved to be the most effective for me.
Vars.java

public class Vars {

    private static final Vars instance = new Vars();

    public int variableName;

    public static Vars get() {
        return instance;
    }

    private Vars() {

    }
}

 

Constants

To store constants, I use a final Constants class. This allows you to static import constants so there is no need to have to reference the class and then the constant.
Note: The Constants class is not a substitution for enums. You should be using enums wherever possible.
Constants.java

public final class Constants {

    public static final int EXAMPLE_CONSTANT = 1;

    private Constants() {

    }
}

 

Development Tools

  • TRiBot Debug Options
    • All options listed under the Debug tab in the TRiBot client.
  • Interface Explorer
    • At the top of the TRiBot client, navigate to Tools -> Interface Explorer
  • LAN ScriptTools
    • Contains various tools to aid in script development.
  • Area Creator and VarBit Explorer
    • These tools will either need to be developed yourself or can potentially be found on the TRiBot forums.
  • Java VisualVM
    • Used to monitor CPU and memory usage. Can be found within the JDK installation directory.

Essential Classes and Methods

  • RSArea
    • Should always be used to check if a location is within a area.
  • Clicking
    • Should be used for all clicking that involves an entity to stay consistent.
  • Timing.waitCondition(Condition c, long timeout)
    • Should always be used where applicable.
Edited by Encoded
  • Like 4
  • Thanks 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Our picks

    • This release will:

      Add LG support for Runelite


      Fix NPCChat issues


      Fix a bug where the camera angle setter would just hold down a key for 5 seconds (the timeout)


      Slightly adjust the rotation via keys to be more accurate


      Add the ability for asynchronous camera movement via keys


      Make Camera rotation via mouse more fluid, with more antiban, and work much better in resizable mode


      Add a "Camera#setCamera" method, allowing the rotation and angle to be set in parallel


      Increase the likelihood of using the mouse for camera movements


      Add support for adjusting the camera to positionable entities (Positionable#adjustCameraTo)



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Thanks
        • Like
      • 36 replies
    • This update will:

      Allow for clicking through the chat box when possible (Thanks @Todd)


      Fix Combat#selectIndex (Thanks @Encoded)


      Ensure worlds stay sorted and added a check to avoid misclicks in the in-game world hopper (Thanks @erickho123)


      Fix out-dated Options API interface indices (Thanks @Todd)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Like
      • 12 replies
    • This release will:

      Fix login bot after today's game update (Thanks @JoeDezzy1)


      Fix latest in-game world hopping issues (Thanks @erickho123)


      Compact Settings UI and set location relative to TRiBot (Thanks @JoeDezzy1)


      Fix an older implementation of GrandExchange#getWindowState (Thanks @JoeDezzy1)


      Improve the preformance of NPCChat by only searching in certain interface parents (Thanks @JoeDezzy1)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      LG support for RuneLite


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Thanks
        • Like
      • 16 replies
    • This release will:

      Fix bytecode manipulation in order to prevent the modification of parameters within the Filter and Condition classes themselves (thanks @wastedbro)


      Fix NPE caused by non-null value in GE API (thanks @erickho123)


      Add and fix equals methods for api2007.types (thanks @JoeDezzy1)


      Modify Mouse#leaveGame to make the mouse leave the game from top, left, right, or bottom (thanks @erickho123)


      Add Entrana area to Ships API (thanks @erickho123)


      Fix raid prayers index/settings in Prayer API (thanks @erickho123)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Like
      • 29 replies
    • This update will:

      Implement better canvas locking/synchronization mechanism


      Fix small Login API bug


      Remove the requirement for xbooting Java classes


      Use ExecutorService to perform canvas work in parallel


      Add "Account Management" game tab to GameTab API (thanks @Encoded)


      Fix NPCChat#getMessage (thanks @Encoded )


      Fix NPCChat#selectOption (thanks @Encoded )


      Fix Banking API after today's update (thanks @Encoded )


      Fix in-game world hopper after today's update (thanks @Encoded )



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Thanks
        • Like
      • 38 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×