Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Three Scripts I Wrote This Afternoon Fisher,Feather_Collecter/Chicken_Killer, Stunner

Featured Replies

Haven't played Runescape in years, logged on briefly thought I'd write a few scripts for the hell of it. Posting this mostly just to help anyone who is new at java or programming in general. All of these scripts are extremely basic and should only be used as a reference; use them at your own risk.

I didn't see many open source code scripts posted, reading other people's code and editing it to do what you want is the only way to learn coding, especially at a beginner level. Any questions feel free to ask.

 

Fisher

import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(name = "Ted_Fisher", author = "Ted", version = 0, info = "", logo = "") 

public class main extends Script {
	
//***************************************************************************************************************************    
	private long startTime;
	private int troutCaught;
	private int salmonCaught;
	
	@[member='Override']
    public void onStart() {//Code here will execute before the loop is started 
		startTime = System.currentTimeMillis();
		troutCaught = 0;
		salmonCaught = 0;
		getExperienceTracker().start(Skill.FISHING);
    }
//***************************************************************************************************************************	
    @[member='Override']
    public void onExit() {
    	long runTime = System.currentTimeMillis() - startTime;
    	log("You caught - " + troutCaught + " trout.");
    	log("You caught - " + salmonCaught + " salmon.");
    	log("The script ran for" + formatTime(runTime) + ".");
    	log("You gained " + getExperienceTracker().getGainedLevels(Skill.FISHING) + " fishing levels.");
    	log("You gained " + getExperienceTracker().getGainedXP(Skill.FISHING) + " fishing experience.");
    }
//*************************************************************************************************************************	
	private enum State {//Fishing States
		FISH, DROP, WAIT, BANKING, WALK_TO_BANK, WALK_TO_FISHING_SPOT, STOP
	}
//***************************************************************************************************************************
	private State getState(){
		if(!neededSuppliesInInventory())//if correct supplies are in inventory continues
			return State.STOP;
		if(!inventory.isFull() && !myPlayer().isAnimating())//if inventory isn't full and player isnt animating it fishes
			return State.FISH;
		if(inventory.isFull())//if inventory is full drops
			return State.DROP;
		return State.WAIT;//if none are true waits
	}
//***************************************************************************************************************************

//***************************************************************************************************************************
    @[member='Override']
    public int onLoop() throws InterruptedException {
    	switch (getState()) {
		case FISH:
			fish();
			break;
		case DROP:
			drop();
			break;
		case WAIT:
			log("waiting");
			sleep(random(500, 700));
			break;
		case STOP:
			this.stop();//exits script
		}
		return random(200, 300);
	}//The amount of time in milliseconds before the loop starts over
//***************************************************************************************************************************
    public void fish(){//fishes 
		NPC closestFishingSpot = getNpcs().closest("Fishing spot");
		closestFishingSpot.interact("Lure");
		log("fishing");
    }
//***************************************************************************************************************************
    public void drop(){//drops all items except fly fishing rod and feathers
    	inventory.dropAllExcept("Fly fishing rod","Feather");
    	log("dropping");
    }
//***************************************************************************************************************************
    public boolean neededSuppliesInInventory(){
    	return inventory.contains("Feather") && inventory.contains("Fly Fishing Rod"); 	
    }
//***************************************************************************************************************************
    @[member='Override']
    public void onPaint(Graphics2D g) {
    	long runTime = System.currentTimeMillis() - startTime;
    
    	Font font = new Font("Open Sans", Font.BOLD, 18);
    	g.setFont(font);
    	
    	g.drawString("Run Time - " + formatTime(runTime), 10, 220);
    	g.drawString("Experience Gained - " + getExperienceTracker().getGainedXP(Skill.FISHING),300,220);
    	
    	g.drawString("Current Fishing Level - " + getSkills().getStatic(Skill.FISHING), 10, 240);
    	g.drawString("Fishing Levels Gained - " + getExperienceTracker().getGainedLevels(Skill.FISHING), 300, 240);
    	
    	g.drawString("EXP Until Level - " + getSkills().experienceToLevel(Skill.FISHING), 10, 260);
    	g.drawString("EXP Per Hour - " + getExperienceTracker().getGainedXPPerHour(Skill.FISHING), 300, 260);
    	
    	g.drawString("Time Until Next Level - " + formatTime(getExperienceTracker().getTimeToLevel(Skill.FISHING)), 10, 280);
    	g.drawString("Current State - " + getState(), 300, 280);
    	
    	g.drawString("Salmon Caught - " + salmonCaught, 10, 300);
    	g.drawString("Trout Caught - " + troutCaught, 300, 300);
    }
//***************************************************************************************************************************    
    public void onMessage(Message message) throws java.lang.InterruptedException {
		String txt = message.getMessage().toLowerCase();
		if (txt.contains("trout"))
			troutCaught++;
		if (txt.contains("salmon"))
			salmonCaught++;
	}
//**************************************************************************************************************************
    public final String formatTime(final long ms){//converts milliseconds to hh:mm:ss will leave out hh and mm if its is 0
        long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
        s %= 60; m %= 60; h %= 24;

        return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) :
               h > 0 ? String.format("%02d:%02d:%02d", h, m, s) :
               String.format("%02d:%02d", m, s);
    }
//***************************************************************************************************************************
}

Chicken Killer

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(name = "Ted_Chicken_Killer", author = "Ted", version = 0, info = "", logo = "") 

public class main extends Script {
//***************************************************************************************************************************    
	private long startTime;
	private long feathersInInventoryAtStart;//for the paint to determine how many we collected. It is a long becauswe the getAmout() method is returns a long
	private int chickensKilled;

	@[member='Override']
    public void onStart() {//Code here will execute before the loop is started 
		startTime = System.currentTimeMillis();
		feathersInInventoryAtStart = this.inventory.getAmount("Feather");
        chickensKilled = 0;
        getExperienceTracker().start(Skill.ATTACK);
        getExperienceTracker().start(Skill.STRENGTH);
        getExperienceTracker().start(Skill.DEFENCE);
        getExperienceTracker().start(Skill.HITPOINTS);
		log("Script started");
    }
//***************************************************************************************************************************	
    @[member='Override']
    public void onExit() {
    	log("Script ended");
    	
    }
//*************************************************************************************************************************	
	private enum State {//Fishing States
		FIGHT, WAIT, COLLECT,STOP
	}
//***************************************************************************************************************************
	private State getState(){
		if(myPlayer().isAnimating() ||  myPlayer().isMoving() || myPlayer().isUnderAttack())//If my player is doing something, or isnt moving and isnt
			return State.WAIT;
		if(feathersAreReachable() && !myPlayer().isUnderAttack())
			return State.COLLECT;//if feathers are present will collect them
		return State.FIGHT;//if none are true FIGHTS
	}
//***************************************************************************************************************************

//***************************************************************************************************************************
    @[member='Override']
    public int onLoop() throws InterruptedException {
    	switch (getState()) {
		case FIGHT:
			attack();
			break;
		case COLLECT:
			collect();
			break;
		case WAIT:
			log("waiting");
			sleep(random(500, 700));
			break;
		case STOP:
			this.stop();//exits script
		}
		return random(200, 300);
	}//The amount of time in milliseconds before the loop starts over

//***************************************************************************************************************************
    public boolean feathersAreReachable(){
    GroundItem feather = groundItems.closest("Feather");
     return feather != null && feather.exists() && map.canReach(feather);
    }
//**************************************************************************************************************************
    
//***************************************************************************************************************************
    public void attack(){//attacks chickens
    	NPC closestChicken = getNpcs().closest("Chicken");
		if(closestChicken.isAttackable())//if your player can attack chicken attacks it
    	closestChicken.interact("Attack");
		log("Fighting Chicken");
    }
//***************************************************************************************************************************
    public void collect(){
    	GroundItem closestFeather = getGroundItems().closest("Feather");
    	closestFeather.interact("Take");
    	log("Collecting Feathers");
    }
//**************************************************************************************************************************
    @[member='Override']
    public void onPaint(Graphics2D g) {
    	long runTime = System.currentTimeMillis() - startTime;
    	long feathersCollected = this.inventory.getAmount("Feather") - feathersInInventoryAtStart;

    	Font font = new Font("Open Sans", Font.BOLD, 18);
    	g.setFont(font);
    	
    	//g.setColor(Color.decode("47FF11"));//Sets paintbrush to lime green
    	
    	g.drawString("Run Time - " + formatTime(runTime), 200, 220);
    	
    	g.drawString("Feathers Collected - " + feathersCollected, 10, 240);
    	g.drawString("Chickens Killed - " + feathersCollected, 310, 240);
    	
    	g.drawString("Attack Levels Gained - " + getExperienceTracker().getGainedLevels(Skill.ATTACK), 10, 260);
    	g.drawString("Strength Levels Gained - " + getExperienceTracker().getGainedLevels(Skill.STRENGTH), 310, 260);
    	
    	g.drawString("Defense Levels Gained - " + getExperienceTracker().getGainedLevels(Skill.DEFENCE), 10, 280);
    	g.drawString("Hitpoints Levels Gained - " + getExperienceTracker().getGainedLevels(Skill.HITPOINTS), 310, 280);
    	
    	g.drawString("Current State - " + getState(), 200, 300);
    }
//***************************************************************************************************************************
    public final String formatTime(final long ms){//converts milliseconds to hh:mm:ss will leave out hh and mm if its is 0
        long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
        s %= 60; m %= 60; h %= 24;

        return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) :
               h > 0 ? String.format("%02d:%02d:%02d", h, m, s) :
               String.format("%02d:%02d", m, s);
    }
//***************************************************************************************************************************    
}

Stunner

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.Spells;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(name = "Ted_Stunner", author = "Ted", version = 0, info = "", logo = "") 

public class main extends Script {
//***************************************************************************************************************************    
	private long startTime;
	private long numSplashes;//for the paint to determine how many we collected. It is a long becauswe the getAmout() method is returns a long

	@[member='Override']
    public void onStart() {//Code here will execute before the loop is started 
		startTime = System.currentTimeMillis();
		numSplashes = 0;
        getExperienceTracker().start(Skill.MAGIC);
    }
//***************************************************************************************************************************	
    @[member='Override']
    public void onExit() {
    	
    }
//*************************************************************************************************************************	
	private enum State {//Fishing States
		SPLASH,WAIT,STOP
	}
//***************************************************************************************************************************
	private State getState(){
		if(myPlayer().isAnimating() ||  myPlayer().isMoving() || myPlayer().isUnderAttack())//If my player is doing something, or isnt moving and isnt
			return State.WAIT;
		return State.SPLASH;//if none are true FIGHTS
	}
//***************************************************************************************************************************

//***************************************************************************************************************************
    @[member='Override']
    public int onLoop() throws InterruptedException {
    	switch (getState()) {
		case SPLASH:
			splash();
			sleep(random(800, 1500));
			break;
		case WAIT:
			log("waiting");
			sleep(random(500, 1500));
			break;
		case STOP:
			this.stop();//exits script
		}
		return random(200, 300);
	}//The amount of time in milliseconds before the loop starts over
//***************************************************************************************************************************
    public void splash(){//attacks chickens
    	NPC monk_of_zamorack = getNpcs().closest("Monk of Zamorak");
		if(monk_of_zamorack.isAttackable()){//if your player can attack chicken attacks it
			if(getTabs().getOpen() != null && getTabs().getOpen().equals(Tab.MAGIC)) {
				getMagic().castSpellOnEntity(Spells.NormalSpells.CURSE, monk_of_zamorack);
				numSplashes++;
			} else {
				getTabs().open(Tab.MAGIC);
			}
		}
		log("SPLASHING");
    }
//**************************************************************************************************************************    
   // public void onMessage(Message message) throws java.lang.InterruptedException {
	//	String txt = message.getMessage().toLowerCase();
		//if (txt.contains("trout"))
			
	
//**************************************************************************************************************************
    @[member='Override']
    public void onPaint(Graphics2D g) {
    	long runTime = System.currentTimeMillis() - startTime;
        
    	Font font = new Font("Open Sans", Font.BOLD, 18);
    	g.setFont(font);
    	
    	g.drawString("Run Time - " + formatTime(runTime), 10, 220);
    	g.drawString("Experience Gained - " + getExperienceTracker().getGainedXP(Skill.MAGIC),300,220);
    	
    	g.drawString("Current Magic Level - " + getSkills().getStatic(Skill.MAGIC), 10, 240);
    	g.drawString("Magic Levels Gained - " + getExperienceTracker().getGainedLevels(Skill.MAGIC), 300, 240);
    	
    	g.drawString("EXP Until Level - " + getSkills().experienceToLevel(Skill.MAGIC), 10, 260);
    	g.drawString("EXP Per Hour - " + getExperienceTracker().getGainedXPPerHour(Skill.MAGIC), 300, 260);
    	
    	g.drawString("Time Until Next Level - " + formatTime(getExperienceTracker().getTimeToLevel(Skill.MAGIC)), 10, 280);
    	g.drawString("Current State - " + getState(), 300, 280);
    	
    	g.drawString("Number of Splashes - " + numSplashes, 10, 300);
    }
//***************************************************************************************************************************
    public final String formatTime(final long ms){//converts milliseconds to hh:mm:ss will leave out hh and mm if its is 0
        long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
        s %= 60; m %= 60; h %= 24;

        return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) :
               h > 0 ? String.format("%02d:%02d:%02d", h, m, s) :
               String.format("%02d:%02d", m, s);
    }
//***************************************************************************************************************************    
}

Edited by teddros

I could learn a thing or two about coding my own scripts. Thanks!

What's with the //********************************************************************************************************* ?

  • Author

What's with the //********************************************************************************************************* ?

This question never gets old. It's nothing just looks neater to me, my friend used to do this and unfortunately it stuck with me as ugly as it may look.

By the way I read your tutorial on the GUI, it was excellent so I stole the entire thing. I'm creating a much more improved fishing script, should be done in a day or so unless I get bored of runescape in a day or so which is highly likely.

Edited by teddros

This question never gets old. It's nothing just looks neater to me, my friend used to do this and unfortunately it stuck with me as ugly as it may look.

 

My only gripe about your code is that. I suggest getting away from doing that. Not sure about anyone else but all that purple strains my eyes

Edited by Zappster

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.