Write your own Sketchy scripts
Sketchy scripts are written in Java with the Sketchy API. This guide takes you from an empty folder to a working woodcutter, with the code and what you should see at every step. Every class name links to the Java docs.
org.sketchy.api.1. What you need
- Sketchy, started once (it installs itself in
C:\Users\<you>\Sketchy). - A Java JDK, version 11 or newer, to compile: Eclipse Temurin is free. Check it in a terminal with
javac -version. - A text editor or an IDE. IntelliJ IDEA Community or VS Code work well.
- The Sketchy API jar: you already have it. After the first start it is here:
Add it as a library in your IDE to get auto-completion.C:\Users\<you>\Sketchy\home\.runelite\sideloaded-plugins\SketchyBridge.jar
--release 11): the game client runs on Java 11. Don't use newer Java features such as record.2. Your first script
A script is a class that extends AbstractScript and carries a @ScriptManifest. Sketchy calls onStart() once, then onLoop() again and again: the number it returns is how long to wait, in milliseconds, before the next loop.
Create a folder HelloSketchy with this file HelloSketchy.java:
import org.sketchy.api.methods.interactive.Players;
import org.sketchy.api.script.AbstractScript;
import org.sketchy.api.script.Category;
import org.sketchy.api.script.ScriptManifest;
import org.sketchy.api.utilities.Logger;
import org.sketchy.api.wrappers.interactive.Player;
@ScriptManifest(name = "Hello Sketchy", author = "You", version = 1.0,
category = Category.MISC, description = "My first Sketchy script")
public class HelloSketchy extends AbstractScript {
private int loops;
@Override
public void onStart() {
Logger.log("Hello from my first script!");
}
@Override
public int onLoop() {
Player me = Players.getLocal();
Logger.log("Loop " + (++loops) + ": I am " + me.getName() + " at " + me.getTile());
if (loops == 3) {
stop(); // ends the script after three loops
}
return 1000; // wait 1 second before the next loop
}
@Override
public void onExit() {
Logger.log("Bye!");
}
}
3. Build and install
Open a terminal (Command Prompt) in the HelloSketchy folder and run:
set API=%USERPROFILE%\Sketchy\home\.runelite\sideloaded-plugins\SketchyBridge.jar
javac --release 11 -cp "%API%" -d out HelloSketchy.java
jar --create --file HelloSketchy.jar -C out .
copy HelloSketchy.jar "%USERPROFILE%\Sketchy\Scripts\"
Result
1 file(s) copied.
Your script is now Sketchy\Scripts\HelloSketchy.jar. To update it later, run the same commands again: you can even do it while Sketchy is open.
4. Run it
- Start Sketchy and log in to the game.
- In Sketchy's bar, click the Script manager button: Hello Sketchy is in the list, with the name, author and description of its
@ScriptManifest. - Select it and start it, then open the Script console (the console button in the bar).
Result in the script console
--- starting HelloSketchy.jar (HelloSketchy, Sketchy API) ---
Hello from my first script!
Loop 1: I am Zezima at Tile(3222, 3218, 0)
Loop 2: I am Zezima at Tile(3222, 3218, 0)
Loop 3: I am Zezima at Tile(3222, 3218, 0)
Bye!
--- the script requested a stop ---
Your name and position will be yours, of course. After a rebuild, the Restart button starts the last script again.
5. How a script runs
| Method | When | Use it to |
|---|---|---|
onStart() | once, at start | read settings, remember start XP, log a hello |
onLoop() | again and again | do one small step, then return the delay in ms |
onPaint(Graphics g) | every frame | draw your info over the game |
onExit() | once, at the end | save, log a summary |
Keep each onLoop() short: look at the game, do one action, return. The next loop looks again. Call stop() to end the script; returning a negative number also stops it.
6. Find and use things
Objects, NPCs and items on the floor are found with GameObjects, NPCs and GroundItems. closest(...) takes names, ids or a filter, and returns null when there is none: always check it. Then interact("Action") clicks the action of its right-click menu.
import org.sketchy.api.methods.container.impl.Inventory;
import org.sketchy.api.methods.interactive.GameObjects;
import org.sketchy.api.methods.interactive.Players;
import org.sketchy.api.script.AbstractScript;
import org.sketchy.api.script.Category;
import org.sketchy.api.script.ScriptManifest;
import org.sketchy.api.utilities.Logger;
import org.sketchy.api.utilities.Sleep;
import org.sketchy.api.wrappers.interactive.GameObject;
@ScriptManifest(name = "Tree Chopper", author = "You", version = 1.0,
category = Category.WOODCUTTING, description = "Chops the nearest tree, drops nothing")
public class TreeChopper extends AbstractScript {
@Override
public int onLoop() {
if (Inventory.isFull()) {
Logger.log("Inventory full: " + Inventory.count("Logs") + " logs. Stopping.");
stop();
return 0;
}
if (Players.getLocal().isAnimating()) {
return 600; // already chopping
}
GameObject tree = GameObjects.closest("Tree");
if (tree == null) {
Logger.log("No tree nearby, waiting...");
return 1200;
}
if (tree.interact("Chop down")) {
Logger.log("Chopping the tree at " + tree.getTile());
// wait until the chopping animation starts (at most 4 seconds)
Sleep.sleepUntil(() -> Players.getLocal().isAnimating(), 4000);
}
return 600;
}
}
Result
--- starting TreeChopper.jar (TreeChopper, Sketchy API) ---
Chopping the tree at Tile(3161, 3454, 0)
Chopping the tree at Tile(3165, 3451, 0)
...
Inventory full: 27 logs. Stopping.
--- the script requested a stop ---
7. Wait the right way
A click takes time to have an effect. Instead of sleeping a fixed time, wait for what you expect with Sleep.sleepUntil(condition, timeout): it returns as soon as the condition is true, or after the timeout.
if (tree.interact("Chop down")) {
Sleep.sleepUntil(() -> Players.getLocal().isAnimating(), 4000); // chopping started
}
if (Bank.open()) {
Sleep.sleepUntil(Bank::isOpen, 5000); // bank window shown
}
8. A complete woodcutter
It chops trees in an area, walks to the nearest bank when the inventory is full, deposits everything except the axe, comes back, and draws its progress over the game. It uses Area, Walking, Bank, Inventory and Skills.
import org.sketchy.api.methods.container.impl.Inventory;
import org.sketchy.api.methods.container.impl.bank.Bank;
import org.sketchy.api.methods.interactive.GameObjects;
import org.sketchy.api.methods.interactive.Players;
import org.sketchy.api.methods.map.Area;
import org.sketchy.api.methods.skills.Skill;
import org.sketchy.api.methods.skills.Skills;
import org.sketchy.api.methods.walking.impl.Walking;
import org.sketchy.api.script.AbstractScript;
import org.sketchy.api.script.Category;
import org.sketchy.api.script.ScriptManifest;
import org.sketchy.api.utilities.Logger;
import org.sketchy.api.utilities.Sleep;
import org.sketchy.api.wrappers.interactive.GameObject;
import java.awt.Color;
import java.awt.Graphics;
@ScriptManifest(name = "Woodcutter", author = "You", version = 1.0,
category = Category.WOODCUTTING, description = "Chops trees, banks the logs, comes back")
public class Woodcutter extends AbstractScript {
// South-west and north-east corners of the trees area (find them with any OSRS map tool)
private static final Area TREES = new Area(3157, 3449, 3171, 3461);
private static final String AXE = "Bronze axe";
private int startXp;
private int banked;
private long startTime;
@Override
public void onStart() {
startXp = Skills.getExperience(Skill.WOODCUTTING);
startTime = System.currentTimeMillis();
Logger.log("Woodcutting level " + Skills.getRealLevel(Skill.WOODCUTTING));
}
@Override
public int onLoop() {
if (Inventory.isFull()) {
return bank();
}
if (!TREES.contains(Players.getLocal())) {
Walking.walk(TREES.getRandomTile());
return 800;
}
return chop();
}
private int chop() {
if (Players.getLocal().isAnimating()) {
return 600;
}
GameObject tree = GameObjects.closest(o -> o != null && "Tree".equals(o.getName()) && TREES.contains(o));
if (tree != null && tree.interact("Chop down")) {
Sleep.sleepUntil(() -> Players.getLocal().isAnimating(), 4000);
}
return 600;
}
private int bank() {
if (!Bank.isOpen()) {
Bank.open(); // walks to the nearest bank and opens it
return 800;
}
int logs = Inventory.count("Logs");
if (Bank.depositAllExcept(AXE)) {
Sleep.sleepUntil(() -> !Inventory.isFull(), 3000);
banked += logs;
Logger.log("Banked " + logs + " logs (" + banked + " in total)");
}
Bank.close();
return 600;
}
@Override
public void onPaint(Graphics g) {
long minutes = Math.max(1, (System.currentTimeMillis() - startTime) / 60000);
int gained = Skills.getExperience(Skill.WOODCUTTING) - startXp;
g.setColor(new Color(0, 0, 0, 150));
g.fillRect(8, 30, 190, 58);
g.setColor(Color.WHITE);
g.drawString("Woodcutter", 16, 46);
g.drawString("Logs banked: " + banked, 16, 62);
g.drawString("XP gained: " + gained + " (" + (gained * 60 / minutes) + "/h)", 16, 78);
}
}
Result in the console
--- starting Woodcutter.jar (Woodcutter, Sketchy API) ---
Woodcutting level 15
Banked 27 logs (27 in total)
Banked 27 logs (54 in total)
...
Result over the game (onPaint)
Logs banked: 54
XP gained: 1350 (5400/h)
The area above is near the Grand Exchange: change the coordinates to your own trees. An OSRS map tool shows the coordinates of any tile.
9. Bigger scripts: tasks
When onLoop() grows, split the script into tasks. A TaskScript runs, at every loop, the first TaskNode whose accept() is true, the highest priority() first. The same woodcutter:
import org.sketchy.api.methods.container.impl.Inventory;
import org.sketchy.api.methods.container.impl.bank.Bank;
import org.sketchy.api.methods.interactive.GameObjects;
import org.sketchy.api.methods.interactive.Players;
import org.sketchy.api.script.Category;
import org.sketchy.api.script.ScriptManifest;
import org.sketchy.api.script.TaskNode;
import org.sketchy.api.script.impl.TaskScript;
import org.sketchy.api.utilities.Sleep;
import org.sketchy.api.wrappers.interactive.GameObject;
@ScriptManifest(name = "Task Woodcutter", author = "You", version = 1.0,
category = Category.WOODCUTTING, description = "The woodcutter, split into tasks")
public class TaskWoodcutter extends TaskScript {
@Override
public void onStart() {
addNodes(new BankTask(), new ChopTask());
}
/** Runs first when the inventory is full (higher priority). */
static class BankTask extends TaskNode {
@Override public int priority() { return 10; }
@Override public boolean accept() { return Inventory.isFull(); }
@Override public int execute() {
if (!Bank.isOpen()) {
Bank.open();
return 800;
}
Bank.depositAllExcept("Bronze axe");
Sleep.sleepUntil(() -> !Inventory.isFull(), 3000);
Bank.close();
return 600;
}
}
/** Runs otherwise. */
static class ChopTask extends TaskNode {
@Override public boolean accept() { return !Inventory.isFull() && !Players.getLocal().isAnimating(); }
@Override public int execute() {
GameObject tree = GameObjects.closest("Tree");
if (tree != null && tree.interact("Chop down")) {
Sleep.sleepUntil(() -> Players.getLocal().isAnimating(), 4000);
}
return 600;
}
}
}
For very large scripts, TreeScript organises the work as branches and leaves.
10. Events and saved settings
Implement a listener on your script class and Sketchy calls it when something happens: ChatListener for chat messages, and others in script.listener (inventory, experience, game ticks...). ScriptSettings saves any object as JSON, so your script remembers things between runs.
import org.sketchy.api.script.AbstractScript;
import org.sketchy.api.script.Category;
import org.sketchy.api.script.ScriptManifest;
import org.sketchy.api.script.listener.ChatListener;
import org.sketchy.api.settings.ScriptSettings;
import org.sketchy.api.utilities.Logger;
import org.sketchy.api.wrappers.widgets.message.Message;
@ScriptManifest(name = "Log Counter", author = "You", version = 1.0,
category = Category.MISC, description = "Counts logs from game messages and remembers the total")
public class LogCounter extends AbstractScript implements ChatListener {
/** Saved as JSON in Sketchy\Scripts\LogCounter\stats.json */
public static class Stats {
public int totalLogs;
}
private static final String[] FILE = {"LogCounter", "stats"};
private Stats stats;
@Override
public void onStart() {
stats = (Stats) ScriptSettings.load(Stats.class, FILE);
if (stats == null) {
stats = new Stats();
}
Logger.log("Logs counted so far: " + stats.totalLogs);
}
@Override
public void onGameMessage(Message message) {
if (message.getMessage().contains("You get some logs")) {
stats.totalLogs++;
Logger.log("Log #" + stats.totalLogs);
}
}
@Override
public int onLoop() {
return 1000; // nothing to do: the work happens in onGameMessage
}
@Override
public void onExit() {
ScriptSettings.save(stats, FILE);
Logger.log("Saved: " + stats.totalLogs + " logs in total");
}
}
Result (second run)
--- starting LogCounter.jar (LogCounter, Sketchy API) ---
Logs counted so far: 27
Log #28
Log #29
Saved: 29 logs in total
The file is Sketchy\Scripts\LogCounter\stats.json (or in DreamBot\Scripts if DreamBot is installed on the computer).
11. Where to find things
| To... | Use |
|---|---|
| know about your character | Players.getLocal(): name, tile, isAnimating(), isMoving(), isInCombat() |
| find NPCs, objects, floor items | NPCs, GameObjects, GroundItems |
| inventory, bank, equipment | Inventory, Bank, Equipment |
| move around | Walking, Tile, Area |
| skills and XP | Skills, Skill |
| talk to NPCs | Dialogues |
| buy and sell | GrandExchange |
| fight | Combat |
| wait and log | Sleep, Logger |
| keyboard and mouse | Keyboard, Mouse |
Everything else: all classes · every method, A to Z.
12. Troubleshooting
| Problem | Fix |
|---|---|
javac is not recognised | Install a JDK (not only a JRE) and open a new terminal. |
error: cannot find symbol | A typo, a missing import, or -cp does not point to SketchyBridge.jar. |
class file has wrong version | You forgot --release 11. |
| The script is not in the Script manager | The class needs @ScriptManifest and must extend AbstractScript; the jar must be in Sketchy\Scripts. |
| Nothing happens in the game | Add Logger.log(...) lines: a closest(...) probably returned null. |
| The script clicks again and again | Wait for the result of each action with Sleep.sleepUntil. |
--- stopped on error in onLoop --- | The line after it says what failed (often a NullPointerException: check for null). |
Still stuck? Ask in #help on the Sketchy Discord.
