Jump to content

Fire making/Cooking script not running all help appreciated


kushroom

Recommended Posts

Hey guys, long time coder for osbot, long ago lost my old account, quit runescape. Finally decieded to come back nd check out the oldschool scene. So i figured save up get a bond nd possibly get back into it, or at the very least make some scripts to release for the community for all the years ive used this wonderful service that the community provides! Im working on a script that starts a fire at the ge in the locations that are able to hold fires. Than itll cook the food on that, and loop back in forth, so far I just started it but unfortunately it doesnt log anything, sits there and lags out the client very hard! If anyone could look at my methods for getting the fire and reading thru the rest to make sure im not over looking anything. All help is very much appreciated! Once the script is 100% flawless id like to release it for free for the public so I can start giving back. After this script is complete ill get to working on a ge bot that i had started a long time before and get it running so everyone can make maximum profits! Thank you guys so much for the years of support and all the help ive recieved!

 

My GECooker script:
 

package com.embah.GECooker;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "GECooker", author = "Kushroom", version = 1.0, info = "Cooks food at the Grand Exchange", logo = "")
public class GECooker extends Script{
	private final int burningLog = 26185;
	private final int[] banker_ID = {5453, 5454, 5455, 5456};
	private final Area fireZone = new Area(3161,3486,3167,3492);
	private Position[] fireSpots = {
			new Position(3166,3492,0),
			new Position(3163, 3492, 0), 
			new Position(3162, 3492, 0),
			new Position(3162, 3491, 0),
			new Position(3161, 3490, 0),
			new Position(3161, 3489, 0),
			new Position(3162, 3488, 0),
			new Position(3162, 3487, 0),
			new Position(3163, 3487, 0),
			new Position(3164, 3486, 0),
			new Position(3165, 3486, 0),
			new Position(3166, 3487, 0),
			new Position(3167, 3487, 0),
			new Position(3167, 3488, 0),
			new Position(3168, 3489, 0),
			new Position(3168, 3490, 0),
			new Position(3167, 3491, 0),
			new Position(3167, 3492, 0),
			new Position(3166, 3492, 0),
			new Position(3165, 3493, 0),
			new Position(3164, 3493, 0),
			new Position(3163, 3492, 0)};
	private final int tinder_ID = 590;
	private int raw_ID = 359;
	private int cooked_ID = 361;
	private int burnt_ID = 367;
	private int log_ID = 1521;
	private Random r = new Random();

	@[member=Override]
	public int onLoop() throws InterruptedException {
		if(getInventory().contains(raw_ID) && getInventory().contains(tinder_ID) && getInventory().contains(log_ID) && !myPlayer().isAnimating()){
			if(bank.isOpen()){
				bank.close();
				sleep(r.nextInt(250) + 350);
			}
			log("Looking for fire");
			Position nearestFire = getNearestFire();
			List<RS2Object> objLoc = objects.get(nearestFire.getX(), nearestFire.getY());
			boolean fireFound = false;
			for(int i=0;i<objLoc.size();i++){
				if(objLoc.get(i).getName().equals("Fire")){		
					fireFound = true;
				}
			}
			log("walking to fire if one isnt found");
			if(fireFound == false){
				walking.getWalking().walk(getNearestFire()); 
				sleep(r.nextInt(250) + 100);
				getInventory().getItem(tinder_ID).interact("Use");
				sleep(r.nextInt(125) + 100);
				getInventory().getItem(log_ID).interact("Use");
				sleep(r.nextInt(250) + 100);
			}
			log("Cooking on fire");
			getInventory().getItem(raw_ID).interact("Use");
			sleep(r.nextInt(250) + 100);
			nearestFire = getNearestFire();
			objLoc = objects.get(nearestFire.getX(), nearestFire.getY());
			for(int i=0;i<objLoc.size();i++){
				if(objLoc.get(i).getName().equals("Fire")){		
					objLoc.get(i).interact("-> Fire");
					sleep(r.nextInt(150) + 300);
				}
			}
			widgets.get(307, 4).interact("Cook All");
		}
		
		
		if(!myPlayer().isAnimating() && (!getInventory().contains(raw_ID) || !getInventory().contains(log_ID))){
			int tin = 0;
			int raw = 0;
			int cook = 0;
			int burnt = 0;
			int log = 0;
			while(!bank.isOpen()){
				bank.open();
				sleep(r.nextInt(200) + 150);
			}
			if(inventory.contains(burnt_ID)){
				if(inventory.getAmount(burnt_ID) > 1){
					bank.depositAll(burnt_ID);
					sleep(r.nextInt(200) + 150);
				} else if(inventory.getAmount(burnt_ID) == 1){
					bank.deposit(burnt_ID, 1);
					sleep(r.nextInt(200) + 150);
				}
			}
			if(inventory.contains(cooked_ID)){
				bank.depositAll(cooked_ID);
				sleep(r.nextInt(200) + 150);
			}
			if(!inventory.contains(tinder_ID)){
				bank.withdraw(tinder_ID, 1);
				sleep(r.nextInt(200) + 150);
			}
			if(!inventory.contains(log_ID)){
				bank.withdraw(log_ID, 1);
				sleep(r.nextInt(200) + 150);
			}
			if(!inventory.isFull()){
				bank.withdrawAll(raw_ID);
				sleep(r.nextInt(200) + 150);
			}
		}
		return r.nextInt(r.nextInt(150) + 200); //100 to 200 fireZone.contains(myPlayer().getPosition())
	}
	
	@[member=Override]
	public void onStart(){
		log("Starting GECooker by Kushroom \"Private\"");
	}
	
	@[member=Override]
	public void onExit(){
		
	}
	
	@[member=Override]
	public void onPaint(Graphics2D g){
		
	}
	
	private Position getNearestFire(){
		ArrayList<Position> matched = new ArrayList<Position>();
		int dist = 513;
		int objIndex = 0;
		
		List<Position> pos = fireZone.getPositions();
		for(int i=0;i<pos.size();i++){
			for(int j=0;j<fireSpots.length;j++){
				if(pos.get(i) == fireSpots[j]){
					matched.add(fireSpots[j]);
					int temp = map.distance(fireSpots[j]);
					if(temp < dist){
						dist = temp;
						objIndex = matched.size() - 1;
					}
				}
			}
		}
		return matched.get(objIndex);
	}

	private boolean isAnimating(){
		return myPlayer().getAnimation() == 0;
	}
	
	private boolean itemSelected(){
		String name = null;
		try {
			name = getInventory().getSelectedItemName();
		} catch (Exception e){}
		return name != null;
	}
}

Link to comment
Share on other sites

private Position getNearestFire(){
		ArrayList<Position> matched = new ArrayList<Position>();
		int dist = 513;
		int objIndex = 0;
		
		List<Position> pos = fireZone.getPositions();
		for(int i=0;i<pos.size();i++){
			for(int j=0;j<fireSpots.length;j++){
				if(pos.get(i) == fireSpots[j]){
					matched.add(fireSpots[j]);
					int temp = map.distance(fireSpots[j]);
					if(temp < dist){
						dist = temp;
						objIndex = matched.size() - 1;
					}
				}
			}
		}
		return matched.get(objIndex);
	}

??????

 

http://osbot.org/api/org/osbot/rs07/api/EntityAPI.html#closest-org.osbot.rs07.api.map.Area-java.lang.String...-

 

RS2Object fire_inside_area = getObjects().closest(fireZone, "Fire");

 

This is probably the first error you are getting i'm not sure though, there is a lot of stuff wrong / inefficient through out your code :l

When you are trying to find solutions for things to be done in your script try referring to the API docs.

 

You also keep calling getNearestFire() over and over again, you could just call it once per loop and store it in a variable.

private Position[] fireSpots = {
			new Position(3166,3492,0),
			new Position(3163, 3492, 0), 
			new Position(3162, 3492, 0),
			new Position(3162, 3491, 0),
			new Position(3161, 3490, 0),
			new Position(3161, 3489, 0),
			new Position(3162, 3488, 0),
			new Position(3162, 3487, 0),
			new Position(3163, 3487, 0),
			new Position(3164, 3486, 0),
			new Position(3165, 3486, 0),
			new Position(3166, 3487, 0),
			new Position(3167, 3487, 0),
			new Position(3167, 3488, 0),
			new Position(3168, 3489, 0),
			new Position(3168, 3490, 0),
			new Position(3167, 3491, 0),
			new Position(3167, 3492, 0),
			new Position(3166, 3492, 0),
			new Position(3165, 3493, 0),
			new Position(3164, 3493, 0),
			new Position(3163, 3492, 0)}; 

^ just declare an area you can light a fire in and get a random / nearest position inside it instead

 

Also use item names rather than ids which are subject to possibly change over time.

 

Look into ConditionalSleep rather than all those static sleeps as sell. http://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html

 

Edited by House
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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