Jump to content

Need Help With First Script


edoggydogg

Recommended Posts

import java.awt.Graphics2D;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.ui.EquipmentSlot;

@ScriptManifest(author = "edoggydogg", info = "Welcome to my very first script!", logo = "", name = "eIron", version = 0.1)
public class main extends Script {

	Position GOODAREA = new Position(random(3683, 3686), random(3478, 3480), 0);
	Position BANKAREA = new Position(random(3687, 3690), random(3466, 3469), 0);

	// code used on start
	public void onStart() {
		log("Welcome to eIron.");
		log("Please begin the script in Port P. Bank");
		log("If any problems occur, please report them to me.");

		camera.toTop();
		camera.moveYaw(random(1, 5));

	}

	private enum state {
		BADAREA, GOODAREA, SMELT, WAIT, BANKAREA, BANK
	};

	public state getState() {
		if (inventory.isEmpty())
			return state.BANK;
		if (inventory.onlyContains(2351))
			return state.BANK;
		if (inventory.onlyContains(440))
			return state.SMELT;
		return state.BANK;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case SMELT:
			localWalker.walk(GOODAREA);
			if (inventory.onlyContains(440)) {
				objects.closest(24009).interact("Smelt");
				sleep(random(1000, 2000));
				mouse.move(random(130, 170), random(400, 440));
				mouse.click(random(130, 170), random(400, 440), true);
				sleep(random(1000, 2000));
				mouse.move(random(130, 170), random(471, 480));
				mouse.click(random(130, 170), random(471, 480), false);
				sleep(random(1000, 2000));
				keyboard.typeString("99", true);
				mouse.moveOutsideScreen();
				sleep(random(85000, 88000));
			}
			break;
		case BANK:
			localWalker.walk(BANKAREA);
			if (inventory.isEmpty()) {
				if (equipment.isWearingItem(EquipmentSlot.RING)) {
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
				} else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.withdraw(2568, 1);
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
					equipment.equip(EquipmentSlot.RING, 2568);
					sleep(random(1500, 2000));
				}
			} else {
				if (equipment.isWearingItem(EquipmentSlot.RING)) {
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.depositAll();
					sleep(random(1500, 2000));
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
				} else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.depositAll();
					sleep(random(1500, 2000));
					bank.withdraw(2568, 1);
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
					equipment.equip(EquipmentSlot.RING, 2568);
					sleep(random(1500, 2000));
				}
			}
			break;
		case WAIT:
			sleep(random(200, 300));
			break;
		default:
			break;
		}
		return random(200, 300);
	}

	// code used on exit
	public void onExit() {
		log("Thank you for using eIron");

	}

	// paint
	public void onPaint(Graphics2D g) {

	}
}
Added code is in green. You forgot to make it only withdraw a ring if it doesn't have one. Your code was saying: if you're wearing ring, bank for ore. Then, bank for ring (without even checking if has ring or not). I made it so it will check if it has ring, then withdraw ore, if not, withdraw ring.

Sorry if I didn't explain myself well enough, if you need any more help just ask.

 

EDIT: Make sure to format your code! It was confusing at first, but just hit CTRL + SHIFT + F to automatically format code in Eclipse IDE.

Edited by Czar
Link to comment
Share on other sites

import java.awt.Graphics2D;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.ui.EquipmentSlot;

@ScriptManifest(author = "edoggydogg", info = "Welcome to my very first script!", logo = "", name = "eIron", version = 0.1)
public class main extends Script {

	Position GOODAREA = new Position(random(3683, 3686), random(3478, 3480), 0);
	Position BANKAREA = new Position(random(3687, 3690), random(3466, 3469), 0);

	// code used on start
	public void onStart() {
		log("Welcome to eIron.");
		log("Please begin the script in Port P. Bank");
		log("If any problems occur, please report them to me.");

		camera.toTop();
		camera.moveYaw(random(1, 5));

	}

	private enum state {
		BADAREA, GOODAREA, SMELT, WAIT, BANKAREA, BANK
	};

	public state getState() {
		if (inventory.isEmpty())
			return state.BANK;
		if (inventory.onlyContains(2351))
			return state.BANK;
		if (inventory.onlyContains(440))
			return state.SMELT;
		return state.BANK;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case SMELT:
			localWalker.walk(GOODAREA);
			if (inventory.onlyContains(440)) {
				objects.closest(24009).interact("Smelt");
				sleep(random(1000, 2000));
				mouse.move(random(130, 170), random(400, 440));
				mouse.click(random(130, 170), random(400, 440), true);
				sleep(random(1000, 2000));
				mouse.move(random(130, 170), random(471, 480));
				mouse.click(random(130, 170), random(471, 480), false);
				sleep(random(1000, 2000));
				keyboard.typeString("99", true);
				mouse.moveOutsideScreen();
				sleep(random(85000, 88000));
			}
			break;
		case BANK:
			localWalker.walk(BANKAREA);
			if (inventory.isEmpty()) {
				if (equipment.isWearingItem(EquipmentSlot.RING)) {
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
				} else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.withdraw(2568, 1);
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
					equipment.equip(EquipmentSlot.RING, 2568);
					sleep(random(1500, 2000));
				}
			} else {
				if (equipment.isWearingItem(EquipmentSlot.RING)) {
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.depositAll();
					sleep(random(1500, 2000));
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
				} else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.depositAll();
					sleep(random(1500, 2000));
					bank.withdraw(2568, 1);
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
					equipment.equip(EquipmentSlot.RING, 2568);
					sleep(random(1500, 2000));
				}
			}
			break;
		case WAIT:
			sleep(random(200, 300));
			break;
		default:
			break;
		}
		return random(200, 300);
	}

	// code used on exit
	public void onExit() {
		log("Thank you for using eIron");

	}

	// paint
	public void onPaint(Graphics2D g) {

	}
}
Added code is in green. You forgot to make it only withdraw a ring if it doesn't have one. Your code was saying: if you're wearing ring, bank for ore. Then, bank for ring (without even checking if has ring or not). I made it so it will check if it has ring, then withdraw ore, if not, withdraw ring.

Sorry if I didn't explain myself well enough, if you need any more help just ask.

 

EDIT: Make sure to format your code! It was confusing at first, but just hit CTRL + SHIFT + F to automatically format code in Eclipse IDE.

 

Yeah I completely understand, I had the else statement in there before but it caused an error i forgot what exactly and i guess i forgot to put it back in, but thank you!

Link to comment
Share on other sites

Did osbot loose the ability to interact with widgets?

+ the lack of checks is intense

Naw chill we still can, they innovated it. They created an interaction event class that allows us to interact with almost anything entity, interfaces, and others Edited by josedpay
Link to comment
Share on other sites

	} else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.depositAll();
					sleep(random(1500, 2000));
					bank.withdraw(2568, 1);
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
					equipment.equip(EquipmentSlot.RING, 2568);
					sleep(random(1500, 2000));

Is this real life?

 

Please tell me you didn't go through with using this....

 

No I will no provide anything helpful because everything you do here should be obvious for ANYONE who spent a small amount of time actually learning Java instead of thinking "Hey I want be popular, so I should start writing scripts.", so please do everyone a favor and start reading.

 

I even took the first step for you: http://www.ibm.com/developerworks/java/tutorials/j-introtojava1/

  • Like 1
Link to comment
Share on other sites

	} else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.depositAll();
					sleep(random(1500, 2000));
					bank.withdraw(2568, 1);
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
					equipment.equip(EquipmentSlot.RING, 2568);
					sleep(random(1500, 2000));

Is this real life?

 

Please tell me you didn't go through with using this....

 

No I will no provide anything helpful because everything you do here should be obvious for ANYONE who spent a small amount of time actually learning Java instead of thinking "Hey I want be popular, so I should start writing scripts.", so please do everyone a favor and start reading.

 

I even took the first step for you: http://www.ibm.com/developerworks/java/tutorials/j-introtojava1/

 

Lool, nah we improved it :D

Link to comment
Share on other sites

	} else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22
					objects.closest(16642).interact("Bank");
					sleep(random(1500, 2000));
					bank.depositAll();
					sleep(random(1500, 2000));
					bank.withdraw(2568, 1);
					bank.withdrawAll(440);
					sleep(random(1500, 2000));
					bank.close();
					sleep(random(1500, 2000));
					equipment.equip(EquipmentSlot.RING, 2568);
					sleep(random(1500, 2000));

Is this real life?

 

Please tell me you didn't go through with using this....

 

No I will no provide anything helpful because everything you do here should be obvious for ANYONE who spent a small amount of time actually learning Java instead of thinking "Hey I want be popular, so I should start writing scripts.", so please do everyone a favor and start reading.

 

I even took the first step for you: http://www.ibm.com/developerworks/java/tutorials/j-introtojava1/

 

Clearly you failed to read the first post where I stated I already am getting assistance. You assume I want to be "popular" on an online forum because I am trying to write my own script. Hmm thats great logic. It was a waste of both your time and my time for you to write a comment like you did. Enjoy your popularity on these forums haha, this was just meant as a side project for myself.

Link to comment
Share on other sites

Seriously though. If you want your script be to be stable, always assume that any action has a chance to fail.

As a result of this, doing multiple things successively without checking what the current situation is, is generally a bad idea.

 

Example (pseudo):

bank.open();

sleep

bank.withdraw();

 

Assume that even after the call to bank.open(), the bank is still not open. An action can fail as a result of multiple factors. Most often being misclicks (caused by camera movements or whatnot), random event interrupt (Yes, they still interrupt your current action), lag or delays. For this reason, it's common practice to return from the main loop after every action, repeating the same action if it was not completed successfully in the previous loop.

Link to comment
Share on other sites

Seriously though. If you want your script be to be stable, always assume that any action has a chance to fail.

As a result of this, doing multiple things successively without checking what the current situation is, is generally a bad idea.

 

Example (pseudo):

bank.open();

sleep

bank.withdraw();

 

Assume that even after the call to bank.open(), the bank is still not open. An action can fail as a result of multiple factors. Most often being misclicks (caused by camera movements or whatnot), random event interrupt (Yes, they still interrupt your current action), lag or delays. For this reason, it's common practice to return from the main loop after every action, repeating the same action if it was not completed successfully in the previous loop.

Yea I understand I will make sure to go back and include checks for those kinds of things and I will keep working on the script. The code that was posted above was put together after maybe an hour of work, it was my first time scripting so thank you for the suggestion and help!

Link to comment
Share on other sites

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

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