My First Script Code

Posts 1–15 of 20 · Page 1 of 2
My First Script Code
Hey guys,

my first Script code for Runedev-Infinity:

Code:
import java.util.Map;
import java.awt.Image;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.JOptionPane;

import org.rsbot.bot.Bot;
import org.rsbot.client.input.Mouse;
import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.script.Constants;
import org.rsbot.script.GrandExchange;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.Skills;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSInterfaceChild;
import org.rsbot.util.ScreenshotUtil;

@ScriptManifest(authors = { "Paul L" }, name = "H[C]ooker", category = "Cooking", version = 1.0, description = "<html>\n"
		+ "<body style='font-family: Arial; background-color: navy; color:white; padding: 0px; text-align; center;'>"
		+ "<h2>"
		+ "H[C]ooker"
		+ "</h2>\n"
		+ "<b>Made by Paul L</b>\n"
		+ "<br><br>\n"
		+ "Select the Location and Start!"
		+ "<br><br>\n"
		+ "<select name='location'>"
		+ "<option>Rogue's Den"
		+ "<option>Al-kharid"
		+ "</select><br /><br/>"
		+ "<br><br>\n"
		+ "Raw Food ID: <input name='FOODID' type='text' width='10' value='' /><br />"
		+ "Cooked Food ID: <input name='COOKEDID' type='text' width='10' value='' /><br />"
		+ "<br><br>\n")
public class PaulsCooker extends Script implements PaintListener, MessageListener {

        private Bot bot;
	final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);

	final GrandExchange grandExchange = new GrandExchange();

	long runTime = 0;
	long seconds = 0;
	long minutes = 0;
	long hours = 0;
	int monkFishHour = 0;
	int currentXP = 0;
	int currentLVL = 0;
	int gainedXP = 0;
	int gainedLVL = 0;
	int xpPerHour = 0;
	int profitHour = 0;
	int stuffCooked = 0;
	public int expToLevel = 0;
	public long secToLevel = 0;
	public long minutesToLevel = 0;
	public long hoursToLevel = 0;
	public float secExp = 0;
	public float minuteExp = 0;
	public float hourExp = 0;

	public String status = "";
	private int startXP = 0;
	private int startLvl;
	public boolean showInventory = false;
	public int guyID = 2271;
	public int[] fireID = { 2732, 25730, 2724 };
	private int FOODID;
	private int COOKEDID;
	public int cost1;
	public int cost2;
	public int profit1;
	public int[] bBoothID = { 2213, 35647 };
	RSTile rogueTile = new RSTile(3044, 4972);
	RSTile bankTile = new RSTile(3270, 3168);
	RSTile boothTile = new RSTile(3268, 3168);
	RSTile rangeTile = new RSTile(3273, 3181);
	RSTile realRangeTile = new RSTile(3271, 3181);
	public long startTime = System.currentTimeMillis();
	public String location;
	final ScriptManifest info = getClass().getAnnotation(ScriptManifest.class);
	public boolean mainClick = true;

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

	protected int getMouseSpeed() {
		return random(6, 8);
	}

	public boolean onStart(Map<String, String> args) {		
		location = args.get("location");
		startLvl = skills.getCurrentSkillLevel(Skills.getStatIndex("cooking"));
		FOODID = Integer.parseInt(args.get("FOODID"));
		COOKEDID = Integer.parseInt(args.get("COOKEDID"));
		cost1 = (grandExchange.loadItemInfo(FOODID).getGuidePrice());
		cost2 = (grandExchange.loadItemInfo(COOKEDID).getGuidePrice());
		profit1 = (cost2 - cost1);
		startTime = System.currentTimeMillis();
		if (isLoggedIn()) {
			startXP = skills.getCurrentSkillExp(Skills.getStatIndex("cooking"));
		}
		return true;
	}

	public void onFinish() {
		long millis = System.currentTimeMillis() - startTime;
		long hours = millis / (1000 * 60 * 60);
		millis -= hours * (1000 * 60 * 60);
		long minutes = millis / (1000 * 60);
		millis -= minutes * (1000 * 60);
		long seconds = millis / 1000;
		int gainedXP = skills.getCurrentSkillExp(Constants.STAT_COOKING)
				- startXP;
		JOptionPane.showMessageDialog(null,
				"Thank You For Using H[C]ooker!\n"
						+ "-------------------------------------------\n"
						+ "Ran for " + hours + ":" + minutes + ":" + seconds
						+ "\n" + "Cooked " + stuffCooked + " Food\n"
						+ "Gained " + gainedLVL + " levels\n"
						+ "Your level is "
						+ skills.getCurrentSkillLevel(Constants.STAT_COOKING)
						+ "\n" + "Gained " + gainedXP + "XP\n"
						+ "-------------------------------------------");

	}

	@Override
	public int loop() {
		if (location.equals("Al-kharid")) {
			return loop2();
		}
		setCameraAltitude(true);
		if (bank.getCount(FOODID) == 0 && bank.isOpen() && !inventoryContains(FOODID)) {
			wait(random(600, 1000));
			if(bank.getCount(FOODID) == 0 && !inventoryContains(FOODID)){
			ScreenshotUtil.takeScreenshot(bot, true);
			log("Nothing left to cook. brb, going to have sex!");
			logOut();
		}
		}
		if (getMyPlayer().getAnimation() != -1) {
			status = "Cooking";
			wait(random(1200, 1600));
			antiBan();
		}
		if (inventoryContains(FOODID) && getMyPlayer().getAnimation() == -1) {
			cook();
		}
		if (!inventoryContains(FOODID)) {
			bank();
		}
		return 0;
	}

	public int loop2() {
		setCameraAltitude(true);
		if (getMyPlayer().getAnimation() != -1) {
			status = "Cooking";
			wait(random(500, 2000));
			antiBan();
		}
		if (bank.getCount(FOODID) == 0 && bank.isOpen() && !inventoryContains(FOODID)) {
			wait(random(600, 1000));
			if(bank.getCount(FOODID) == 0 && !inventoryContains(FOODID)){
			ScreenshotUtil.takeScreenshot(bot, true);
			log("Nothing left to cook. brb, going to have sex!");
			logOut();
		}
		}
		if (inventoryContains(FOODID) && getMyPlayer().getAnimation() == -1) {
			if (atRange()) {
				cook();
			} else if (!atRange() && !getMyPlayer().isMoving()) {
				status = "Walking to Range";
				walkTileMiniM(rangeTile);
				wait(random(1, 900));
				antiBan();
				return random(2000, 2500);
			}
			while (getMyPlayer().isMoving()) {
				wait(random(300, 600));
			}
		}
		if (!inventoryContains(FOODID)) {
			if (atBank()) {
				bank();
			} else if (!atBank() && !getMyPlayer().isMoving()) {
				status = "Walking to Bank";
				walkTileMiniM(bankTile);
				wait(random(1, 700));
				antiBan();
				return random(1000, 1400);
			}
			while (getMyPlayer().isMoving()) {
				wait(random(300, 600));
			}
		}
		return 0;
	}

	public void bank() {

		// Rouge's Den
		if (location.equals("Rogue's Den")) {
			final RSNPC guy = getNearestNPCByID(guyID);
			if (guy.isOnScreen()) {
				mainClick = true;
				final RSNPC bBooth = getNearestNPCByName("Emerald Benedict");
				if (bank.isOpen()) {
					status = "Depositing";
					if (getInventoryCount() != 0) {
						bank.depositAll();
					}
					wait(random(300, 400));
					bank.atItem(FOODID, "Withdraw-All");
					wait(random(300, 400));
					bank.close();
				} else if (!bank.isOpen()) {
					if(isItemSelected()){
						moveMouse(644, 170, 10, 10);
						clickMouse(true);
					}
					status = "Opening Bank";
					clickRSNPC(bBooth, "Bank");
					wait(random(200, 300));
				}
			} else if (!guy.isOnScreen()) {
				walkTo(guy.getLocation());
			}
		}

		// Al-Kharid
		if (location.equals("Al-kharid")) {
			final RSObject bBooth = getNearestObjectByID(bBoothID);
			if (bank.isOpen()) {
				status = "Depositing";
				if (getInventoryCount() != 0) {
					bank.depositAll();
				}
				wait(random(400, 500));
				bank.atItem(FOODID, "Withdraw-All");
				wait(random(500, 600));
			}
			if (distanceTo(bBooth) <= 4) {
				if (!bank.isOpen()) {
					if (bBooth != null) {
						atTile(boothTile, "Use-Quickly");
						waitForIface(bank.getInterface(), 3000);
					}
				}
			}
		}
	}

	public void cook() {
		if (!mainClick) {
			wait(random(600, 700));
			if (getMyPlayer().getAnimation() != -1) {
				wait(random(200, 300));
			}
		} else {
			mainClick = false;
		}
		if (getMyPlayer().getAnimation() == -1) {

			// Rouge's Den
			if (location.equals("Rogue's Den")) {
				final RSObject fire = getNearestObjectByID(fireID);
				if (distanceTo(fire) <= 4) {
					if (fire != null) {
						status = "Trying to cook";
						if (!isItemSelected() && getMyPlayer().getAnimation() == -1) {
							moveMouse(578, 230, 8, 8);
							wait(random(20, 300));
							atMenu("Use");
							wait(random(60, 400));
						}
						if (isItemSelected() && getMyPlayer().getAnimation() == -1) {
							atObject(fire, "Fire");
							wait(random(1700, 1800));
							moveMouse(244, 394, 30, 30);
							wait(random(100, 200));
							atMenu("Cook All");
							wait(random(1600, 2000));
						}
					}
				} else if (distanceTo(fire) >= 5) {
					walkTo(fire.getLocation());
				}
			}

			// Al-Kharid
			if (location.equals("Al-kharid")) {
				final RSObject range = getNearestObjectByID(fireID);
				if (range != null) {
					status = "Trying to cook";
					if (!isItemSelected()) {
						moveMouse(578, 230, 8, 8);
						wait(random(20, 300));
						atMenu("Use");
						wait(random(60, 400));
					}
					if (isItemSelected()) {
						atTile(realRangeTile, "Range");
						wait(random(500, 600));
						moveMouse(244, 394, 30, 30);
						waitForIface(getInterface(905), 4000);
						wait(random(100, 200));
						atMenu("Cook All");
						wait(random(1600, 2000));
					}
				}
			}
		}
	}

	public void waitToStop() {
		while (getMyPlayer().isMoving()) {
			wait(100);
		}
	}

	public boolean atNedHouse() {
		return getMyPlayer().getLocation().getX() <= 3101
				&& getMyPlayer().getLocation().getX() >= 3095
				&& getMyPlayer().getLocation().getY() <= 3260
				&& getMyPlayer().getLocation().getY() >= 3256;
	}

	public void logOut() {
		moveMouse(754, 10, 10, 10);
		clickMouse(true);
		moveMouse(642, 378, 20, 15);
		clickMouse(true);
		wait(random(2000, 3000));
		stopScript();
	}

	public boolean atRogue() {
		return distanceTo(rogueTile) <= 6;
	}

	public boolean atBank() {
		return distanceTo(bankTile) <= 6;
	}

	public boolean atRange() {
		return distanceTo(rangeTile) <= 4;
	}

	public boolean antiBan() {
		int randomNumber = random(1, 20);
		if (randomNumber <= 18) {
			if (randomNumber == 1) {
				randomHoverPlayer();
			}
			if (randomNumber == 2) {
				moveMouse(random(50, 700), random(50, 450), 2, 2);
				wait(random(1000, 1500));
				moveMouse(random(50, 700), random(50, 450), 2, 2);
			}
			if (randomNumber == 3) {
				openRandomTab();
				wait(random(100, 500));
				moveMouse(522, 188, 220, 360);
				wait(random(500, 2800));
			}
			if (randomNumber == 4) {
				wait(random(100, 200));
				moveMouse(random(50, 700), random(50, 450), 2, 2);
				setCameraRotation(random(1, 360));
				moveMouse(random(50, 700), random(50, 450), 2, 2);
			}
			if (randomNumber == 6) {
				moveMouse(random(50, 700), random(50, 450), 2, 2);
			}
			if (randomNumber == 7) {
				moveMouse(random(50, 700), random(50, 450), 2, 2);
			}
			if (randomNumber == 8) {
				wait(random(100, 200));
				moveMouse(random(50, 700), random(50, 450), 2, 2);
				wait(random(200, 500));
				if (randomNumber == 9) {
					wait(random(100, 200));
					moveMouse(random(50, 700), random(50, 450), 2, 2);
					if (randomNumber == 10) {
						moveMouse(random(50, 700), random(50, 450), 2, 2);
					}
					if (randomNumber == 11) {
						setCameraRotation(random(1, 360));
						moveMouse(random(50, 700), random(50, 450), 2, 2);
					}
					if (randomNumber == 12) {
						openTab(TAB_STATS);
						wait(random(50, 100));
						moveMouse(675, 268, 20, 20);
						wait(random(500, 1700));
					}
					if (randomNumber == 13) {
						moveMouse(random(50, 700), random(50, 450), 2, 2);
						setCameraRotation(random(1, 360));
					}
					if (randomNumber == 14) {
						openTab(TAB_STATS);
						wait(random(50, 100));
						moveMouse(675, 268, 20, 20);
						wait(random(500, 1700));
					}
					if (randomNumber == 15) {
						randomHoverPlayer();
					}
				}

			}
		}
		return true;
	}

	public boolean antiBan2() {
		int randomNumber = random(1, 18);
		if (randomNumber <= 12) {
			if (randomNumber == 1) {
				setCameraRotation(random(1, 360));
			}
			if (randomNumber == 2) {
				moveMouse(random(50, 700), random(50, 450), 2, 2);
				wait(random(200, 300));
				moveMouse(random(50, 700), random(50, 450), 2, 2);
			}
			if (randomNumber == 3) {
				moveMouse(522, 188, 220, 360);
			}
			if (randomNumber == 4) {
				setCameraRotation(random(1, 360));
				moveMouse(random(50, 700), random(50, 450), 2, 2);
			}
			if (randomNumber == 6) {
				moveMouse(random(50, 700), random(50, 450), 2, 2);
			}
			if (randomNumber == 7) {
				moveMouse(random(50, 700), random(50, 450), 2, 2);
			}
		}
		return true;
	}

	private void randomHoverPlayer() {
		int randomNumber = random(1, 15);
		if (randomNumber <= 10) {
			if (randomNumber == 1) {
				RSPlayer p = getNearestPlayerByLevel(1, 130);
				if ((p != null) && tileOnScreen(p.getLocation())) {
					moveMouse(p.getScreenLocation(), 40, 40);
					wait(random(450, 650));
				}
				if (randomNumber == 2) {
					if ((p != null) && tileOnScreen(p.getLocation())) {
						moveMouse(p.getScreenLocation(), 40, 40);
						wait(random(100, 400));
						clickMouse(false);
						wait(random(1000, 1700));
						moveMouse(random(50, 700), random(50, 450), 2, 2);
					}
				}
			}
		}
	}

	private void openRandomTab() {
		int randomNumber = random(1, 20);
		if (randomNumber <= 11) {
			if (randomNumber == 1) {
				openTab(TAB_STATS);
				wait(random(100, 200));
				moveMouse(675, 268, 20, 20);
				wait(random(500, 1700));
			}
			if (randomNumber == 2) {
				openTab(TAB_ATTACK);
			}
			if (randomNumber == 3) {
				openTab(TAB_EQUIPMENT);
			}
			if (randomNumber == 4) {
				openTab(TAB_FRIENDS);
			}
			if (randomNumber == 6) {
				openTab(TAB_MAGIC);
			}
			if (randomNumber == 7) {
				openTab(TAB_STATS);
			}
			if (randomNumber == 8) {
				openTab(TAB_QUESTS);
			}
			if (randomNumber == 9) {
				openTab(TAB_CLAN);
			}
			if (randomNumber == 10) {
				openTab(TAB_MUSIC);
			}
			if (randomNumber == 11) {
				openTab(TAB_ACHIEVEMENTDIARIES);
			}
		}
	}

	public int getProfitGain() {
        	int profit = (profit1 * (stuffCooked));
        	return (int) ((3600000.0 / (double) (System.currentTimeMillis() - startTime)) * profit);
	}


    private final Color color1 = new Color(0, 0, 0, 130);
    private final Color color2 = new Color(0, 0, 0, 175);
    private final Color color3 = new Color(255, 255, 255);

    private final Font font1 = new Font("Comic Sans MS", 1, 14);
    private final Font font2 = new Font("Comic Sans MS", 0, 11);

    private final Image img1 = getImage("http://images.brighthub.com/84/2/842302f9b40257d13cbb5e8fb2890030cb92adc0_small.jpg");


	public void onRepaint(Graphics g) {
		runTime = System.currentTimeMillis() - startTime;
		seconds = runTime / 1000;
		if (seconds >= 60) {
			minutes = seconds / 60;
			seconds -= (minutes * 60);
		}
		if (minutes >= 60) {
			hours = minutes / 60;
			minutes -= (hours * 60);
		}

		currentXP = skills.getCurrentSkillExp(Skills.getStatIndex("cooking"));
		currentLVL = skills.getCurrentSkillLevel(Skills.getStatIndex("cooking"));
		gainedXP = currentXP - startXP;
		gainedLVL = currentLVL - startLvl;
		xpPerHour = (int) ((3600000.0 / (double) runTime) * gainedXP);
		monkFishHour = (int) ((3600000.0 / (double) runTime) * stuffCooked);
	        g.setColor(color1);
        	g.fillRect(0, 1, 154, 148);
        	g.setColor(color2);
        	g.fillRect(0, 0, 154, 49);
        	g.setFont(font1);
        	g.setColor(color3);
        	g.drawString("H[C]ooker", 66, 37);
        	g.drawString("Paul L ", 44, 17);
        	g.setFont(font2);
        	g.drawString("Current Lvl: " + currentLVL, 6, 95);
        	g.drawString("XP Per Hr: " + xpPerHour, 6, 65);
        	g.drawString("Profit/Hr: " + getProfitGain(), 6, 75);
        	g.drawString("Cooked/Hr: " + monkFishHour, 6, 85);
        	g.drawString("Lvls Gained: " + gainedLVL, 6, 105);
        	g.drawString("XP TNL: " + skills.getXPToNextLevel(Skills.getStatIndex("cooking")), 6, 115);
		g.drawString("% TNL: " + skills.getPercentToNextLevel(Skills.getStatIndex("cooking")), 6, 125);
        	g.drawString("Status: " + status, 5, 135);
        	g.drawString("Runtime: " + hours + ":" + minutes + ":" + seconds, 6, 145);
        	g.drawImage(img1, 1, -2, null);
				if (hours == 2 && minutes == 0 && seconds == 0) {
					log("w00t! ran for 2 hours! taking screenie :)");
					ScreenshotUtil.takeScreenshot(bot, true);
				}
				if (hours == 3 && minutes == 0 && seconds == 0) {
					log("awesome! ran for 3 hours! taking screenie :)");
					ScreenshotUtil.takeScreenshot(bot, true);
				}
				if (hours == 4 && minutes == 0 && seconds == 0) {
					log("Epic! ran for 4 hours! taking screenie :)");
					ScreenshotUtil.takeScreenshot(bot, true);
				}
				if (hours == 5 && minutes == 0 && seconds == 0) {
					log("Hell yeaH! ran for 5 hours! taking screenie :)");
					ScreenshotUtil.takeScreenshot(bot, true);
				}
				if (hours == 6 && minutes == 0 && seconds == 0) {
					log("keep it up! ran for 6 hours! taking screenie :)");
					ScreenshotUtil.takeScreenshot(bot, true);
				}
				if (hours == 7 && minutes == 0 && seconds == 0) {
					log("NICE NICE! ran for 7 hours! taking screenie :)");
					ScreenshotUtil.takeScreenshot(bot, true);
				}
				if (hours == 8 && minutes == 0 && seconds == 0) {
					log("SICK! ran for 8 hours! taking screenie :)");
					ScreenshotUtil.takeScreenshot(bot, true);
				}
				if (hours == 9 && minutes == 0 && seconds == 0) {
					log("DA PERFECT PROGGY! ran for 9 hours! taking screenie :)");
					ScreenshotUtil.takeScreenshot(bot, true);
				}
				if (hours == 10 && minutes == 0 && seconds == 0) {
					log("FUCKING AWESOME DUDE! ran for 10 hours! taking screenie :) fuck me!");
					ScreenshotUtil.takeScreenshot(bot, true);
		}
	}

	@Override
	public void messageReceived(MessageEvent e) {
		final String serverString = e.getMessage();
		if (serverString.contains("cook") || serverString.contains("roast") || serverString.contains("bake")) {
			stuffCooked++;
		}
		if (serverString.contains("You've just advanced a level!! w00t :D")) {
			log("Congrats on level up, Screenshot taken!");
			ScreenshotUtil.takeScreenshot(bot, true);
			wait(random(1500, 2500));
			if (canContinue()) {
				clickContinue();
			}
		}
	}
}

its basically the same principe as the bot from rsbots.net has

do you like it?
well i dont no scripting but make a jar for the elite to use and test
You didnt mention what it does, though in the code it says [H]Cooker
what exactly does your script do?
it is cooking for you
Quote Originally Posted by [H]arris View Post
it is cooking for you
I see does it cook a vast amount of food or does it focus mainly on one type of food
It's not hard to leech a cooking code and put your name into it.
Quote Originally Posted by Terell. View Post
It's not hard to leech a cooking code and put your name into it.
give me the script its leeched from
Hmm, what places it supports and what sorts of food?
supports al-kharid and rougue's Den.

Supports almost all fishes
Quote Originally Posted by [H]arris View Post
supports al-kharid and rougue's Den.

Supports almost all fishes
, to bad i only use Rsbuddy and i'm way to lazy to download any other Oo
Quote Originally Posted by iMexi View Post
, to bad i only use Rsbuddy and i'm way to lazy to download any other Oo
your fault
Suppose it is his fault
So, this is powerbot right? or rsbud,
Quote Originally Posted by Son Goku View Post
Suppose it is his fault
So, this is powerbot right? or rsbud,
it is runedev
Makes sense, although i haven't used it
Posts 1–15 of 20 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us