Jump to content

Scripting Help


01053
 Share

Recommended Posts

So I'm having issues with world hopping, It seems it still tries to hop to p2p worlds even though I've given it set worlds to hop to and basically at this point it just causes the script to break.


import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import com.sun.glass.events.KeyEvent;

import java.awt.*;
import java.util.Random;

@ScriptManifest(name = "Rune Pack Buyer", author = "01053", version = 1.0, info = "", logo = "")

public class Shopping extends Script {

	public Timer timer;
	private long buyDelay;
	private State state;

	private int npcId = 637;
	private int packId = 12732;
	private int buying;

	private int[] worlds = {

			1, 8, 16, 26, 35, 82, 83, 84, 93, 94

	};

	Random random = new Random();

	public enum State {
		TRADING, BUYING, OPENING
	}

	public State getState() {
		if (!getStore().isOpen() && buying <= 0) {
			return State.TRADING;
		}
		if (getStore().isOpen()) {
			return State.BUYING;
		}
		if (!getStore().isOpen() && getInventory().contains(packId) && buying > 0) {
			return State.OPENING;
		}
		return State.TRADING;
	}

	private boolean hop;

	public void execute() throws InterruptedException {
		state = getState();
		switch (state) {
		case TRADING:
			/*if (getStore().getAmount(packId) <= 57) {
				int randomWorld = random.nextInt(worlds.length);
				getWorlds().hop(randomWorld);
				buying = 0;
				hop = false;
			}*/
			NPC npc = (NPC) getNpcs().closest(npcId);
			if (npc != null) {
				if (npc.interact(new String[] { "Trade" })) {
					log("Trading shopkeeper");
					new ConditionalSleep(5500, 6000) {
						public boolean condition() throws InterruptedException {
							return getStore().isOpen();
						}
					}.sleep();
				}
			}
			break;
		case BUYING:
			if (System.currentTimeMillis() - buyDelay < 1000) {
				return;
			}
			if (getStore().getAmount(12732) <= 57 && !getInventory().contains(12732)) {
				int randomWorld = random.nextInt(worlds.length);
				getWorlds().hop(randomWorld);
				buying = 0;
				hop = false;
			}
			if (getInventory().isFull()) {
				getKeyboard().pressKey(KeyEvent.VK_ESCAPE);
				buying++;
			}
			Item rune = getStore().getItem(packId);
			if ((rune != null) && (getStore().getAmount(packId) > 54)) {
				getStore().buy(packId, 10);
				log("Buying Rune Packs");
				hop = false;
				buyDelay = System.currentTimeMillis();
			}
			break;
		case OPENING:
			if (hop && getStore().getAmount(12732) <= 57 && !getInventory().contains(12732)) {
				int randomWorld = random.nextInt(worlds.length);
				getWorlds().hop(randomWorld);
				buying = 0;
				hop = false;
			}
			if (getInventory().contains(packId) && !getTabs().open(Tab.INVENTORY)) {
				getKeyboard().pressKey(KeyEvent.VK_F1);
			}
			for (int i = 1; i < 28; i++) {
				getMouse().click(getInventory().getMouseDestination(i + 1));
				hop = true;
			}
			break;
		}
	}

	@[member='Override']
	public void onStart() {
		timer = new Timer(0L);
		log("Rune Pack BUYING Script Initiating.");
	}

	@[member='Override']
	public int onLoop() throws InterruptedException {
		execute();
		return 100;
	}

	Color color = new Color(0, 0, 0, 85);

	@[member='Override']
	public void onPaint(Graphics2D gr) {
		gr.setColor(this.color);
		gr.fillRect(56, 355, 198, 100);
		gr.setColor(Color.GREEN);
		gr.setFont(new Font("Ariel", 0, 20));
		gr.drawString("Script by: 01053", 75, 436);
		gr.setFont(new Font("Ariel", 0, 14));
		gr.drawString("Time Elapsed: " + Timer.format(timer.getElapsed()), 61, 372);
		gr.drawString("State: " + getState(), 62, 397);
		gr.setColor(Color.BLACK);
	}
}

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

 

95% that you ripped this code biggrin.png

 

Look here

if (System.currentTimeMillis() - openDelay < 1000) {
return;
}
Item pack = getInventory().getItem(12732);
if ((pack != null)) {
openDelay = System.currentTimeMillis();
pack.interact("Open");
opened++;
log("" + opened);

Lol if your talking about the openDelay I added that because it was spam clicking boxes and I didn't like it. so no that has nothing to do with it thank you though.

Link to comment
Share on other sites

use #interactWithSlot or whatever it was called

Thank you I'll look into it.

 

If anyone needs to do this also:

for (int i = 1; i < 28; i++) {
				getMouse().click(getInventory().getMouseDestination(i + 1));
			} 
works probably a better way of doing it though but yeah.
 
Edit:
 
Edited op with a new question.
Edited by 01053
Link to comment
Share on other sites

int randomWorld = random.nextInt(worlds.length);

????

 

It chooses a random index# from 

	private int[] worlds = {

			1, 8, 16, 26, 35, 82, 83, 84, 93, 94

	};

And hops to whatever world it chooses I've also tried using the 

getWorlds().HopToF2PWorld();

function and that too sometimes goofs like as if it 'clicks' the world but doesn't hop and then it just sits there.

Link to comment
Share on other sites

It chooses a random index# from 

	private int[] worlds = {

			1, 8, 16, 26, 35, 82, 83, 84, 93, 94

	};

And hops to whatever world it chooses I've also tried using the 

getWorlds().HopToF2PWorld();

function and that too sometimes goofs like as if it 'clicks' the world but doesn't hop and then it just sits there.

 

you should probably take another look at the code m8. that wasnt me asking what the line does. that was me telling you theres a problem in that line lol.

Edited by Imateamcape
Link to comment
Share on other sites

you should probably take another look at the code m8. that wasnt me asking what the line does. that was me telling you theres a problem in that line lol.

After looking over it I found one issue not relevant to that code but care to explain? thanks :)

int randomWorld = random.nextInt(worlds.length);
				getWorlds().hop(randomWorld);

Should have been

int randomWorld = random.nextInt(worlds.length);
				getWorlds().hop(worlds[randomWorld]);

Was tired when I did this last night :o

  • Like 1
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.

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.

 Share

  • Recently Browsing   0 members

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