Jump to content
Appelflapjes

New scripter says hello to OSBOT ;)

Recommended Posts

Hello everyone,

 

As you've read the title, I'm a new scripter in town wink.png.

I'm probably going to create a few scripts to understand the world of OSBOT API.

 

Few things about myself:

I'm 19 years old, live in Belgium and WILL take coding classes (Which will include Java, ...). This might also explain why my English isn't top-notch, so please take that in mind wink.png.

At the moment I'm taking an ICT-related course, which is honesly way to easy for me. Whitout really trying I get 80/100 average.Too bad that's the only coding-related course there is in Belgium. Next year i'll try and get my grade in coding(in Louvain if some people have heard of it).

I play RuneScape since... about 2007 - 2008, and I've botted a couple 99's. I started playing 07 about a couple months ago, but my bought main got banned (Barrows bot... :/). I always loved the concept of a 'bot', and dreamt of making one.

Now this dream has already came true. I've written my first script (very basic, no Antiban) which shears sheep in Lumbrigde and banks.

I already knew the basics of C and Visual Basic, and thought it would've been easyer. The script itself probably has alot of coding mistakes... If you see one, PLEASE tell me what to do, and most importantly WHY it must be changed. I'm here to lean after all.

 

My goals:

To be one of the premium scriptwriters! I'd love the idea that my creatings will be usefull one day. I've got a long way ahead of me, and I think i'll like it smile.png. I'll try to focus alot on 'User Friendly'-ness (Nice GUI's, informative paints, ...) and keeping in touch with the people who review my scripts.

 

 

Cheers!

 

Edit: I'd love to be able to talk to an active scripter (on Skype or ...) to ask coding-related questions. This would help me ALOT smile.png.

Edit2: I'm working atm on a Lumbrigde Swamp (Giant Rat, Giant & Big & Normal Frog) killer with deathwalk/food/bank/hometele/mage/ranged/Draynor bank/Bones/... support. Also looking into a GUI and decent paint smile.png.

 

My first script (*proud*):

(If you know something about how to code: please give a quick review wink.png )

Todo:

• Some kind of antiban

• Paint improvements: Profit/hr, wool/hr

• ...?

(• Making an useless GUI to get the hang of it.)


package Shearer;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Area;
import java.awt.*;
import java.util.Arrays;

@ScriptManifest(name = "Sheep Shearer", author = "Appelflap", version = 1.0, info = "Shears sheep in Lumbridge.", logo = "") 
public class Main extends Script {

	State Current;
	long startTime ;
	private enum State {TOBANK, SHEAR, TOTHESHEEP, CLOSEBANK, IDLE, DEPOSIT };
	
	
	Position[] BANK_TO_STAIRS = {new Position(3208, 3220, 2), new Position(3206, 3224, 2), new Position(3206, 3229, 2)};
	Position[] STAIRS_TO_BANK = {new Position(3206, 3229, 2), new Position(3206, 3224, 2), new Position(3208, 3220, 2)};
	Position[] INTO_PEN = {new Position (3210, 3261, 0), new Position (3206, 3261, 0),};
	Position[] TO_GATE = {new Position (3206, 3261, 0), new Position( 3212, 3261, 0)};
	Position[] STAIRS_TO_SHEEP = {new Position(3205, 3228, 0), new Position(3214, 3227, 0),
			 new Position(3221, 3218, 0), new Position(3232, 3219, 0), new Position(3232, 3228, 0), new Position(3225, 3235, 0),
			 new Position(3219, 3246, 0), new Position(3216, 3257, 0), new Position(3213, 3262, 0)};
	Position[] SHEEP_TO_STAIRS = {new Position(3213, 3262, 0), new Position(3216, 3257, 0),
			new Position(3219, 3246, 0), new Position(3225, 3235, 0), new Position(3232, 3228, 0), new Position(3232, 3219, 0),
			new Position(3221, 3218, 0), new Position(3214, 3227, 0), new Position(3205, 3228, 0)};
	
	
    public void onStart() {
    	log("Let's shear some sheep!");
    	startTime = System.currentTimeMillis();
    	combat.toggleAutoRetaliate(true); //Safety Purposes
    	mouse.setSpeed(150);
    }
    
    public void onExit() {
        log("We stopped shearing the sheep.");
    }

    public int onLoop() throws InterruptedException {
    	Current = getState();
    	log(Current.toString());
    	switch (Current){
 
    	case CLOSEBANK: 
    		while (bank.isOpen()){
    			bank.close();
    			sleep(gRandom(500,1700));
    		}
    		break;
    	
    	case SHEAR:
    		Shear();
    		break;
    	
    	case TOBANK: 
    		WalkToBank();
    		break;
        	
    	case TOTHESHEEP: 
    		WalkToSheep();
    		break;
    	case DEPOSIT: 
    		Deposit();
    		break;
    		
    	case IDLE: 
    		log("This should never happen...");
    		break;
    	
    	}
    	
        return gRandom(100, 800);
 }
   	  	
    public void WalkToSheep() throws IllegalArgumentException, InterruptedException {

			if (myPlayer().getZ() == 2) {
				localWalker.walkPath(BANK_TO_STAIRS);
				sleep(gRandom(1500,2000));
				Entity stairs = objects.closest("Staircase");
				if (stairs != null && stairs.exists()&& Arrays.asList(stairs.getDefinition().getActions()).contains("Climb-down"))
					stairs.interact("Climb-down");
				sleep(gRandom(3000, 4200));
			}
			
			if (myPlayer().getZ() == 1) {
				Entity stairs = objects.closest("Staircase");
				if (stairs != null && stairs.exists()&& Arrays.asList(stairs.getDefinition().getActions()).contains("Climb-down"))
					stairs.interact("Climb-down");
				sleep(gRandom(1000, 1200));
			}
			
			if (myPlayer().getZ() == 0){
				localWalker.walkPath(STAIRS_TO_SHEEP);
				sleep (gRandom(1000,2000));
				Entity Gate = objects.closest("Gate");
				if (Gate != null && Gate.exists()&& Arrays.asList(Gate.getDefinition().getActions()).contains("Open")&& (Gate.getId()== 12987 || Gate.getId()== 12989))
					Gate.interact("Open");
				localWalker.walkPath(INTO_PEN);
				sleep (gRandom(1500,3000));
			}
			
    }
	
    public void WalkToBank() throws IllegalArgumentException, InterruptedException{
    	
    	if (myPlayer().getZ() == 0){
			localWalker.walkPath(TO_GATE);
			sleep (gRandom(1000,2000));
			Entity Gate = objects.closest("Gate");
			if (Gate != null && Gate.exists()&& Arrays.asList(Gate.getDefinition().getActions()).contains("Open"))
				Gate.interact("Open");
			localWalker.walkPath(SHEEP_TO_STAIRS);
			sleep (gRandom(1500,3000));
			Entity stairs = objects.closest("Staircase");
			if (stairs != null && stairs.exists()&& Arrays.asList(stairs.getDefinition().getActions()).contains("Climb-up"))
				stairs.interact("Climb-up");
			sleep (gRandom(2000,5200));
		}
    	
    	if (myPlayer().getZ() == 1) {
			Entity stairs = objects.closest("Staircase");
			if (stairs != null && stairs.exists()&& Arrays.asList(stairs.getDefinition().getActions()).contains("Climb-up"))
				stairs.interact("Climb-up");
			sleep(gRandom(1000, 1200));
		}
    	
    	if (myPlayer().getZ() == 2) {
			localWalker.walkPath(STAIRS_TO_BANK);
			sleep(random(1500,2000));
			Entity Bank = objects.closest ("Bank booth");
			if (Bank != null && Bank.exists()&& Arrays.asList(Bank.getDefinition().getActions()).contains("Bank"))
				Bank.interact("Bank");
			sleep(gRandom(1000, 1200));
					
		}
    }
    
	public void Deposit() throws IllegalArgumentException, InterruptedException {

		if (bank.isOpen()){
				bank.depositAllExcept("Shears");
				if (!inventory.contains("Shears")){
						if (bank.contains("Shears")){
							bank.withdraw("Shears", 1);
							if (inventory.isEmptyExcept("Shears")){
								return;
							}
						}
						else {
							log("ERROR: You do not have shears!");
							stop();
						}
					}		
				
			}
			
		else {
			if (objects.closest("Bank booth") != null) {
				objects.closest("Bank booth").interact("Bank");
				sleep (gRandom(300,800));
			}
			else{
				log("No bank booth found");
			}
		}
		
	}

	public void Shear() throws IllegalArgumentException, InterruptedException{
    	NPC Sheep = getNpcs().closest("Sheep");	
    	Area SHEEP_PEN = new Area(3193, 3257, 3211, 3276);
    	
		if (Sheep != null) {
			if (Sheep.hasAction("Shear")){
				if (myPlayer().getAnimation()!= 893){
					if (Sheep.isVisible()&&Sheep.isOnScreen()){
						if (!Sheep.hasAction("Talk-to")){
							if (Sheep.hasAction("Shear")){
								if (SHEEP_PEN.contains(Sheep)){
										Sheep.interact("Shear");
										sleep (gRandom(1124,2335));
								}						
							}
								
						}
    				}
    				else {
    					camera.toEntity(Sheep);
    					sleep (gRandom(600,800));
					
    				}
				}
			}
		}
    }

    public State getState(){
    	NPC Sheep = getNpcs().closest("Sheep");	
   
    	if (inventory.isEmptyExcept("Shears")&& bank.isOpen())
    		return State.CLOSEBANK; 
    	
    	if (bank.isOpen()|| myPlayer().getPosition() == new Position(3208,3220,2))
    		return State.DEPOSIT;
    	
    	if (!inventory.contains(1735) || inventory.isFull())
    		return State.TOBANK;
    	
    	if (inventory.contains("Shears")&& !inventory.isFull() && Sheep != null)
    		return State.SHEAR;
    	
    	if (inventory.isEmptyExcept("Shears")&& Sheep == null)
    		return State.TOTHESHEEP;
    	
    	if (inventory.isFull())
    		if (!bank.isOpen())
    			return State.TOBANK;
 
    	return State.IDLE;
    	}
 
	public void onPaint(Graphics2D g) {
		
		g.setColor(Color.GREEN);
		g.drawString("Script is running!", 400, 300);
		long elapsed = System.currentTimeMillis() - startTime;
		g.drawString((new StringBuilder("Time: ")).append(format(elapsed)).toString(), 400, 270); //look below
	}

    public String format(long time) { //this is 100% copied from someone of the forums, 0% mine.

        	StringBuilder string = new StringBuilder();
        	long totalSeconds = time / 1000L;
        	long totalMinutes = totalSeconds / 60L;
        	long totalHours = totalMinutes / 60L;
        	int seconds = (int) totalSeconds % 60;
        	int minutes = (int) totalMinutes % 60;
        	int hours = (int) totalHours % 24;
        	if (hours > 0) {
        		string.append((new StringBuilder(String.valueOf(hours))).append(
        				":").toString());
        	}
        	if (minutes > 0) {
        		string.append((new StringBuilder(String.valueOf(minutes))).append(
        				":").toString());
        	}
        	string.append((new StringBuilder(String.valueOf(seconds))).append(":")
        			.toString());
        	return string.toString();
        	}
    
 }
 
 
Edited by Appelflapjes
  • Like 1
Link to comment
Share on other sites

Hi welcome and good luck!
Your first script looks promising :)

Alright, I briefly checked your script ;)

First of all when you script it's important to use an IDE such as eclipse or IntelliJ IDEA. Using IntelliJ you can jump to the (decompiled) implementation of an API method, so you can actually see what it does. There's this line in your script: while (bank.isOpen()){ bank.close(); ...  if we check the implementation, bank.close() already checks if the bank is open. I use this very often, perhaps it's useful for you as well to understand what exactly the api methods do.

Arrays.asList(stairs.getDefinition().getActions()).contains("Climb-down") could be simplified into stairs.hasAction("Climb-down")

You could also check out the doorHandler api, it most likely support gates. You specify what position you want to walk to and the doorhandler opens any doors/gates between the player and the target position.

There are a lot of nested if statements :p I remember I did the same thing when I first started scripting. It's very difficult to debug, so you might want to avoid it ;)

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing   0 members

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