Jump to content

clayMiner (Yanille) [First script]


wavh

Recommended Posts

Hello! Earlier this week I got into scripting and tried to make a runecrafting bot, it was unsucessful and i ragequitted for some days. I got back today and decided to create a clay miner. I have been spending the whole night trying to get it work. Its in a critical stage which means that it probably contains alot of bugs. Therefor i'll be releasing it and let you guys test it.

 

Please post below if you are gonna try it, and please post below if you find any bug. Explain the bug and i will fix it.

 

Add my skype : william.holmb if you want to be a beta tester for future scripts.

 

Dont mind the paint, will remove if you think its annoying. Was just playing around with photoshop haha!

post-1828-0-21507500-1388186228_thumb.png

 

For download.
 
 
 
Code:
package Miner;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.RS2Object;
import org.osbot.script.rs2.skill.Skill;
import org.osbot.script.rs2.ui.Bank;
import org.osbot.script.rs2.utility.Area;


@ScriptManifest(author = "Wavh", info = "Mines dem clays for you![BETA STAGE]", name = "ClayMiner", version = 0.1)
public class Clay extends Script{
	static Timer runTime = new Timer(0);
	public Position bankPos = new Position(2613,3094,0);
	public Area mineArea = new Area(2633,3140,2627,3146);
	Position minePos = new Position(2628,3145,0);
	
	

	int clayRock = 11728;
	int claysmined = 0;
	int clay = 434;
	int startXp;
	String status = "Starting!";
	public void onStart() {
		startXp = client.getSkills().getExperience(Skill.MINING);
		runTime = new Timer(0);
	}
	public long lastRun = 0;
	public Position lastClick = null;
	public int randomDistance = 0;
	 
	public boolean walkToLocation(Position p) throws InterruptedException {
	int maxY;
	int maxX;
	boolean revY = false;
	boolean revX = false;
	Position playerPosition = myPlayer().getPosition();
	if(playerPosition.getX() < p.getX()) {
	revX = true;
	int distance = p.getX()-playerPosition.getX();
	if(distance > 17) {
	maxX = 17;
	} else {
	maxX = distance;
	}
	} else {
	int distance = playerPosition.getX()-p.getX();
	if(distance > 17) {
	maxX = 17;
	} else {
	maxX = distance;
	}
	}
	if(playerPosition.getY() < p.getY()) {
	revY = true;
	int distance = p.getY()-playerPosition.getY();
	if(distance > 17) {
	maxY = 17;
	} else {
	maxY = distance;
	}
	} else {
	int distance = playerPosition.getY()-p.getY();
	if(distance > 17) {
	maxY = 17;
	} else {
	maxY = distance;
	}
	}
	int addX = (int) (10+(Math.random()*(maxX-10)));
	int addY = (int) (10+(Math.random()*(maxY-10)));
	if(maxX < 10) {
	addX = maxX;
	}
	if(maxY < 10) {
	addY = maxY;
	}
	if(!revX) {
	addX = addX*-1;
	}
	if(!revY) {
	addY = addY*-1;
	}
	if(lastClick == null) {
	if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) {
	lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ());
	randomDistance = (int) (3+(Math.random() * 3));
	}
	} else {
	if(lastClick.distance(myPlayer().getPosition()) < randomDistance) {
	if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) {
	lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ());
	randomDistance = (int) (3+(Math.random() * 3));
	}
	}
	}
	if(lastClick.distance(p) < 5) {
	lastClick = null;
	return true;
	}
	return false;
	}
	
	public enum State {
		WALK_TO_BANK, WALK_TO_MINE,MINE,BANK
	}
	
	public State getState() {
		if(client.getInventory().isFull() && !client.getMyPlayer().getPosition().equals(bankPos)) {
			return State.WALK_TO_BANK;
		}
		if(client.getInventory().isFull() && client.getMyPlayer().getPosition().equals(bankPos)) {
			return State.BANK;
		}
		if(!client.getInventory().isFull() && !mineArea.contains(client.getMyPlayer())) {
			return State.WALK_TO_MINE;
			
		}
		if(!client.getInventory().isFull() && mineArea.contains(client.getMyPlayer())) {
			return State.MINE;
		}
		return null;
		
	}
	
	public int onLoop() throws InterruptedException  {
	
		switch(getState()) {
		case WALK_TO_BANK:
			status = "Walking to bank!";
			walkToBank();
			break;
		case WALK_TO_MINE:
			status = "Walking to mine!";
			walkToMine();
		case MINE:
			status = "Mining!";
			mine();
		break;
		case BANK:
			status = "Banking!";
			bank();
		}
	
		
			
		
		return 80;
	
		
	}
	
	


	


	private void walkToMine() throws InterruptedException {
		walkToLocation(minePos);
		
	}

	private void walkToBank() throws InterruptedException {
		walkToLocation(bankPos);
		
	}

	private void bank() throws InterruptedException {
		Bank bank = client.getBank();
		RS2Object booth = closestObjectForName("Bank booth");
		if(!bank.isOpen()) {
			if(booth != null) {
				booth.interact("Bank");
			}
		}
		if(bank.isOpen()) {
			bank.depositAll();
			sleep(500);
			bank.close();
		}
		
	}




	private void mine() throws InterruptedException {
		RS2Object clayRocks = closestObject(clayRock);
		if(mineArea.contains(client.getMyPlayer())) {
			if(!client.getInventory().isFull()) {
				if(!client.getMyPlayer().isAnimating()){
				if(clayRocks != null) {
					client.moveCameraToEntity(clayRocks);
					clayRocks.interact("Mine");
					if(clayRocks.interact("Mine")) {
						sleep(random(700, 1400));
						}
					
				}
				
			  }
				
			}
		}else {
			walkToLocation(minePos);
		}
		
	}
	
	public void onMessage(String message){
		if(message.contains("You manage to mine some clay")) {
			claysmined++;
		}
	}



    private Image getImage(String url) {
        try {
            return ImageIO.read(new URL(url));
        } catch(IOException e) {
            return null;
        }
    }

    private final Color color1 = new Color(132, 214, 255);

    private final Font font1 = new Font("GulimChe", 0, 13);

    private final Image img1 = getImage("http://gyazo.com/09735524a20461076ee4c206a1e8c6a3.png");

    
    public void onPaint(Graphics g1) {
    	int atmXp = client.getSkills().getExperience(Skill.MINING);
    	int xpGained = atmXp - startXp;
    	
    	
        Graphics2D g = (Graphics2D)g1;
        g.drawImage(img1, -5, 338, null);
        g.setFont(font1);
        g.setColor(color1);
        g.drawString("Experience gained: " + xpGained + " (" + getPerHour(xpGained)+ "/h)", 277, 416);
        g.drawString("Clays mined: " + claysmined + " (" + getPerHour(claysmined) + "/h)", 277, 386);
        g.drawString("Status: " + status, 77, 465);
      //  g.drawString("Timer: " , 406, 465);
    }
    
    public static int getPerHour(int value) {
    	if(runTime != null && runTime.getElapsed() > 0) {
    		return (int) (value*3600000 / runTime.getElapsed());
    	} else{
    		return 0;
    	}
    }
    
    public static long getPerHour(long value) {
    	if(runTime != null && runTime.getElapsed() > 0) {
    		return (long) (value*3600000 / runTime.getElapsed());
    	} else{
    		return 0;
    	}
    }
    
    
    

		
	
	public void onExit() {
		
	}
	
}

 

Link to comment
Share on other sites

ty man, its probably just some id's etc smile.png

Alright so I just took this script to a whole new level. Added some basic GUI (COULD SOME1 PLEASE TEACH ME HOW TO MAKE A SEXY ONE? QwPha8E.png) which means it can now mine everything in yanille.

 

 

Download link: http://uppit.com/hb2rghjwd11m/YanilleAIO.jar

 
Edited by wavh
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...