Jump to content

All My Scripts (Merchanter, Fighter, JatiszoOreFarm, NatCrafter, Pest Control)


Mikey

Recommended Posts

Don't play Runescape anymore, so I won't need these. Made these myself in Eclipse. You'll need to edit these yourself to change functionality (merchanting item, fighting monster, etc). These were made before 2.0 came out.

 

If someone could add these to the repo and add some GUI functionality that'd be great (atleast the good ones). Just keep my name as one of the authors and make sure they are free.

 

Mechanter here, this one was working 100% last time I tried it. I did get banned for macroing but it was a "minor" macro ban, only got 3 days for it. You need this API for this one to work: http://paste.ofcode.org/LUiSzjMXMNcyXY6s8adFpz

 

import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Item;
import org.osbot.script.rs2.model.Player;

import trade.api.*;

@ScriptManifest(author = "Mikey1", 
info = "Merchants shit. test1", 
name = "AutoMerch", 
version = 1)
public class Merchanter extends Script {
	
	private final Trade trade = new Trade(this);
	private final boolean DEBUG = true;
	private final long TIME_OUT = 40000;
	
	private final Map<String, Integer> spammers = new HashMap<String, Integer>();
	
	private String merchanting = "granite maul";
	private String username = "";
	private Position start = null;
	private int unnoted = 4153;
	private int noted = 4154;
	private int buy = 70000;
	private int sell = 110000;
	private byte offset = 0;
	private long timeout = 0;
	
	public void a(String mess) {
		if (DEBUG) {
			log(mess);
		}
	}
	
	@Override
	public int onLoop() {
		if (start == null) {
			start = myPlayer().getPosition();
		}
		
		try {
			if (start.distance(myPlayer().getPosition()) >= 7) {
				super.walk(start);
				Thread.sleep(random(678, 890));
			}
			
			a("loop");
			
			if (isTradeOpen()) {
				if (System.currentTimeMillis() - timeout >= TIME_OUT) {
					decline();
					return 500;
				}
				
				a("trade is open..");
				/**
				 * Do trade shit
				 */
				
				if (trade.tradeScreenOneOpen()) {
					a("screen 1 open");
					/**
					 * Determine what to offer or if should decline
					 */
					
					Item offered = getTheirOfferedItem();
					
					if (offered != null) {
						/**
						 * He's offered an item, let's do something about that
						 */
						
						if (offered.getId() == noted || offered.getId() == unnoted) {
							/**
							 * He's selling us something, let's buy it
							 */
							if (client.getInventory().getAmount(995) < buy && getOfferedItemAmount() == 0) {
								decline();
								return random(350, 650);
							}
							
							a("state 7");
							
							int items = offered.getAmount();
							int gold = items * buy;
							
							int offering = getOfferedItemAmount();
							
							if (offering == gold) {
								/**
								 * We're offering the current amount for his gold
								 */
								accept();
							} else if (offering > gold) {
								/**
								 * He has changed his offer, decline.
								 */
								
								a("state 6");
								
								decline();
								return random(1234, 2345);
							} else {
								/**
								 * We need to offer gold
								 */
								
								a("state 5");
								
								gold -= offering;
								
								client.getInventory().interactWithSlot(getCoinSlot(), "Offer-X");
								Thread.sleep(random(1890, 2345));
								
								if (offering == 0 && gold > client.getInventory().getAmount(995)) {
									gold = (int) (client.getInventory().getAmount(995) / buy) * buy;
								}
								
								client.typeString("" + gold);
								return random(1234, 2345);
							}
							
						} else if (offered.getId() == 995) {
							if (client.getInventory().getAmount(unnoted) == 0
									&& client.getInventory().getAmount(noted) == 0 
									&& getOfferedItemAmount() == 0) {
								decline();
								return random(350, 650);
							}
							
							/**
							 * He's buying something, let's accommodate him
							 */
							int gold = offered.getAmount();
							
							if (gold >= sell) {
								/**
								 * He's offered an acceptable amount
								 */
								
								int offering = gold / sell;
								
								if (getOfferedItemAmount() == offering) {
									/**
									 * We're offering the current amount for his gold
									 */
									accept();
								} else if (getOfferedItemAmount() > offering) {
									/**
									 * He has changed his offer, decline.
									 */
									a("decline 11");
									
									decline();
									return random(1234, 2345);
								} else {
									if (offering > 0) {
										a("state 4");
										offering -= getOfferedItemAmount();
										/**
										 * We're going to offer an amount
										 */
										if (offering <= 0) {
											return 500;
										}
										
										///TODO: Enter x amount for a very high amount when applicable
										if (offering >= 10) {
											client.getInventory().interactWithSlot(getItemSlot(), "Offer-10");
										} else if (offering >= 5) {
											client.getInventory().interactWithSlot(getItemSlot(), "Offer-5");
										} else {
											client.getInventory().interactWithSlot(getItemSlot(), "Offer");
										}
										
									} else {
										/**
										 * Not possible, freak out!
										 */
										a("decline 10");
										decline();
										return random(1234, 2345);
									}
								}
								
							} else {
								a("decline 9");
								decline();
								return random(1234, 2345);
							}
							
						} else {
							/**
							 * He's offered something we do not recognize, let's decline the trade
							 */
							
							a("decline 8");
							
							decline();
							return random(1234, 2345);
						}
					}
					
				} else {
					
					a("state 3");
					
					/**
					 * Confirm/Deny the offer and act accordingly
					 */
					
					List<TradeItem> local = getSecondScreenItems(trade.TRADE_SCREEN_TWO_CHILD_MY_ITEMS);
					List<TradeItem> other = getSecondScreenItems(trade.TRADE_SCREEN_TWO_CHILD_THEIR_ITEMS);
					
					if (other == null || local == null || other.size() == 0 || local.size() == 0) {
						a("decline 7");
						decline();
						return random(1234, 2345);
					}
					
					TradeItem mine = local.get(0);
					TradeItem theirs = other.get(0);
					
					if (theirs == null || mine == null) {
						a("decline 6");
						decline();
						return random(1234, 2345);
					}
					
					if (mine.getName().equalsIgnoreCase(theirs.getName())) {
						a("decline 5");
						decline();
						return random(1234, 2345);
					}
					
					if (mine.getName().equals("Coins")) {
						/**
						 * I'm buying
						 */
						
						a("stage 2");
						
						int coins = mine.getAmount();
						int buying = theirs.getAmount();
						
						if (!theirs.getName().equalsIgnoreCase(merchanting)) {
							a("decline 4");
							decline();
							return random(1234, 2345);
						}
						
						if (coins / buy > buying) {
							/**
							 * Didn't offer enough
							 */
							
							a("decline 3");
							
							decline();
							return random(1234, 2345);
						} else {
							/**
							 * Accepted.
							 */
							
							accept();
							return random(1234, 2345);
						}
					} else if (mine.getName().equalsIgnoreCase(merchanting)) {
						a("state 1");
						
						/**
						 * I'm selling
						 */
						
						int selling = mine.getAmount();
						int coins = theirs.getAmount();
						
						if (!theirs.getName().equalsIgnoreCase("Coins")) {
							a("decline 2");
							
							decline();
							return random(1234, 2345);
						}
						
						if (selling * sell > coins) {
							/**
							 * Didn't offer enough
							 */
							
							a("decline 1");
							
							decline();
							return random(1234, 2345);
						} else {
							/**
							 * Accepted.
							 */
							
							accept();
							return random(1234, 2345);
						}
					}
				}
				
			} else {
				/**
				 * Advertise
				 */
				
				a("type");
				
				if (offset++ >= 6) {
				
					typeString(getRandomTextEffect() + (client.getInventory().getAmount(995) >= buy ? "Buy " + merchanting + " " + getAmount(buy) : "")
							+ (hasSellItem() ? " / Sell " + merchanting + " " + getAmount(sell) : "")
							+ " / " + username, true
							);
					
					offset = 0;
				}
				
				return random(456, 567);
				
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return random(1234, 1567);
	}
	
	public void typeString(String s, boolean enter) throws InterruptedException {
		for (char c : s.toCharArray()) {
			bot.getKeyboard().typeKeyEvent(c, 0);
		}
		if (enter) {
			client.typeKey((char) KeyEvent.VK_ENTER, 0, 0, false);
		}
	}
	
	public String getRandomTextEffect() {
		String[] e = {
			"cyan:", "red:", "wave:", "flash1:", "flash2:", "flash3:",
			"purple:",
		};
		
		return e[random(0, e.length)];
	}
	
	public void accept() throws Exception {
		a("accept");
		trade.acceptTrade();
		client.clickMouse(false);
		Thread.sleep(random(1679, 1980));
	}
	
	public void decline() throws Exception {
		a("decline..");
		trade.declineTrade();
		client.clickMouse(false);
		Thread.sleep(random(1679, 1980));
	}
	
	public List<TradeItem> getSecondScreenItems(int child) throws Exception {
		String text = trade.getSecondWindowText(child);
		
		if (text == null) {
			return null;
		}
		
		return trade.getItemsSecondaryScreen(text);
	}
	
	public int getCoinSlot() {
		Item[] k = client.getInventory().getItems();
		int slot = 0;
		
		for (Item i : k) {
			if (i != null && i.getId() == 995) {
				return slot;
			}
			
			slot++;
		}
		
		return -1;
	}
	
	public int getItemSlot() {
		Item[] k = client.getInventory().getItems();
		int slot = 0;
		
		for (Item i : k) {
			if (i != null && i.getId() == unnoted || i != null && i.getId() == noted) {
				return slot;
			}
			
			slot++;
		}
		
		return -1;
	}
	
	public int getOfferedItemAmount() {
		Item[] local = trade.getItemsFirstScreen(trade.TRADE_SCREEN_ONE_CHILD_MY_ITEMS);
		
		if (local == null || local[0] == null) {
			return 0;
		}
		
		return local[0].getAmount();
		
	}
	
	public Item getTheirOfferedItem() {
		Item[] other = trade.getItemsFirstScreen(trade.TRADE_SCREEN_ONE_CHILD_THEIR_ITEMS);
		
		if (other == null) {
			return null;
		}
		
		return other[0];
	}
	
	public boolean hasSellItem() {
		Item[] i = client.getInventory().getItems();
		
		for (Item k : i) {
			if (k != null) {
				if (k.getId() == unnoted || k.getId() == noted) {
					return true;
				}
			}
		}
		
		return false;
	}
	
	public String getAmount(int amount) {
		if (amount >= 1000) {
			return (amount / 1000) + "K";
		} else {
			return amount + " gp";
		}
	}
	
	public boolean isTradeOpen() {
		return trade.tradeScreenOneOpen() || trade.tradeScreenTwoOpen();
	}
	
	@Override
	public void onReceiveTrade(String traded) {
		Player p = getPlayerWithName(traded);
		
		if (p != null) {
			try {
				Thread.sleep(random(1290, 1690));
				
				if (p.getPosition().distance(myPlayer().getPosition()) <= 2) {
					p.interact("trade with");
					timeout = System.currentTimeMillis();
					
					if (spammers.containsKey(traded)) {
						int am = spammers.get(traded);
						
						if (am >= 3) {
							return;
						} else {
							spammers.remove(traded);
							spammers.put(traded, am + 1);
						}
					} else {
						spammers.put(traded, 1);
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public Player getPlayerWithName(String name) {
		List<Player> players = client.getLocalPlayers();
		
		for (Player i : players) {
			if (i.getName().toLowerCase().equalsIgnoreCase(name.toLowerCase())) {
				return i;
			}
		}
		
		return null;
	}
	
	
	
	
	
	/**
	 * Ignore..
	 */
	public void test() throws Exception {
		Item[] local = trade.getItemsFirstScreen(trade.TRADE_SCREEN_ONE_CHILD_MY_ITEMS);
		Item[] other = trade.getItemsFirstScreen(trade.TRADE_SCREEN_ONE_CHILD_THEIR_ITEMS);
		
		if (local != null) {
			log("|| local ||");
			for (Item i : local) {
				if (i != null) {
					log("" + i.getName());
				}
			}
		} else {
			log("local is null");
		}
		
		if (other != null) {
			log("|| other ||");
			for (Item i : other) {
				if (i != null) {
					log("" + i.getName());
				}
			}
		} else {
			log("other is null");
		}
	}
}

 

Fighter, pretty simple just auto-eats and logs out (I think).

 

import java.awt.Color;
import java.awt.Graphics;
import java.util.List;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.def.ItemDefinition;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.GroundItem;
import org.osbot.script.rs2.model.Item;
import org.osbot.script.rs2.model.NPC;
import org.osbot.script.rs2.skill.Skill;
import org.osbot.script.rs2.ui.LogoutTab;

@ScriptManifest(author = "Mikey1", info = "A simple combat script that fights Chaos Druids and collects Herbs.", name = "HerbsCollector", version = 1)
public class OSCombatFighter extends Script {
	private final boolean DEBUG_MODE = true;
	private static final int RANNAR = 207;
	private static final int SNAPDRAGON = 3051;
	private static final int LOOT_BAG = 11941;
	
	private boolean buryBones = true;
	
	public byte lookPosition = 0;
	
	private long noCombatantDelay = System.currentTimeMillis();
	private long noCombatantStartDelay = System.currentTimeMillis();
	
	private int[] attackIds = {5430, 5396, 5395, 5399, 5400, 5398, 5397,
			474, 476, 475, 478, 471, 473, 472, 477, 536, 386, 390, 389, 387, 385, };
	
	private Position deadNpcPosition = null;
	
	private int runStatus = 0;
	
	private double exp = 0;
	
	private final long start = System.currentTimeMillis();
	
	public long elapsed() {
		return System.currentTimeMillis() - start;
	}
	
	public double getTotalExp() {
		double exp = 0;
		
		exp += client.getSkills().getExperience(Skill.ATTACK);
		exp += client.getSkills().getExperience(Skill.STRENGTH);
		exp += client.getSkills().getExperience(Skill.DEFENCE);
		exp += client.getSkills().getExperience(Skill.RANGED);
		exp += client.getSkills().getExperience(Skill.MAGIC);
		
		return exp;
	}
	
	public final Position[] runAwayPositions = {
		new Position(3105, 9953, 0),
		new Position(3121, 9958, 0),
		new Position(3128, 9949, 0),
		new Position(3133, 9939, 0),
		new Position(3125, 9930, 0),
		new Position(3117, 9931, 0),
	};;
	
	@Override
	public void onStart() {
		log("Initializing HerbCollector by Mikey1..");
		
	}
	
	public void debug(String string) {
		if (DEBUG_MODE) {
			log(string);
		}
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		checkHealthAndEat(false);
		//checkForRunAway();
		//exp = getTotalExp();
		
		if (myPlayer().getClient().getLevelStat()[1] >= 60) {
			new LogoutTab(this).logOut();
			this.stop();
			
			return random(900, 1200);
		}
		
		if (runStatus != 0) {
			log("Running!");
			
			int index = runStatus - 1;
			
			if (getDistance(runAwayPositions[5]) <= 4) {
				runStatus = 0;
				return 100;
			}
			
			if (getDistance(runAwayPositions[index]) <= 4) {
				runStatus++;
				index++;
				
				if (index >= runAwayPositions.length) {
					runStatus = 0;
					return 100;
				}
			}
			
			this.walk(runAwayPositions[index]);
			
			
			return random(100, 200);
		}
		
		if (!myPlayer().isMoving()) {
			checkForLoot();
		}
		
		if (buryBones) {
			buryBones();
		}
		
		if (myPlayer().getFacing() != null && myPlayer().getFacing() instanceof NPC) {
			deadNpcPosition = ((NPC) myPlayer().getFacing()).getPosition();
		}
		
		if (!isAttacking() && !myPlayer().isMoving()) {
			NPC next = getClosestAttackMob();
			
			if (next != null) {
				myPlayer().getClient().moveCameraToEntity(next);
				
				next.interact("Attack");
				
				noCombatantStartDelay = 0;
				
				debug("Combatant found, attacking..");
				
				return random(2000, 3123);
			} else {
				doAntiban();
				try {
					moveCamera();
				} catch (Exception e) {
					e.printStackTrace();
				}
				
				/*if (noCombatantStartDelay == 0) {
					noCombatantStartDelay = System.currentTimeMillis();
					noCombatantDelay = 0;
				}
				
				noCombatantDelay += System.currentTimeMillis() - noCombatantStartDelay;
				
				if (noCombatantDelay >= 60000 * 5) {
					new LogoutTab(this).logOut();
				}*/
				
				debug("No combatant found, moving camera to different position.");
			}
			
		} else {
			doAntiban();
			debug("Waiting for combat to finish..");
		}
		
		return random(1750, 2750);
	}
	
	public void checkForRunAway() {
		List<NPC> npcs = myPlayer().getClient().getLocalNPCs();
		
		for (NPC i : npcs) {
			int id = i.getId();
			if (id == 3100 || id == 3102 || id == 2188
					|| id ==2190 || id == 2187 ) {
				if (i.getFacing() != null && i.getFacing().getIndex() == myPlayer().getIndex()) {
					
					int lowDist = 9999;
					
					int index = 0;
					for (Position k : runAwayPositions) {
						if (getDistance(k) < lowDist) {
							runStatus = index + 2;
							lowDist = getDistance(k);
						}
						
						index++;
					}
					
					return;
				}
			}
		}
	}
	
	public void checkForLoot() {
		List<GroundItem> items = myPlayer().getClient().getCurrentRegion().getItems();
		
		for (GroundItem i : items) {
			if (myPlayer().getClient().getLevelStat()[5] < 52) {//prayer level check
				if (buryBones && myPlayer().getClient().getInventory().getEmptySlots() > 0) {
					if (deadNpcPosition != null && i.getPosition().equals(deadNpcPosition) 
							&& i.getName() != null && i.getName().toLowerCase().contains("bones")) {
						try {
							i.interact("Take");
							Thread.sleep(3000);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				}
			}
			
			if (i.getId() == LOOT_BAG) {
				try {
					i.interact("Take");
					Thread.sleep(3000);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
			if (i.getId() == RANNAR || i.getId() == SNAPDRAGON) {
				try {
					i.interact("Take");
					Thread.sleep(3000);
					//depositHerbIntoLootBag();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	public void depositHerbIntoLootBag() {
		if (hasLootBag()) {
			Item[] items = myPlayer().getClient().getInventory().getItems();
			int slot = 0;
			
			for (Item i : items) {
				if (i != null && i.getId() == RANNAR) {
					try {
						myPlayer().getClient().getInventory().interactWithSlot(slot, "Use");
						myPlayer().getClient().getInventory().interactWithSlot(myPlayer().getClient().getInventory().getSlotForId(LOOT_BAG), "Use");
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				
				slot++;
			}
		}
	}
	
	public boolean hasLootBag() {
		return myPlayer().getClient().getInventory().contains(LOOT_BAG);
	}
	
	public boolean hasFood() {
		Item[] items = myPlayer().getClient().getInventory().getItems();
		
		for (Item i : items) {
			if (i != null && ItemDefinition.forId(i.getId()).getActions()[0] != null) {
				if (ItemDefinition.forId(i.getId()).getActions()[0].equals("Eat")) {
					return true;
				}
			}
		}
		return false;
	}
	
	public void buryBones() {
		if (!buryBones) {
			return;
		}
		Item[] items = myPlayer().getClient().getInventory().getItems();
		int slot = 0;
		
		for (Item i : items) {
			if (i != null && ItemDefinition.forId(i.getId()).getActions()[0] != null) {
				if (ItemDefinition.forId(i.getId()).getActions()[0].equals("Bury")) {
					try {
						myPlayer().getClient().getInventory().interactWithSlot(slot, "Bury");
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
			
			slot++;
		}
	}
	
	public void moveCamera() throws Exception {
		switch (lookPosition) {
		case 0:
			myPlayer().getClient().moveCameraToPosition(
					new Position(myPlayer().getPosition().getX() - 10, 
							myPlayer().getPosition().getY(), 
							myPlayer().getPosition().getZ()));
			break;
		case 1:
			myPlayer().getClient().moveCameraToPosition(
					new Position(myPlayer().getPosition().getX(), 
							myPlayer().getPosition().getY() - 10, 
							myPlayer().getPosition().getZ()));
			break;
		case 2:
			myPlayer().getClient().moveCameraToPosition(
					new Position(myPlayer().getPosition().getX() + 10, 
							myPlayer().getPosition().getY(), 
							myPlayer().getPosition().getZ()));
			break;
		case 3:
			myPlayer().getClient().moveCameraToPosition(
					new Position(myPlayer().getPosition().getX(), 
							myPlayer().getPosition().getY() + 10, 
							myPlayer().getPosition().getZ()));
			break;
		}
		
		lookPosition = (byte) (lookPosition >= 3 ? 0 : lookPosition + 1);
		
		Thread.sleep(random(900, 1453));
	}
	
	public void checkHealthAndEat(boolean override) {
		if (isLowHealth() || override) {
			Item[] items = myPlayer().getClient().getInventory().getItems();
			
			int slot = 0;
			
			for (Item i : items) {
				if (i != null && ItemDefinition.forId(i.getId()) != null 
						&& ItemDefinition.forId(i.getId()).getActions()[0] != null) {
					if (ItemDefinition.forId(i.getId()).getActions()[0].equals("Eat")) {
						
						try {
							myPlayer().getClient().getInventory().interactWithSlot(slot, "Eat");
							myPlayer().getClient().clickMouse(false);
							Thread.sleep(2000);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
						
						if (!isLowHealth()) {
							return;
						}
					}
				}
				
				slot++;
			}
			
			if (myPlayer().getHealth() <= 25) {
			}
		}
	}
	
	public void doAntiban() {
		
		if (random(0, 100) <= 15) {
			try {
				moveCamera();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}
	
	@Override
	public void onExit() {
		log("Exiting HerbCollector by Mikey1..");
	}

	@Override
	public void onPaint(Graphics g) {
		g.setColor(Color.WHITE);
		int y = 90;
		g.drawString("Attack: " + client.getLevelStat()[Skill.ATTACK.getId()] , 15, y += 15);
		g.drawString("Strength: " + client.getLevelStat()[Skill.STRENGTH.getId()] , 15, y += 15);
		g.drawString("Defence: " + client.getLevelStat()[Skill.DEFENCE.getId()] , 15, y += 15);
		g.drawString("Magic: " + client.getLevelStat()[Skill.MAGIC.getId()] , 15, y += 15);
		g.drawString("Ranged: " + client.getLevelStat()[Skill.RANGED.getId()] , 15, y += 15);
		g.drawString("Prayer: " + client.getLevelStat()[Skill.PRAYER.getId()] , 15, y += 15);
		g.drawString("Hitpoints: " + client.getLevelStat()[Skill.HITPOINTS.getId()] , 15, y += 15);
	}
	
	public boolean hasAttackId(int id) {
		for (int i : attackIds) {
			if (i == id) {
				return true;
			}
		}
		
		return false;
	}
	
	public NPC getClosestAttackMob() {
		List<NPC> npcs = myPlayer().getClient().getLocalNPCs();
		
		int lowDist = 99999;
		NPC closest = null;
		
		for (NPC i : npcs) {
			if (i != null && i.getHealth() > 0) {
				
				if (i.getFacing() != null 
						&& i.getFacing().getIndex() == myPlayer().getIndex()) {
					log("Attacking mob that is currently attacking player..");
					return i;
				}
				
				if (!i.isUnderAttack() && hasAttackId(i.getId())) {
					if (closest == null || lowDist > getDistance(i)) {
						closest = i;
						lowDist = getDistance(i);
					}
				}
			}
		}
		
		return closest;
	}
	
	public int getDistance(NPC mob) {
		return Math.abs(mob.getX() - myPlayer().getX()) 
				+ Math.abs(mob.getY() - myPlayer().getY());
	}
	
	public int getDistance(Position p) {
		return Math.abs(p.getX() - myPlayer().getX()) 
				+ Math.abs(p.getY() - myPlayer().getY());
	}
	
	public boolean isAttacking() {
		return myPlayer().getFacing() != null && myPlayer().isUnderAttack() 
				|| myPlayer().getFacing() != null &&  Math.abs(myPlayer().getCombatTime() - myPlayer().getClient().getCurrentTime()) <= 500;
	}
	
	@Override
	public String getAuthor() {
		return "Mikey1";
	}
	
	public boolean isLowHealth() {
		return ((double) myPlayer().getClient().getCurrentLevelStat()[3] / (double) myPlayer().getClient().getLevelStat()[3]) <= 0.5;
	}
}

 

Jatiszo ore farmer, buys ore which you can then sell. Did this one about 3 days straight with no ban.

 

 

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.security.SecureRandom;
import java.util.List;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.mouse.AreaDestination;
import org.osbot.script.rs2.def.ItemDefinition;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Item;
import org.osbot.script.rs2.model.NPC;
import org.osbot.script.rs2.model.Player;
import org.osbot.script.rs2.model.RS2Object;
import org.osbot.script.rs2.ui.Inventory;
import org.osbot.script.rs2.ui.LogoutTab;
import org.osbot.script.rs2.ui.Message;
import org.osbot.script.rs2.ui.Message.MessageType;
import org.osbot.script.rs2.ui.Tab;
import org.osbot.script.rs2.ui.WorldHopper;

@ScriptManifest(author = "Mikey1", 
info = "Farms gold by buying ore in Jatizso and selling for profit.", 
name = "JatiszoGoldFarm", 
version = 1)

public class OreGoldFarm extends Script {
	
	private final int BANK_NPC = 5786;
	private final int ACCIDENT_MOB_1 = 5783;
	private final int SHOP_KEEPER = 5781;
	
	private final Loc[] PATH = {
		new Loc(2417, 3801),
		new Loc(2405, 3799),
		new Loc(2395, 3797),
	};

	private Inventory inventory = null;
	private Player player = null;
	
	/**
	 * Script fields
	 */
	private boolean banking = false;
	private int progress = 0;
	private int bvalue = 0;
	private int sbvalue = 0;
	private int gold = 0;
	private int silver = 0;
	private int coal = 0;
	private int iron = 0;
	private int copper = 0;
	private final long start = System.currentTimeMillis();
	private long talk = System.currentTimeMillis();
	private long clantalk = System.currentTimeMillis();
	private int world = 303;
	
	@Override
	public void onPaint(Graphics g) {
		int y = 45;
		int x = 5;
		g.setColor(Color.RED);
		g.drawString("JatizsoOreFarm", x, y += 15);
		g.drawString("Runtime: " + (seconds() > 3600 * 2 ? (seconds() * 3600) + " Hours" : (seconds() / 60) + " Minutes"), x, y += 15);
		y += 20;
		g.drawString("Banked ore value: " + (bvalue / 1000) + "K", x, y += 15);
		y += 20;
		g.drawString("Banked Gold Ore: " + gold, x, y += 15);
		g.drawString("Banked Silver Ore: " + gold, x, y += 15);
		g.drawString("Banked Coal Ore: " + coal, x, y += 15);
		g.drawString("Banked Iron Ore: " + iron, x, y += 15);
		g.drawString("Banked Copper Ore: " + copper, x, y += 15);
		y += 20;
		g.drawString("Total Profit: " + ((bvalue - sbvalue) / 1000) + "K", x, y += 15);
		
		if (minutes() > 0) {
			g.drawString("Profit/Hour: " + (( ((bvalue - sbvalue) / minutes()) * 60  ) / 1000) + "K", x, y += 15);
		}
	}
	
	public int getTotalValue() {
		return (gold * 340) + (coal * 184) + (iron * 70) + (silver * 135) + (copper * 105);
	}
	
	public int multiply(int a, int b) {
		return a * b;
	}
	
	@Override
	public void onStart() {
		inventory = myPlayer().getClient().getInventory();
		player = myPlayer();
		super.worldHopper = new WorldHopper(this);
	}
	
	@Override
	public int onLoop() {
		try {
			
			if (getItemAmount(995) <= 5000) {
				while (isLoggedIn()) {
					super.closeOpenInterface();
					new LogoutTab(this).logOut();
				}
				this.stop();
			}
			
			/*if (world < 370 && !isShopOpen() && !client.getBank().isOpen() && client.getLocalPlayers().size() > 3
					&& this.isLoggedIn()) {
				/**
				 * Hop worlds.
				 */
				
				/*world++;
				
				if (world == 325) {
					world = 324;
				}
				
				if (world == 337) {
					world = 336;
				}
				
				if (world == 316) {
					world = 315;
				}
				
				if (world == 308) {
					world = 307;
				}
				
				super.worldHopper.hopWorld(world);
				return random(789, 1234);
			}*/
			
			if (banking || inventory.isFull() 
					|| client.getBank().isOpen() || !isShopOpen() && inventory.getEmptySlots() < 10) {
				progress = 0;
			
				if (client.getBank().isOpen()) {
					while (inventory.getEmptySlots() != 27 && getSlotThatIsntCoins() != -1) {
						log("store");
						inventory.interactWithSlot(getSlotThatIsntCoins(), "Deposit-all");
						delay();
						delay();
					}
					
					
					delay();
					delay();
					setBankValue();
					
					client.getBank().close();
					if (!client.getBank().isOpen()) {
						banking = false;
					}
				} else if (isNearBank()) {
					/**
					 * Open bank
					 */
					log("open bank");
					interactWithMob(BANK_NPC, "Bank");
				} else {
					/**
					 * Walk to bank
					 */
					log("walking");
					walk(true);
				}
			} else {
				if (isShopOpen()) {
					if (getShopIndexForName("chainbody") != -1) {
						super.closeOpenInterface();
						return random(1000, 1250);
					}
					
					int index = getFirstOreShopIndex();
					log("buy from " + index);
					
					while (index != -1 && !inventory.isFull() || inventory.getEmptySlots() > 3) {
						int free1 = inventory.getEmptySlots();
						buyFromShop(index, 10);
						delay();
						int free2 = inventory.getEmptySlots();
						
						if (free1 != free2) {
							progress++;
							
							if (progress >= 4) {
								banking = true;
								progress = 0;
							}
						}
						
						index = getFirstOreShopIndex();
					}
				} else if (isNearStore()) {
					log("trade");
					
					/**
					 * Anti-ban
					 */
					if (random(0, 100) <= 7) {
						log("anti-ban measure");
						interactWithMob(ACCIDENT_MOB_1, "Trade");
					}
					/**
					 * 
					 */
					
					interactWithMob(SHOP_KEEPER, "Trade");
				} else {
					log("walking");
					walk(false);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return random(567, 789);
	}
	
	public boolean isNearPlayer() {
		List<Player> p = client.getLocalPlayers();
		
		for (Player i : p) {
			if (i != null) {
				if (!i.equals(player) && i.getPosition().distance(player.getPosition()) <= 7) {
					return true;
				}
			}
		}
		
		return false;
	}
	
	public boolean isLoggedIn() {
		return client.getLoginState() == 30;
	}
	
	public void moveMouseToAndClick(int x, int y, boolean left) throws Exception {
		client.moveMouse(new AreaDestination(new Area(new Rectangle(x, y, 7, 7))), true);
		Thread.sleep(500);
		client.clickMouse(left);
	}
	
	public long seconds() {
		return (System.currentTimeMillis() - start) / 1000;
	}
	
	public long minutes() {
		return seconds() / 60;
	}
	
	@Override
	public void onMessage(Message m) {
		if (m.getType() == MessageType.CLAN_CHAT) {
			/**
			 * Is clan chat..
			 */
			
			String c = m.getMessage().toLowerCase();
			
			try {
				
				if ((System.currentTimeMillis() - clantalk) / 1000 < 60 * 6) {
					return;
				}
			
				if (c.contains("grat") || c.contains("gz")) {
					int r = random(0, 100);
					if (r <= 33) {
						client.typeString("/gratz");
					} else if (random(0, 100) <= 66) {
						client.typeString("/gz");
					} else {
						client.typeString("congrats!");
					}
					
					clantalk = System.currentTimeMillis();
				} else if (c.contains("lol") || c.contains("lmfao") || c.contains("l0l")) {
					int r = random(0, 100);
					if (r <= 33) {
						client.typeString("/lol");
					} else if (random(0, 100) <= 66) {
						client.typeString("/lmfao");
					} else {
						client.typeString("l0l");
					}
					
					clantalk = System.currentTimeMillis();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * Get average amount per hour
	 * @param current
	 * 			the current amount of this thing
	 * @return
	 * 		the average amount per hour
	 */
	public int getAmountPerHour(int amount) {
		return (int) ((amount) / seconds()) * 3600;
	}
	
	public int getSlotThatIsntCoins() {
		Item[] k = inventory.getItems();
		int slot = 0;
		
		for (Item i : k) {
			if (i != null && i.getId() != 995) {
				return slot;
			}
			
			slot++;
		}
		
		return -1;
	}
	
	public int getFirstOreShopIndex() {
		if (client.getOpenInterface() == null) {
			log("No open interface..");
			return -1;
		}
		
		if (getShopIndexForName("gold") != -1) {
			return getShopIndexForName("gold");
		}
		
		for (int i = client.getOpenInterface().getChildren().length - 1; i >= 0; i--) {
			Item[] k = client.getOpenInterface().getItems(i);
			
			if (k != null) {
				int a = 0;
					for (Item j : k) {
						
						if (j != null && j.getAmount() > 0 && ItemDefinition.forId(j.getId()).getName() != null) {
							String n = ItemDefinition.forId(j.getId()).getName().toLowerCase();
							
							if (n.contains("gold")
									|| n.contains("iron") && getShopIndexForName("gold") == -1 && getShopIndexForName("coal") == -1
									|| n.contains("copper") && getShopIndexForName("coal") == -1
									|| n.contains("coal")
									/*|| n.contains("iron") && progress == 3*/) {
								return a;
							}
						}
						a++;
					}
			}
		}
		
		return -1;
	}
	
	public void setBankValue() {
		Item[] i = client.getBank().getItems();
		bvalue = 0;
		coal = 0;
		gold = 0;
		iron = 0;
		
		for (Item k : i) {
			if (k != null && k.getDefinition() != null && k.getDefinition().getName() != null) {
				final String n = k.getDefinition().getName().toLowerCase();
				
				if (n.contains("gold")) {
					gold = k.getAmount();
				}
				
				if (n.contains("coal")) {
					coal = k.getAmount();
				}
				
				if (n.contains("iron")) {
					iron = k.getAmount();
				}
				
				if (n.contains("copper")) {
					copper = k.getAmount();
				}
				
				if (n.contains("silver")) {
					silver = k.getAmount();
				}
			}
		}
		
		bvalue = getTotalValue();
		
		if (sbvalue == 0) {
			sbvalue = bvalue;
		}
	}
	
	public void walk(boolean reverse) throws Exception {
		int closest = -1;
		int dist = 0;
		
		if (!this.isRunning() && hasFullEnergy()) {
			this.setRunning(true);
			delay();
		}
		
		if (player.isMoving()) {
			Thread.sleep(random(750, 892));
		}
		
		for (int k = 0; k < PATH.length; k++) {
			Loc i = PATH[k];
			if (closest == -1 || getDistance(i) < dist) {
				closest = k;
				dist = getDistance(i);
			}
		}
		
		Loc close = PATH[closest + (reverse ? -1 : 1)];
		Position waypoint = new Position(close.x, close.y, 0);
		
		client.moveCameraToPosition(waypoint);
		
		if (!this.canReach(waypoint)) {
			log("walk 1");
			close = PATH[closest];
			this.walk(new Position(close.x, close.y, 0));
		} else {
			log("walk 2");
			this.walk(waypoint);
		}
		
		if (player.getWalkingQueueSize() >= 8 && !super.isRunning()) {
			super.moveMouseOutsideScreen();
			delay();
			delay();
		} else {
		
			/**
			 * Some anti-ban
			 */
			if (!super.isRunning()) {
				if (random(0, 100) <= 16) {
					super.openTab(Tab.FRIENDS);
					Thread.sleep(random(456, 789));
					super.openTab(Tab.INVENTORY);
				} else if (random(0, 100) <= 16) {
					super.openTab(Tab.SKILLS);
					Thread.sleep(random(900, 1456));
					super.openTab(Tab.INVENTORY);
				} else if (random(0, 100) <= 15) {
					openTab(Tab.QUEST);
					Thread.sleep(random(1345, 2456));
					super.openTab(Tab.INVENTORY);
				} else if (random(0, 100) <= 18) {
					this.client.rotateCameraPitch(50 + random(1, 70));
				} else if (random(0, 100) <= 18) {
					this.client.rotateCameraToAngle(150 + (random(30, 70)));
				} else if (random(0, 100) <= 18) {
					this.client.rotateCameraPitch(50);
				} else if (random(0, 100) <= 4) {
					moveMouseOutsideScreen();
					sleep(random(3000, 7000));
				} else if (random(0, 100) <= 12) {
					openTab(Tab.CLANCHAT);
					delay();
				}
			}
			
			if (isNearPlayer()) {
				if ((System.currentTimeMillis() - talk) / 1000 >= 60 * 30) {
					int r = random(0, 100);
					client.typeString(
							r <= 5 ? "hi"
							: r <= 10 ? "total lvl?"
							: r <= 20 ? "how u doin"
							: r <= 30 ? "how r u, sir"	
							: r <= 40 ? "what u up 2"
							: r <= 45 ? "hm gold you got?"
							: r <= 50 ? "how much cash you get so far?"
							: r <= 60 ? "attack level?"
							: r <= 70 ? "total level?"
							: r <= 80 ? "how much cash you get so far?"
							: r <= 85 ? "smithing lvl?"
							: "sup");
					talk = System.currentTimeMillis();
				}
			}
		}
		
		Thread.sleep(super.isRunning() ? random(890, 1090) : random(1290, 1690));
	}
	
	public int getDistance(Loc p) {
		return Math.abs(p.x - myPlayer().getX()) 
				+ Math.abs(p.y - myPlayer().getY());
	}
	
	public int getWalkingOffset() {
		return random(0, 1) == 1 ?
				random(0, 4) : -random(0, 4);
	}
	
	public int getPathOffset() {
		return random(0, 1) == 1 ?
				random(0, 2) : -random(0, 4);
	}
	
	public int getDistance(Position p) {
		return Math.abs(p.getX() - myPlayer().getX()) 
				+ Math.abs(p.getY() - myPlayer().getY());
	}
	
	public void interactWithMob(int id, String interaction) throws Exception {
		List<NPC> n = client.getLocalNPCs();
		
		for (NPC i : n) {
			if (i != null && i.getId() == id) {
				client.moveCameraToPosition(i.getPosition());
				Thread.sleep(random(123, 234));
				i.interact(interaction);
				delay();
				delay();
				delay();
				delay();
				break;
			}
		}
	}
	
	public int getSlotForName(String name) {
		for (int j = 0; j < inventory.getItems().length; j++) {
			Item i = inventory.getItems()[j];
			if (i != null && i.getDefinition().getName().contains(name.toLowerCase())) {
				return j;
			}
		}
		
		return -1;
	}
	
	public boolean hasFullEnergy() {
		return client.getRunEnergy() >= 25;
	}
	
	public boolean isShopOpen() {
		return !banking && client.getOpenInterface() != null;
	}
	
	public boolean isNearStore() {
		return getShop() != null;
	}
	
	public boolean isNearBank() {
		return getDistance(new Loc(2417, 3801)) <= 9 || distance(new Position(2413, 3797, 0)) <= 8;
	}
	
	public static int random(int start, int end) {
		return start + (new SecureRandom().nextInt(end - start));
	}
	
	public boolean hasItem(int id) {
		Item[] i = inventory.getItems();
		
		for (Item k : i) {
			if (k != null && k.getId() == id) {
				return false;
			}
		}
		
		return false;
	}
	
	public int getItemAmount(int id) {
		Item[] i = inventory.getItems();
		int a = 0;
		
		for (Item k : i) {
			if (k != null && k.getId() == id) {
				a += k.getAmount();
			}
		}
		
		return a;
	}
	
	public int getShopIndexForName(String name) {
		if (client.getOpenInterface() == null) {
			log("No open interface..");
			return -1;
		}
		
		for (int i = client.getOpenInterface().getChildren().length - 1; i >= 0; i--) {
			Item[] k = client.getOpenInterface().getItems(i);
			
			if (k != null) {
				int a = 0;
				for (Item j : k) {
					if (j != null && ItemDefinition.forId(j.getId()).getName() != null) {
						if (ItemDefinition.forId(j.getId()).getName().toLowerCase().contains(name)) {
							return a;
						}
					}
					a++;
				}
			}
		}
		
		return -1;
	}
	
	public void clickObject(int id, String interaction) throws Exception {
		for (RS2Object i : client.getCurrentRegion().getObjects()) {
			if (i.getId() == id) {
				client.moveCameraToEntity(i);
				i.interact(interaction);
				delay();
				return;
			}
		}
	}
	
	public void buyFromShop(int slot, int amount) throws Exception {
		if (slot == -1) {
			return;
		}
		
		delay();
		 
		int x = 93;
		int y = 75;
		
		y += (slot / 8) * 50;
		x += (slot % 8) * 48;
		
		client.moveMouse(new AreaDestination(new Area(new Rectangle(x, y, 4, 4))), true);
		client.clickMouse(true);
		
		y += (amount == 1 ? 40 : amount == 5 ? 55 : amount == 10 ? 70 : 40);
		client.moveMouse(new AreaDestination(new Area(new Rectangle(x, y, 4, 4))), true);
		
		client.clickMouse(false);
		delay();
		delay();
	}
	
	public void delay() throws Exception {
		if (random(0, 100) <= 25) {
			Thread.sleep(random(234, 256));
			return;
		}
		
		if (random(0, 100) <= 8) {
			Thread.sleep(random(456, 678));
			return;
		}
		
		Thread.sleep(random(345, 456));
	}
	
	public NPC getShop() {
		List<NPC> local = client.getLocalNPCs();
		
		for (NPC i : local) {
			if (i.getId() == SHOP_KEEPER) {
				return i;
			}
		}
		
		return null;
		
	}
	
	public boolean doesShopHaveOre() {
		return getShopIndexForName("gold") != -1
				|| getShopIndexForName("coal") != -1 
				|| getShopIndexForName("iron") != -1;
	}
	
	public boolean isOre(int id) {
		String n = ItemDefinition.forId(id).getName().toLowerCase();
		return n.contains("gold") || n.contains("iron") || n.contains("coal");
	}
	
	/**
	 * Shorthand Position class
	 */
	public static class Loc {
		protected int x;
		protected int y;
		
		Loc(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}


}

 

Pest control bot, this one works well and got me to about 77 ranged in a day or two. It will glitch sometimes but overall it functions well.

 

import java.util.List;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.NPC;
import org.osbot.script.rs2.model.RS2Object;
import org.osbot.script.rs2.ui.LogoutTab;
import org.osbot.script.rs2.ui.Tab;

@ScriptManifest(author = "Mikey1", 
info = "Does Pest Control.", 
		name = "PestPro", 
		version = 1)
public class PCBot extends Script {
	
	private final long LOGOUT = 60000 * 375;//estimated time to 250 points
	private final long START = System.currentTimeMillis();
	
	private final int LOW = 14315;
	private final int MED = 25631;
	
	@Override
	public int onLoop() {
		try {
		
			if (!isInGame() && !isOnBoat() && isNearBoatEntrance()) {
				/*if (System.currentTimeMillis() - START >= LOGOUT) {
					while (isLoggedIn()) {
						new LogoutTab(this).logOut();
						Thread.sleep(random(1234, 2345));
					}
					
					this.stop();
				} else {*/
					enterBoat();
					return random(123, 234);
				//}
			} else if (isInGame() && isAtStartBoat()) {
				goToVoidKnight();
				log("walk");
			} else if (isInGame() && !isAttacking()) {
				attack();
				log("attack");
			} else {
				log("anti-ban");
				/**
				 * Anti-ban
				 */
				
				/*if (random(0, 100) <= 21) {
					if (!this.isRunning() && client.getRunEnergy() >= 85) {
						this.setRunning(true);
					} else if (random(0, 100) <= 16) {
						super.openTab(Tab.FRIENDS);
						Thread.sleep(random(456, 789));
						super.openTab(Tab.INVENTORY);
					} else if (random(0, 100) <= 16) {
						super.openTab(Tab.SKILLS);
						Thread.sleep(random(900, 1456));
						super.openTab(Tab.INVENTORY);
					} else if (random(0, 100) <= 15) {
						openTab(Tab.QUEST);
						Thread.sleep(random(1345, 2456));
						super.openTab(Tab.INVENTORY);
					} else if (random(0, 100) <= 18) {
						this.client.rotateCameraPitch(50 + random(1, 70));
					} else if (random(0, 100) <= 18) {
						this.client.rotateCameraToAngle(150 + (random(30, 70)));
					} else if (random(0, 100) <= 18) {
						this.client.rotateCameraPitch(50);
					} else if (random(0, 100) <= 4) {
						moveMouseOutsideScreen();
						sleep(random(3000, 7000));
					} else if (random(0, 100) <= 12) {
						openTab(Tab.CLANCHAT);
					}
				} else {
					if (random(0, 100) <= 25) {
						this.client.rotateCameraPitch(50 + random(1, 70));
					} else if (random(0, 100) <= 25) {
						this.client.rotateCameraToAngle(150 + (random(30, 70)));
					} else if (random(0, 100) <= 25) {
						this.client.rotateCameraPitch(50);
					}
				}*/
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return random(456, 1190);
	}
	
	/**
	 * Attack any mob
	 */
	public void attack() throws Exception {
		NPC next = getClosestAttackMob();
		
		if (next != null) {
			next.interact("Attack");
		}
	}
	
	/**
	 * Enter the boat
	 */
	public void enterBoat() throws Exception {//14315 is entrance
		clickObject(14315, "Cross");
	}
	
	/**
	 * Walk to near the void knight
	 */
	public void goToVoidKnight() throws Exception {
		super.walk(new Position(myPlayer().getX(), myPlayer().getY() - random(8, 12), 0));
	}
	
	/**
	 * Click object
	 */
	public void clickObject(int id, String interaction) throws Exception {
		RS2Object close = null;
		int dist = 999;
		
		for (RS2Object i : client.getCurrentRegion().getObjects()) {
			if (i.getId() == MED || i.getId() == LOW) {
				
				if (close == null || getDistance(i.getPosition()) < dist) {
					close = i;
					dist = getDistance(i.getPosition());
				}
			}
		}
		
		if (close != null) {
			client.moveCameraToEntity(close);
			close.interact(interaction);
		}
	}
	
	/**
	 * Getting the closest attackable npc
	 */
	public NPC getClosestAttackMob() {
		List<NPC> npcs = myPlayer().getClient().getLocalNPCs();
		
		int lowDist = 99999;
		NPC closest = null;
		
		log ("NPCs on local list: " + npcs.size());
		
		for (NPC i : npcs) {
			if (i != null && i.getHealth() > 0 
					&& !i.getName().toLowerCase().contains("knight")
					&& !i.getName().toLowerCase().contains("squire")
					&& !i.getName().contains("Splat")) {
				
				if (i.getName().contains("Spinner")) {
					return i;
				}
				
				if (i.getFacing() != null 
						&& i.getFacing().getIndex() == myPlayer().getIndex()) {
					log("Attacking mob that is currently attacking player..");
					return i;
				}
				
				if (closest == null || lowDist > getDistance(i.getPosition())) {
					closest = i;
					lowDist = getDistance(i.getPosition());
				}
			}
		}
		
		return closest;
	}
	
	public int getDistance(Position p) {
		return Math.abs(p.getX() - myPlayer().getX()) 
				+ Math.abs(p.getY() - myPlayer().getY());
	}
	
	public boolean isInGame() {
		for (RS2Object i : client.getCurrentRegion().getObjects()) {
			if (i.getName() != null 
					&& i.getName().toLowerCase().equals("lander boat")
					&& i.getPosition().distance(new Position(2657, 2639, 0)) >= 100) {
				return true;
			}
		}
		
		return false;
	}
	
	public boolean isAtStartBoat() {
		for (RS2Object i : client.getCurrentRegion().getObjects()) {
			if (i.getName() != null 
					&& i.getName().toLowerCase().equals("lander boat")
					&& distance(i.getPosition()) <= 17) {
				return true;
			}
		}
		
		//return getDistance(new Position(10722, 9907, 0)) <= 6;
		return false;
	}
	
	public boolean isOnBoat() {
		int x = myPlayer().getPosition().getX();
		int y = myPlayer().getPosition().getY();
		
		return x >= 2660 && y >= 2638 && x <= 2663 && y <= 2643
				|| x >= 2638 && y >= 2642 && x <= 2641 && y <= 2647;
	}
	
	public boolean isNearBoatEntrance() {
		return getDistance(new Position(2657, 2639, 0)) <= 16 || getDistance(new Position(2644, 2644, 0)) <= 16;
	}
	
	public boolean isAttacking() {
		return myPlayer().getFacing() != null;
	}
	
	public boolean isLoggedIn() {
		return client.getLoginState() == 30;
	}
}

This one crafts natures on Karamja using the noted essence and shop method. I wouldn't recommend using this as it was abandoned but here it is. This was the first bot I wrote for RS.


import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.util.List;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.mouse.AreaDestination;
import org.osbot.script.rs2.def.ItemDefinition;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Item;
import org.osbot.script.rs2.model.NPC;
import org.osbot.script.rs2.model.Player;
import org.osbot.script.rs2.model.RS2Object;
import org.osbot.script.rs2.skill.Skill;
import org.osbot.script.rs2.ui.Inventory;
import org.osbot.script.rs2.ui.Tab;


@ScriptManifest(author = "Mikey1", 
info = "NatureBot", 
name = "NaturesBitch", 
version = 1)

/**
 * This bot makes Nature runes using the shop method on Karamja.
 * 
 * @author Mikey1
 *
 */
public class NatureCrafter extends Script {
	
	/**
	 * The player
	 */
	private Player player;
	
	/**
	 * Player's Inventory
	 */
	private Inventory inventory;
	
	/**
	 * Debug
	 */
	private final boolean DEBUG = true;
	
	/**
	 * Mobs
	 */
	private static final int SHOP_KEEPER = 2599;
	
	/**
	 * Items
	 */
	private static final int PURE_ESSENCE = 7936;
	private static final int PURE_ESSENCE_NOTE = 7937;
	private static final int COOKED_MEAT = 2142;
	private static final int BREAD = 2309;
	private static final int ANTI_3 = 175;
	private static final int ANTI_2 = 177;
	
	/**
	 * Objects
	 */
	private static final int ALTAR_ENTRANCE = 15610;
	private static final int PORTAL_OUT = 14892;
	private static final int ALTAR = 14905;
	
	/**
	 * Fields for the script
	 */
	private final long TALK_DELAY = 60000 * 15;
	private boolean poisoned = false;
	private boolean checking = false;
	private int crafted = 0;
	private int pouched = 0;
	private double exp = 0;
	private final long start = System.currentTimeMillis();
	private String status = "Waiting..";
	private long talk = 0;
	
	/**
	 * Path from shop to altar
	 */
	private static final Loc[] WAYPOINTS_FROM_SHOP = {
		new Loc(2768, 3118),
		new Loc(2776, 3111),
		new Loc(2785, 3098),
		new Loc(2796, 3086),
		new Loc(2809, 3077),
		new Loc(2819, 3070),
		new Loc(2832, 3061),
		new Loc(2844, 3050),
		new Loc(2856, 3041),
		new Loc(2868, 3031),
		new Loc(2868, 3021),
		new Loc(2400, 4835),
		new Loc(2400, 4839),
	};
	
	/**
	 * Things to say
	 */
	private static String[] CHAT = {
		"sup",
		"hey",
	};
	
	@Override
	public void onPaint(Graphics g) {
		int y = 90;
		g.setColor(Color.WHITE);
		g.drawString("KaramjaNaturePro", 15, y - 17);
		g.drawString("Status: " + status, 15, y - 2);
		g.drawString("Runtime - " + (elapsed() / 60000) + " min", 15, y += 15);
		g.drawString("Runes/Hr - " + getAmountPerHour(crafted), 15, y += 15);
		g.drawString("Exp/Hr - " + getAmountPerHour((int) exp), 15, y += 15);
		g.drawString("Profit/Hr - " + getAmountPerHour(crafted * 200), 15, y += 15);
		g.drawString("Natures Made - " + crafted, 15, y += 15);
		g.drawString("Experience Gained - " + exp, 15, y += 15);
	}
	
	public long elapsed() {
		return System.currentTimeMillis() - start;
	}
	
	/**
	 * Get average amount per hour
	 * @param current
	 * 			the current amount of this thing
	 * @return
	 * 		the average amount per hour
	 */
	public long getAmountPerHour(int current) {
		if ((elapsed() / 60000) == 0) {
			return 0;
		}
		
		return (current / (elapsed() / 60000)) * 60;
	}
	
	
	@Override
	public void onStart() {
		log("Starting scipt..");
		
		/**
		 * Set quick references
		 */
		player = myPlayer();
		inventory = myPlayer().getClient().getInventory();
		
		/**
		 * Check pouch amounts
		 */
		try {
			checking = true;
			
			for (int j = 0; j < inventory.getItems().length; j++) {
				Item i = inventory.getItems()[j];
				if (i != null && isPouch(i.getId())) {
					
					inventory.interactWithSlot(j, "Check");
					delay();
				}
			}
			
			checking = false;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void onMessage(String s) {
		s = s.toLowerCase();
		
		try {
		
			if (checking) {
				/**
				 * We're checking how many essence are in each pouch
				 */
				if (s.contains("pouch contains")) {
					///XXX: TEST ME
					pouched += Integer.parseInt( s.substring(s.indexOf("contains") + "contains".length(), s.indexOf("essence") - 1) );
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public int onLoop() {
		/**
		 * Debug
		 */
		if (DEBUG) {
			
		}
		
		try {
		
			/**
			 * Check to activate run
			 */
			
			status = "Checking for other players..";
			
			if (isNearPlayer()) {
				if (System.currentTimeMillis() - talk >= TALK_DELAY) {
					client.typeString(CHAT[random(0, CHAT.length - 1)]);
					delay();
				}
			}
			
			status = "Running..";
			if (inventory.isFull()) {
				/**
				 * Go make natures
				 */
				status = "Inventory is full..";
				
				/**
				 * Activate run when full
				 */
				if (!this.isRunning() && hasFullEnergy()) {
					this.setRunning(true);
					delay();
				}
				
				if (inNatureAltar()) {
					status = "Making runes..";
					/**
					 * Craft runes
					 */
					craft();

				} else {
					/**
					 * Walk to nature altar
					 */
					if (isNearRuins()) {
						status = "Entering altar..";
						clickObject(ALTAR_ENTRANCE, "Enter");
						delay();
					} else {
						/**
						 * Check pouches
						 */
						while (pouched < getPouchStoreAmount() && hasItem(PURE_ESSENCE)) {
							
							for (int j = 0; j < inventory.getItems().length; j++) {
								Item i = inventory.getItems()[j];
								if (i != null && isPouch(i.getId())) {
									int before = getItemAmount(PURE_ESSENCE);
									inventory.interactWithSlot(j, "Fill");
									delay();
									int after = getItemAmount(PURE_ESSENCE);
									
									pouched += before - after;
								}
							}
						}
						
						walk(false);
					}
				}
				
			} else {
				/**
				 * Go exchange natures
				 */
				if (inNatureAltar()) {
					for (int i = 0; i < 5; i++) {
						if (pouched > 0) {
							doEmptyPouches();
							craft();
						}
					}
					
					pouched = 0;
					
					/**
					 * Exit it
					 */
					status = "Leaving altar..";
					clickObject(PORTAL_OUT, "Use");
					delay();
					
				} else {
					status = "Going to restock.";
					
					if (isShopOpen()) {
						/**
						 * Do stuff
						 */
						status = "Using shop..";
						if (isLowHealth() && !hasFood()) {
							status = "Buying food..";
							/**
							 * Buy food
							 */
							
							int i = getShopIndexForName("meat") == -1 ? getShopIndexForName("bread") : getShopIndexForName("meat");
							if (i != -1) {
								buyFromShop(i, 1);
								i = getShopIndexForName("meat") == -1 ? getShopIndexForName("bread") : getShopIndexForName("meat");
								buyFromShop(i, 1);
								i = getShopIndexForName("meat") == -1 ? getShopIndexForName("bread") : getShopIndexForName("meat");
								buyFromShop(i, 1);
								i = getShopIndexForName("meat") == -1 ? getShopIndexForName("bread") : getShopIndexForName("meat");
								buyFromShop(i, 1);
							} else {
								log("No food found!");
							}
						}
						
						if (poisoned && !hasAntiPoison()) {
							status = "Buying anti..";
							/**
							 * Buy anti
							 */
							
							int i = getShopIndexForName("anti");
							if (i != -1) {
								for (int k = 0; k < 25; k++) {
									if (!hasItem(ANTI_3)) {
										buyFromShop(i, 1);
										delay();
									}
								}
							} else {
								log("No anti found!");
							}
						}
						
						if (!isLowHealth() && !poisoned) {
							 if (!isShopCarryingEssence()) {
								status = "Selling essence..";
								/**
								 * Sell essence
								 */
								log("Selling..");
								
								int space = 28 - inventory.getFullSlots();
								
								for (int j = 0; j < inventory.getItems().length; j++) {
									Item i = inventory.getItems()[j];
									
									if (i != null) {
										log("" + i.getDefinition().getName() + " " + i.getId());
									}
									
									if (i != null && i.getId() == PURE_ESSENCE_NOTE) {
										log("Essence found.");
										for (int k = 0; k < 20; k++) {
											if (space > 0) {
												int sell = 5;
												
												if (space >= 10) {
													sell = 10;
												} else if (space >= 5) {
													sell = 5;
												}
												
												if (sell != -1) {
													status = "Interacting with essence..";
													inventory.interactWithSlot(j, "Sell " + sell);
													space -= sell;
													delay();
												}
											} else {
												log("Space is 0.");
											}
										}
										
										break;
									}
								}
								
							}
							 
							 if (isShopCarryingEssence()) {
								status = "Buying essence..";
								/**
								 * Buy essence
								 */
								
								int i = getShopIndexForName("essence");
								if (i != -1) {
									for (int k = 0; k < 25; k++) {
										if (isShopCarryingEssence()) {
											buyFromShop(i, 10);
											delay();
											if (inventory.getEmptySlots() <= 0) {
												break;
											}
										}
									}
								} else {
									log("No anti found!");
								}
							}
						}
						
						/**
						 * Close shop
						 */
						if (!isLowHealth() && !poisoned && hasItem(PURE_ESSENCE) && (inventory.isFull() || !hasItem(PURE_ESSENCE_NOTE))
								|| poisoned && hasItem(ANTI_3) 
								|| isLowHealth() && (hasItem(COOKED_MEAT) || hasItem(BREAD))) {
							/**
							 * You may close the shop, we should have what we need
							 */
							
							
							status = "Closing shop..";
							super.closeOpenInterface();
							delay();
							
							if (!isLowHealth() && !poisoned) {
								status = "Filling pouches..";
								/**
								 * Click all pouches right here, after shop is closed
								 */
							}
						}
						
						
						
					} else if (isNearStore()) {
						/**
						 * Open shop
						 */
						status = "Find npc to open shop..";
						
						NPC shop = getShop();
						if (shop != null) {
							status = "Opening shop..";
							client.moveCameraToEntity(shop);
							shop.interact("Trade");
							delay();
						} else {
							log("No shop keeper found");
							delay();
							return 0;
						}
						
						if (isLowHealth() && hasFood()) {
							status = "Eating food..";
							/**
							 * Eat the food
							 */
							for (int j = 0; j < inventory.getItems().length; j++) {
								Item i = inventory.getItems()[j];
								if (i != null && i.getId() == COOKED_MEAT || i != null && i.getId() == BREAD) {
									inventory.interactWithSlot(j, "Eat");
									delay();
								}
							}
						}
						
						if (poisoned && hasAntiPoison()) {
							status = "Curing poison..";
							/**
							 * Drink potion and drop it
							 */
							
							for (int j = 0; j < inventory.getItems().length; j++) {
								Item i = inventory.getItems()[j];
								if (i != null && i.getId() == ANTI_3) {
									inventory.interactWithSlot(j, "Drink");
									delay();
									inventory.interactWithSlot(j, "Drop");
									delay();
									
									poisoned = false;
									
									while (hasItem(ANTI_2)) {
										inventory.interactWithSlot(j, "Drop");
										delay();
									}
									
									break;
								}
							}
						}
						
						/**
						 * Check pouches
						 */
						while (pouched < getPouchStoreAmount() && hasItem(PURE_ESSENCE)) {
							
							for (int j = 0; j < inventory.getItems().length; j++) {
								Item i = inventory.getItems()[j];
								if (i != null && isPouch(i.getId())) {
									int before = getItemAmount(PURE_ESSENCE);
									inventory.interactWithSlot(j, "Fill");
									delay();
									int after = getItemAmount(PURE_ESSENCE);
									
									pouched += before - after;
								}
							}
						}
						
					} else {
						/**
						 * Walk to shop
						 */
						
						walk(true);
					}
					
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return random(507, 1078);
	}
	
	/**
	 * Methods
	 */
	
	public NPC getShop() {
		List<NPC> local = client.getLocalNPCs();
		
		for (NPC i : local) {
			if (i.getId() == SHOP_KEEPER) {
				return i;
			}
		}
		
		return null;
		
	}
	
	/**
	 * Gets the amount of essence pouches hold.
	 */
	public int getPouchStoreAmount() {
		int a = 0;
		
		if (hasItemForName("small pouch")) {
			a += 3;
		}
		
		if (hasItemForName("medium pouch")) {
			a += 6;
		}
		
		if (hasItemForName("large pouch")) {
			a += 9;
		}
		
		if (hasItemForName("giant pouch")) {
			a += 12;
		}
		
		return a;
	}
	
	/**
	 * Walk
	 * 
	 * @param reverse
	 * 				reverse path
	 * 
	 * @throws Exception
	 */
	public void walk(boolean reverse) throws Exception {
		int closest = -1;
		int dist = 0;
		
		status = "Walking..";
		
		if (player.isMoving() && player.getWalkingQueueSize() > 5) {
			return;
		}
		
		for (int k = 0; k < WAYPOINTS_FROM_SHOP.length; k++) {
			Loc i = WAYPOINTS_FROM_SHOP[k];
			if (closest == -1 || getDistance(i) < dist) {
				closest = k;
				dist = getDistance(i);
			}
		}
		
		Loc close = WAYPOINTS_FROM_SHOP[closest + (reverse ? -1 : 1)];
		if (!this.canReach(new Position(close.x, close.y, 0))) {
			close = WAYPOINTS_FROM_SHOP[closest];
			this.walk(new Position(close.x, close.y, 0));
		} else {
			this.walk(new Position(close.x, close.y, 0));
		}
		
		/**
		 * Some anti-ban
		 */
		if (!super.isRunning()) {
			if (random(0, 100) <= 9) {
				super.openTab(Tab.FRIENDS);
				Thread.sleep(random(234, 456));
				super.openTab(Tab.INVENTORY);
			} else if (random(0, 100) <= 9) {
				super.openTab(Tab.SKILLS);
				Thread.sleep(random(678, 900));
				super.openTab(Tab.INVENTORY);
			} else if (random(0, 100) <= 12) {
				client.moveCameraToPosition(new Position(player.getPosition().getX() + getWalkingOffset(),
						player.getPosition().getY() + getWalkingOffset(), 0));
			}
		}
		
		Thread.sleep(super.isRunning() ? random(890, 1090) : random(1290, 1690));
	}
	
	/**
	 * XXX: I know this is not proper, but API is so messed up
	 *  I decided to do it so I know it would be consistent
	 * Buy item from shop
	 * @param slot
	 * 			the shop slot
	 * @param amount
	 * 			
	 * @throws Exception
	 */
	public void buyFromShop(int slot, int amount) throws Exception {
		if (slot == -1) {
			delay();
			return;
		}
		
		status = "Buying item..";
		 
		int x = 93;
		int y = 75;
		
		y += (slot / 8) * 50;
		x += (slot % 8) * 48;
		
		client.moveMouse(new AreaDestination(new Area(new Rectangle(x, y, 4, 4))), true);
		delay();
		client.clickMouse(true);
		delay();
		
		y += (amount == 1 ? 40 : amount == 5 ? 55 : amount == 10 ? 70 : 40);
		client.moveMouse(new AreaDestination(new Area(new Rectangle(x, y, 4, 4))), true);
		delay();
		client.clickMouse(false);
		delay();
	}
	
	/**
	 * Delay the thread.
	 * 
	 * @throws Exception
	 */
	public void delay() throws Exception {
		Thread.sleep(random(678, 987));
	}
	
	/**
	 * Craft runes
	 * @throws Exception
	 */
	public void craft() throws Exception {
		status = "Crafting runes..";
		long essence = inventory.getAmount(PURE_ESSENCE);
		double exp1 = client.getSkills().getExperience(Skill.RUNECRAFTING);
		clickObject(ALTAR, "Craft-rune");
		delay();
		long essence2 = inventory.getAmount(PURE_ESSENCE);
		double exp2 = client.getSkills().getExperience(Skill.RUNECRAFTING);
		exp += exp2 - exp1;
		
		if (essence2 == 0) {
			crafted += essence;
		} else {
			craft();
			return;
		}
		
		delay();
	}
	
	public void doEmptyPouches() throws Exception {
		for (int j = 0; j < inventory.getItems().length; j++) {
			Item i = inventory.getItems()[j];
			if (i != null && isPouch(i.getId())) {
				int before = getItemAmount(PURE_ESSENCE);
				
				inventory.interactWithSlot(j, "Empty");
				delay();
				
				int after = getItemAmount(PURE_ESSENCE);
				
				pouched -= after - before;
			}
		}
		
		delay();
		
		if (hasItem(PURE_ESSENCE)) {
			craft();
			return;
		}
	}
	
	public void clickObject(int id, String interaction) throws Exception {
		for (RS2Object i : client.getCurrentRegion().getObjects()) {
			if (i.getId() == id) {
				client.moveCameraToEntity(i);
				i.interact(interaction);
				return;
			}
		}
	}
	
	public int getWalkingOffset() {
		return random(0, 1) == 1 ?
				random(0, 4) : -random(0, 4);
	}
	
	public int getDistance(Position p) {
		return Math.abs(p.getX() - myPlayer().getX()) 
				+ Math.abs(p.getY() - myPlayer().getY());
	}
	
	public int getDistance(Loc p) {
		return Math.abs(p.x - myPlayer().getX()) 
				+ Math.abs(p.y - myPlayer().getY());
	}
	
	public int getShopIndexForName(String name) {
		if (client.getOpenInterface() == null) {
			log("No open interface..");
			return -1;
		}
		
		for (int i = 0; i < client.getOpenInterface().getChildren().length; i++) {
			Item[] k = client.getOpenInterface().getItems(i);
			
			if (k != null) {
				int a = 0;
				for (Item j : k) {
					if (j != null && ItemDefinition.forId(j.getId()).getName() != null) {
						if (ItemDefinition.forId(j.getId()).getName().toLowerCase().contains(name)) {
							return a;
						}
					}
					a++;
				}
			}
		}
		
		return -1;
	}
	
	/**
	 * Booleans
	 */
	
	public boolean isNearPlayer() {
		List<Player> p = client.getLocalPlayers();
		
		for (Player i : p) {
			if (i != null) {
				if (!i.equals(player) && i.getPosition().distance(player.getPosition()) <= 7) {
					return true;
				}
			}
		}
		
		return false;
	}
	
	public boolean hasItem(int id) {
		Item[] i = inventory.getItems();
		
		for (Item k : i) {
			if (k != null && k.getId() == id) {
				return false;
			}
		}
		
		return false;
	}
	
	public boolean hasItemForName(String n) {
		Item[] i = inventory.getItems();
		
		for (Item k : i) {
			if (k != null && k.getDefinition().getName().toLowerCase().equals(n.toLowerCase())) {
				return false;
			}
		}
		
		return false;
	}
	
	public int getItemAmount(int id) {
		Item[] i = inventory.getItems();
		int a = 0;
		
		for (Item k : i) {
			if (k != null && k.getId() == id) {
				a++;
			}
		}
		
		return a;
	}
	
	public boolean inNatureAltar() {
		return getDistance(new Position(2400, 4835, 0)) <= 25;
	}
	
	public boolean isNearStore() {
		return getShop() != null;
	}
	
	public boolean isNearRuins() {
		return getDistance(new Position(2868, 3021, 0)) <= 6;
	}
	
	public boolean isShopOpen() {
		return client.getOpenInterface() != null;
	}
	
	public boolean isPouch(int id) {
		return ItemDefinition.forId(id).getName() != null
				&& ItemDefinition.forId(id).getName().toLowerCase().contains("pouch");
	}
	
	public boolean isLowHealth() {
		return ((double) myPlayer().getClient().getCurrentLevelStat()[3] 
				/ (double) myPlayer().getClient().getLevelStat()[3]) <= 0.95;
	}
	
	public boolean isShopCarryingEssence() {
		return getShopIndexForName("essence") != -1;
	}
	
	public boolean hasFood() {
		for (Item i : inventory.getItems()) {
			if (i != null && ItemDefinition.forId(i.getId()).getActions()[0] != null) {
				if (ItemDefinition.forId(i.getId()).getActions()[0].equals("Eat")) {
					return true;
				}
			}
		}
		
		return false;
	}
	
	public boolean hasFullEnergy() {
		return client.getRunEnergy() == 100;
	}
	
	public boolean hasAntiPoison() {
		for (Item i : inventory.getItems()) {
			if (i != null && i.getId() == ANTI_3) {
				return true;
			}
		}
		
		return false;
	}
	
	/**
	 * Shorthand Position class
	 */
	public static class Loc {
		protected int x;
		protected int y;
		
		Loc(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

}

Thanks for reading this far, enjoy!

 

 

 

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

  • 2 months later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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