Jump to content

My first script - help make me better!


Recommended Posts

As the topic says this is my first java script. I have been studying JAVA for a couple weeks and think I am starting to get it. That being said I know there are some really stupid things in my script and my intent is to post it here and you guys and gals can tell me how bad it is and how to improve as a programmer. 


Saying I "wrote" this is fairly generous as I mostly looked at what other people did and made it work for what I wanted to do. I decided not to make a fisher or woodcutter because then I would just be copying some of the fine examples provided by this website, so in order to make sure I was learning not copying here is what this script does:


Goes to "Drogo dwarf", tries to buy Iron ore, if there isn't enough to fill inventory hop to a different world and when full go bank.


A couple of things that I know are done wrong:


The loop to buy the ore. I tried to get it to buy 27 but the docs indicate it wants it in forms of 1,5,or 10. I would think there would be a way to tell it to buy exactly 27, but I can't figure it out.


The other thing I am not happy with is the world hopper. Instead of going to a random f2p world I would rather keep them all in an array and tell it get the current world and then hop to the next, but that is beyond me as well.


This script doesn't make much money, it wasn't the intent, this was to learn. I will say I am having a blast learning and scripting, hopefully I can make some more complicated ones soon.


So here it is, let me know if I am on the right track and what I need to work on please!


(Oh, and I didn't steal this from someone named jubjub, that's another online nick I use!)


edit: Wow those code tags dont format well! Check the spoiler for my script.



package jubjubOreRunner;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "Ore Buyer", author = "jubjub", version = 1, info = "Buys Iron Ore", logo = "")

public class jubjubOreRunner extends Script {

private State state;

Area Shop = new Area(3033, 9847, 3038, 9844);
Area TheBank = new Area (3092, 3494, 3094, 3490);
public int storeAmount;

private enum State{


private State getState(){
if (getInventory().isFull() && TheBank.contains(myPlayer())){
return state.Bank;

if (getInventory().isFull() && !TheBank.contains(myPlayer())){
return state.WalkToBank;


if (!getInventory().isFull() && Shop.contains(myPlayer())){
return state.BuyOre;

if (!getInventory().isFull() && !Shop.contains(myPlayer())){
return state.WalkToOre;

return state.WalkToOre;


public void onStart() {


public int onLoop() throws InterruptedException {
state = getState();

switch (state) {
case Bank:

if (!getBank().isOpen()) {
} else {

case WalkToBank:


case BuyOre:

npcs.closest("Drogo dwarf").interact("Talk-to");
Script.sleep(Script.random(1000, 5000));
Script.sleep(Script.random(1000, 2000));
dialogues.completeDialogue("Do you want to trade?");
Script.sleep(Script.random(1000, 2000));
storeAmount = store.getAmount(440);
int counter = 3;
while (counter > 0){
Script.sleep(Script.random(500, 1500));
counter = counter -1;
if (storeAmount <= 27){
Script.sleep(Script.random(4000, 5500));


case WalkToOre:




return random(150,175);


Edited by sudoinit6
Link to comment
Share on other sites

I'd look into nested if statements like so:

private State getState(){
			if (getInventory().isFull()) {
					return State.Bank;
				else {
					return State.WalkToBank;
			else if(Shop.contains(myPlayer())) {
				return State.BuyOre;			
		        return State.WalkToOre;

Also would look into naming conventions.

Edited by Precise
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...