Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Bug My bot just walks between 2 tiles. I can't figure out why.

Joined
Nov 2, 2015
Messages
17
So my bot is meant to run from Burthorpe bank down to the flax pen, pick a whole inventory and return back and bank them.

Whenever I load the bot up it just runs just a little north of the bank then south then back north then south in an endless cycle.

I'm sure it's a minor thing. I used AesBerries old script as a model and made a note to re-type it all out so I can get a better understanding of how it's working. Although this has me puzzled.

Code:
package com.sinatra.bots.sFlaxNSpin;

import com.runemate.game.api.client.paint.PaintListener;
import com.runemate.game.api.hybrid.entities.GameObject;
import com.runemate.game.api.hybrid.entities.Player;
import com.runemate.game.api.hybrid.entities.definitions.ItemDefinition;
import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.hybrid.location.Area;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.location.navigation.Traversal;
import com.runemate.game.api.hybrid.location.navigation.basic.BresenhamPath;
import com.runemate.game.api.hybrid.location.navigation.web.WebPath;
import com.runemate.game.api.hybrid.region.GameObjects;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.hybrid.util.StopWatch;
import com.runemate.game.api.hybrid.util.calculations.CommonMath;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.LoopingScript;
import com.runemate.game.api.script.framework.listeners.InventoryListener;
import com.runemate.game.api.script.framework.listeners.events.ItemEvent;

import java.awt.*;
import java.util.concurrent.TimeUnit;

public class sFlaxNSpin extends LoopingScript implements PaintListener, InventoryListener {

    private final static Player player = Players.getLocal();
    private final static StopWatch runtime = new StopWatch();
    private final static Area flaxArea = new Area.Rectangular(new Coordinate(2886, 3464, 0), new Coordinate(2886, 3460, 0));
    private final static Area bankArea = new Area.Rectangular(new Coordinate(2888, 3536, 0), new Coordinate(2888, 3538, 0));
    private static int pickedFlax = 0;

    @Override
    public void onStart(String... args) {
        getEventDispatcher().addListener(this);
        setLoopDelay(250, 750);
        runtime.start();
    }

    @Override
    public void onLoop() {
        GameObject flax = GameObjects.getLoaded(67263, 67264, 67265).nearestTo(player);

        if (Inventory.isFull() && flaxArea.contains(player) && isIdle()) { // Picking Flax
            if (flax != null && flax.isValid()) {
                flax.interact("Pick");
            }
        } else if (!Inventory.isFull() && !bankArea.contains(player)) { // Walking to Bank
            final WebPath bankPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(bankArea.getCenter());
            final BresenhamPath failBankPath = BresenhamPath.buildTo(bankArea.getCenter());

            if (bankPath != null) {
                bankPath.step();
            } else if (failBankPath != null) {
                failBankPath.step();
            }
        } else if (Inventory.isFull() && bankArea.contains(player)) { //Banking
            if (!Bank.isOpen()) {
                Bank.open();
                Execution.delay(250, 450);
            } else {
                Bank.depositInventory();
                Execution.delay(200, 500);
            }
        } else if (!Inventory.isFull() && !flaxArea.contains(player)) { // Walking to Flax
            final WebPath flaxPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(flaxArea.getCenter());
            final BresenhamPath failFlaxPath = BresenhamPath.buildTo(flaxArea.getCenter());

            if (flaxPath != null) {
                flaxPath.step();
            } else if (failFlaxPath != null) {
                failFlaxPath.step();
            }
        }
    }


    @Override
    public void onPaint(Graphics2D g) {
        Color transBlack = new Color(0, 0, 0, 150);
        //Draw trans rect
        g.setColor(transBlack);
        g.fillRect(0, 0, 150, 70);
        //Draw border of rect
        g.setColor(Color.blue);
        g.drawRect(0, 0, 150, 70);
        //Draw green underline under title
        g.drawLine(5, 20, 145, 20);
        //Draw text
        g.setColor(Color.white);
        g.drawString("sFlaxNSpin", 50, 15);
        g.drawString("Run time: " + runtime.getRuntimeAsString(), 5, 35);
        g.drawString("Picked Flax: " + pickedFlax + " ,P/H: " + (int) CommonMath.rate(TimeUnit.HOURS, runtime.getRuntime(), pickedFlax), 5, 50);
        g.drawString("Bowstring Strung: SOON", 5, 65);
    }

    @Override
    public void onItemAdded(ItemEvent event) {
        ItemDefinition definition = event.getItem().getDefinition();

        if (definition != null && definition.getName().equals("Flax")) {
            ++pickedFlax;
        }
    }

    private boolean isIdle() {
        return player.getAnimationId() == -1 && !player.isMoving();
    }

}
 
Last edited:
Joined
Oct 29, 2015
Messages
6
It's because your logic is off. You want the bot to walk back when Inventory.isFull() not !Inventory.isFull(). Also it is because it is trying to walk to the bank and walk to the flax area one after the other so it will keep going back and forth. so you should probably make an enum to control the state of the bot. Then you could use a switch statement to determine where you want it to walk.
 
Joined
Nov 2, 2015
Messages
17
It's because your logic is off. You want the bot to walk back when Inventory.isFull() not !Inventory.isFull(). Also it is because it is trying to walk to the bank and walk to the flax area one after the other so it will keep going back and forth. so you should probably make an enum to control the state of the bot. Then you could use a switch statement to determine where you want it to walk.

Ahh okay I understand. Where would I be using !Inventory.isFull() then in most cases? I'm not sure what the symbol '!' is doing in my code, I'm trying to figure that out.

As for making an enum could you expand on that a little bit? I'm not after the resolution to my issue but rather an example on how it works that I can dissect and learn from.
 
Joined
Oct 2, 2015
Messages
31
I gotchu fam hang on
Code:
package com.sinatra.bots.sFlaxNSpin;


public class sFlaxNSpin extends LoopingScript implements PaintListener, InventoryListener {

    @Override
    public void onLoop() {
        if (!Inventory.isFull() && !bankArea.contains(player)) { // Walking to Bank
            final WebPath bankPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(bankArea.getCenter());
            final BresenhamPath failBankPath = BresenhamPath.buildTo(bankArea.getCenter());

            if (bankPath != null) {
                bankPath.step();
            } else if (failBankPath != null) {
                failBankPath.step();
            }
        } else if (!Inventory.isFull() && !flaxArea.contains(player)) { // Walking to Flax
            final WebPath flaxPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(flaxArea.getCenter());
            final BresenhamPath failFlaxPath = BresenhamPath.buildTo(flaxArea.getCenter());

            if (flaxPath != null) {
                flaxPath.step();
            } else if (failFlaxPath != null) {
                failFlaxPath.step();
            }
        }
    }

    }


due to your logic your script is basically only just spamming this.
Also nice to see you here too ^_^

You're pretty much just telling it, if its not at the bank, walk to the bank, and if it is, walk to the flax.
So the moment it tries to walk to the flax and leaves the bank it'll walk back in


EDIT: "!" on a booleans means NOT so it's like NOTinventory.isFull()
AKA your script would work if you flipped the !'s on your inventory checks
 
Joined
Nov 2, 2015
Messages
17
You're pretty much just telling it, if its not at the bank, walk to the bank, and if it is, walk to the flax.
So the moment it tries to walk to the flax and leaves the bank it'll walk back in

Ahh silly mistake of mine I guess.

Is Inventory.isEmpty a better alternative then? Or is my bot not actually getting that far?

Code:
    @Override
    public void onLoop() {
        GameObject flax = GameObjects.getLoaded(67263, 67264, 67265).nearestTo(player);

        if (Inventory.isFull() && flaxArea.contains(player) && isIdle()) { // Picking Flax
            if (flax != null && flax.isValid()) {
                flax.interact("Pick");
            }
        } else if (Inventory.isFull() && bankArea.contains(player)) { // Walking to Bank
            final WebPath bankPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(bankArea.getCenter());
            final BresenhamPath failBankPath = BresenhamPath.buildTo(bankArea.getCenter());

            if (bankPath != null) {
                bankPath.step();
            } else if (failBankPath != null) {
                failBankPath.step();
            }
        } else if (Inventory.isFull() && bankArea.contains(player)) { //Banking
            if (!Bank.isOpen()) {
                Bank.open();
                Execution.delay(250, 450);
            } else {
                Bank.depositInventory();
                Execution.delay(200, 500);
            }
        } else if (Inventory.isEmpty() && flaxArea.contains(player)) { // Walking to Flax
            final WebPath flaxPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(flaxArea.getCenter());
            final BresenhamPath failFlaxPath = BresenhamPath.buildTo(flaxArea.getCenter());

            if (flaxPath != null) {
                flaxPath.step();
            } else if (failFlaxPath != null) {
                failFlaxPath.step();
            }
        }
    }
 
Joined
Oct 29, 2015
Messages
6
Ahh okay I understand. Where would I be using !Inventory.isFull() then in most cases? I'm not sure what the symbol '!' is doing in my code, I'm trying to figure that out.

As for making an enum could you expand on that a little bit? I'm not after the resolution to my issue but rather an example on how it works that I can dissect and learn from.
Ok, so what ! does is it is the opposite of whatever it returns by default so it is searching for if inventory is not full, but you want the bot to walk back when it is full. Also you should make a boolean that gets activated when it reaches the area and check if the boolean is false in the else ifs.
 

Code:
public boolean atbank=false;
@Override
    public void onLoop() {
        GameObject flax = GameObjects.getLoaded(67263, 67264, 67265).nearestTo(player);

        if (!Inventory.isFull() && flaxArea.contains(player) && isIdle()) { // Picking Flax
            if (flax != null && flax.isValid()) {
                flax.interact("Pick");
            }
        }else if (Inventory.isFull() && !bankArea.contains(player) && atbank==false) { // Walking to Bank
            final WebPath bankPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(bankArea.getCenter());
            final BresenhamPath failBankPath = BresenhamPath.buildTo(bankArea.getCenter());

            if (bankPath != null) {
                bankPath.step();
            } else if (failBankPath != null) {
                failBankPath.step();
            }
        } else if (Inventory.isFull() && bankArea.contains(player)) { //Banking
            atbank=true;
            if (!Bank.isOpen()) {
                Bank.open();
                Execution.delay(250, 450);
            } else {
                while(!Inventory.isEmpty()){
                 Bank.depositInventory();
                }
                Execution.delay(200, 500);
            }
        } else if (Inventory.isEmpty() && !flaxArea.contains(player) && atbank==true) { // Walking to Flax
            final WebPath flaxPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(flaxArea.getCenter());
            final BresenhamPath failFlaxPath = BresenhamPath.buildTo(flaxArea.getCenter());

            if (flaxPath != null) {
                flaxPath.step();
            } else if (failFlaxPath != null) {
                failFlaxPath.step();
            }
            atbank=false
        }
    }
This is an example that should work, make sure to use booleans or anything that will disable an if statement from firing once it arrives at the destination.
 
Joined
Oct 2, 2015
Messages
31
Two birds one stone.
The enum reference earlier was most likely just aimed at neatness and readability.
Example In Your Case:

Code:
public class EnumStateExample extends LoopingScript {
    Area bank = new Area.Rectangular(new Coordinate(0,0,0), new Coordinate(0,0,0));

    enum State{
        WALK_TO_BANK, WALK_TO_FIELD, PICK, BANK;
    }

    @Override
    public void onLoop() {
    switch (currentState()){
        case BANK:
            handleBank();
            break;
        case WALK_TO_BANK:
            walkToBank();
            break;
    }
    }

    private void handleBank() {
        //do banking here
    }

    private void walkToBank() {
        //do walking to bank here
    }

    private State currentState(){
        if(Inventory.isFull()){
            if(bank.contains(Players.getLocal())){
                return State.BANK;
            }else{
                return State.WALK_TO_BANK;
            }
        }else{
            //picking flax and walking to field checks
            //and so on
            return null;
        }
    }
}

but since we have task script this'd be slightly redundant now.

And you have the right checks just in the wrong place.
You're telling to to bank if the inventory isn't full.
And to pick when the inventory is full
you can still use
Inventory.isFull() and !Inventory.isFull() but you just have them in the wrong places :D
 
Joined
Nov 2, 2015
Messages
17
Amazing! Thank you so much for the help I really do appreciate it!

I ran into some issues re-coding it to the layout you suggested but I managed to figure them out.

How is this code looking? Anything you can see straight away that will cause any issues?

Code:
package com.sinatra.bots.sFlaxNSpin;

import com.runemate.game.api.client.paint.PaintListener;
import com.runemate.game.api.hybrid.entities.GameObject;
import com.runemate.game.api.hybrid.entities.Player;
import com.runemate.game.api.hybrid.entities.definitions.ItemDefinition;
import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.hybrid.location.Area;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.location.navigation.Traversal;
import com.runemate.game.api.hybrid.location.navigation.basic.BresenhamPath;
import com.runemate.game.api.hybrid.location.navigation.web.WebPath;
import com.runemate.game.api.hybrid.region.GameObjects;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.hybrid.util.StopWatch;
import com.runemate.game.api.hybrid.util.calculations.CommonMath;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.LoopingScript;
import com.runemate.game.api.script.framework.listeners.InventoryListener;
import com.runemate.game.api.script.framework.listeners.events.ItemEvent;

import java.awt.*;
import java.util.concurrent.TimeUnit;

public class sFlaxNSpin extends LoopingScript implements PaintListener, InventoryListener {

    private final static Player player = Players.getLocal();
    private final static StopWatch runtime = new StopWatch();
    private final static Area flaxArea = new Area.Rectangular(new Coordinate(2886, 3464, 0), new Coordinate(2886, 3460, 0));
    private final static Area bankArea = new Area.Rectangular(new Coordinate(2888, 3536, 0), new Coordinate(2888, 3538, 0));
    private static int pickedFlax = 0;

    enum State{
        WALK_TO_BANK, WALK_TO_FIELD, PICK, BANK;
    }

    @Override
    public void onStart(String... args) {
        getEventDispatcher().addListener(this);
        setLoopDelay(250, 750);
        runtime.start();
    }

    @Override
    public void onLoop() {
    switch (currentState()){
        case BANK:
            handleBank();
            break;
        case WALK_TO_BANK:
            walkToBank();
            break;
        case PICK:
            handlePick();
            break;
        case WALK_TO_FIELD:
            walkToField();
        }
    }

    private void handleBank() {
        if (Inventory.isFull() && bankArea.contains(player)) { //Banking
            if (!Bank.isOpen()) {
                Bank.open();
                Execution.delay(250, 450);
            } else {
                Bank.depositInventory();
                Execution.delay(200, 500);
            }
        }
    }

    private void walkToBank() {
        if (Inventory.isFull() && !bankArea.contains(player)) { // Walking to Bank
            final WebPath bankPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(bankArea.getCenter());
            final BresenhamPath failBankPath = BresenhamPath.buildTo(bankArea.getCenter());

            if (bankPath != null) {
                bankPath.step();
            } else if (failBankPath != null) {
                failBankPath.step();
            }
        }
    }

    private void handlePick() {
        GameObject flax = GameObjects.getLoaded(67263, 67264, 67265).nearestTo(player);

        if (!Inventory.isFull() && flaxArea.contains(player) && isIdle()) { // Picking Flax
            if (flax != null && flax.isValid()) {
                flax.interact("Pick");
            }
        }
    }

    private void walkToField() {
        if (!Inventory.isFull() && !flaxArea.contains(player)) {
            final WebPath flaxPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(flaxArea.getCenter());
            final BresenhamPath failFlaxPath = BresenhamPath.buildTo(flaxArea.getCenter());

            if (flaxPath != null) {
                flaxPath.step();
            } else if (failFlaxPath != null) {
                failFlaxPath.step();
            }
        }
    }

    private State currentState(){
        if (Inventory.isFull()){
            if (bankArea.contains(Players.getLocal())){
                return State.BANK;
            }else{
                return State.WALK_TO_BANK;
            }
        }
        if (!Inventory.isFull()){
            if (flaxArea.contains(Players.getLocal())){
                return State.PICK;
            }else{
                return State.WALK_TO_FIELD;
            }
        }
        return null;
    }


    @Override
    public void onPaint(Graphics2D g) {
        Color transBlack = new Color(0, 0, 0, 150);
        //Draw trans rect
        g.setColor(transBlack);
        g.fillRect(0, 0, 150, 70);
        //Draw border of rect
        g.setColor(Color.blue);
        g.drawRect(0, 0, 150, 70);
        //Draw green underline under title
        g.drawLine(5, 20, 145, 20);
        //Draw text
        g.setColor(Color.white);
        g.drawString("sFlaxNSpin", 50, 15);
        g.drawString("Run time: " + runtime.getRuntimeAsString(), 5, 35);
        g.drawString("Picked Flax: " + pickedFlax + " ,P/H: " + (int) CommonMath.rate(TimeUnit.HOURS, runtime.getRuntime(), pickedFlax), 5, 50);
        g.drawString("Bowstring Strung: SOON", 5, 65);
    }

    @Override
    public void onItemAdded(ItemEvent event) {
        ItemDefinition definition = event.getItem().getDefinition();

        if (definition != null && definition.getName().equals("Flax")) {
            ++pickedFlax;
        }
    }

    private boolean isIdle() {
        return player.getAnimationId() == -1 && !player.isMoving();
    }


}
 
Joined
Oct 2, 2015
Messages
31
private void walkToBank() {
if (Inventory.isFull() && !bankArea.contains(player)) { // Walking to Bank
final WebPath bankPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(bankArea.getCenter());
final BresenhamPath failBankPath = BresenhamPath.buildTo(bankArea.getCenter());

if (bankPath != null) {
bankPath.step();
} else if (failBankPath != null) {
failBankPath.step();
}
}
}

Can't see any major problems although I'm a bit out of it atm.
Just a random kinda note thing.
Where you've done this.
(aka adding the checks into the functions after reaching the function)
(namely the isFull and contains line)

Are redundant to write again since if those conditions aren't true that method wouldn't even be reached as the state :)
Just if you ever want to save production time, any checks in the currentState() don't need to be added again in the state method.
 
Also A small Neaten

Code:
private State currentState(){
        if (Inventory.isFull()){
            if (bankArea.contains(Players.getLocal())){
                return State.BANK;
            }else{
                return State.WALK_TO_BANK;
            }
        }else{
            if (flaxArea.contains(Players.getLocal())){
                return State.PICK;
            }else{
                return State.WALK_TO_FIELD;
            }
        }
    }
 
Joined
Nov 2, 2015
Messages
17
Ahh right okay.

Say for example if I didn't want the bot to bank after inventory is full but rather full of bowstrings (after spinning them near by).

I'm assuming I would tackle this the same way right? add on another 2 states, (WALK_TO_WHEEL and SPIN)

can Inventory.isFull() work like the following?
private void walkToWheel() {
if (Inventory.isFull("Flax") or am I going to have to somehow go down the definition.getName().equals("Flax")) route?
 
Joined
Oct 2, 2015
Messages
31
can Inventory.isFull() work like the following?
private void walkToWheel() {
if (Inventory.isFull("Flax") or am I going to have to somehow go down the definition.getName().equals("Flax")) route?

IMO, The Simplest Modification To Accommodate :


Code:
private State currentState(){
        if (Inventory.isFull()){
            if(Inventory.containsAnyOf("Flax")){
                if(wheelArea.contains(Players.getLocal())){
                    return State.SPIN;
                }else{
                    return State.WALK_TO_WHEEL;
                }
            }else {
                if (bankArea.contains(Players.getLocal())) {
                    return State.BANK;
                } else {
                    return State.WALK_TO_BANK;
                }
            }
        }else{
            if (flaxArea.contains(Players.getLocal())){
                return State.PICK;
            }else{
                return State.WALK_TO_FIELD;
            }
        }
    }

Wherever possible try to utilize old checks if they're also relative and just slip the logic in where it seems right :p
 
Joined
Nov 2, 2015
Messages
17
IMO, The Simplest Modification To Accommodate

Nice! I'm testing my bot now for a couple hours to see what comes up.

I'm worried about what happens when a strange rock appears in my inventory but I guess I'll have to wait and see.
 
Last edited:
Joined
Oct 2, 2015
Messages
31
Nice! I'm testing my bot now for a couple hours to see what comes up.

I'm worried about what happens when a strange rock appears in my inventory but I guess I'll have to wait and see.
The script will auto destroy it causing you to walk back to the field for 1 flax :p.
There are two ways you could overcome this :)
1.
GameEvents.RS3.UNEXPECTED_ITEM_HANDLER.disable();
in your onstart

2.
Code:
private State currentState(){
        if (Inventory.isFull() || Inventory.containsAnyOf("Bowstring")){
            if(Inventory.containsAnyOf("Flax")){
                if(wheelArea.contains(Players.getLocal())){
                    return State.SPIN;
                }else{
                    return State.WALK_TO_WHEEL;
                }
            }else {
                if (bankArea.contains(Players.getLocal())) {
                    return State.BANK;
                } else {
                    return State.WALK_TO_BANK;
                }
            }
        }else{
            if (flaxArea.contains(Players.getLocal())){
                return State.PICK;
            }else{
                return State.WALK_TO_FIELD;
            }
        }
    }
 
also bowstring might be spelt wrong, idk how its spelt in game
 
Joined
Nov 2, 2015
Messages
17
The script will auto destroy it causing you to walk back to the field for 1 flax :p.

Yeah I just watched my bot destroy one and run back for 1 more flax.

Unfortunately it doesn't click on the spinning wheel to open up the spin menu. However if I open up the spin interface myself by manually clicking on the wheel it will select all the bowstrings and wait for them to finish before running to the bank. I'm not sure what is actually causing this issue?

Code:
    private void handleSpin() {
        GameObject spinningWheel = GameObjects.getLoaded(66850).nearestTo(player);

        if (Inventory.isFull() && wheelArea.contains(player)) {
            spinningWheel.interact("Spin");
            final InterfaceComponent spinInterface = Interfaces.newQuery().texts("Spin").visible().results().first();
            if (spinInterface != null) {
                spinInterface.click();
            }
            final Player local = Players.getLocal();
            Execution.delayUntil(() -> !Inventory.contains("Flax"), () -> local != null && local.getAnimationId() != -1, 3000);
        }
    }
 
Joined
Oct 2, 2015
Messages
31

Might be the way you query it.
Also with your checks since this will just be looping you can format everything with more conditions.
It doesn't need to all happen in one run through, especially accounting for error.
I'd imagine it to look more like this
Code:
 private void handleSpin() {       
        GameObject spinningWheel = GameObjects.newQuery().within(wheelArea).names("Spinning wheel").results().nearest();
        final InterfaceComponent spinInterface = Interfaces.newQuery().texts("Spin").visible().results().first();
        final Player local = Players.getLocal();

        if(spinInterface != null && spinInterface.isVisible()){
            if(spinInterface.click()){
                Execution.delayUntil(() -> !Inventory.contains("Flax"), () -> local != null && local.getAnimationId() != -1, 3000);
            }
        }else{           
            if(spinningWheel != null){
                if(spinningWheel.isVisible()){
                    if(spinningWheel.interact("Spin")){
                        Execution.delayUntil(() -> spinInterface != null && spinInterface.isVisible(), 2500, 3500);
                    }
                }else{
                    Camera.turnTo(spinningWheel);
                }
            }
        }          
    }
 
Joined
Nov 2, 2015
Messages
17
Might be the way you query it.

My bot just seems to stand in the center of the wheelArea and doesn't move. When I manually move the mouse it tries to move back to the center using the minimap?

Any ideas?

current code:

Code:
    private void handleSpin() {
        GameObject spinningWheel = GameObjects.newQuery().within(wheelArea).names("Spinning wheel").results().nearest();

        final InterfaceComponent spinInterface = Interfaces.newQuery().texts("Spin").visible().results().first();
        final Player local = Players.getLocal();

        if(spinInterface != null && spinInterface.isVisible()){
            if(spinInterface.click()){
                Execution.delayUntil(() -> !Inventory.contains("Flax"), () -> local != null && local.getAnimationId() != -1, 3000);
            }
        }else{
            if(spinningWheel != null){
                if(spinningWheel.isVisible()){
                    if(spinningWheel.interact("Spin")){
                        Execution.delayUntil(() -> spinInterface != null && spinInterface.isVisible(), 2500, 3500);
                    }
                }else{
                    Camera.turnTo(spinningWheel);
                }
            }
        }
    }

I've also tried

GameObject spinningWheel = GameObjects.newQuery().within(wheelArea).names("Spinning wheel").results().nearestTo(player);

Still producing the same results.
 
Joined
Nov 2, 2015
Messages
17
Is it stuck trying to walk to the area?

I'm not sure.

After gathering a full inventory of flax is walks to the wheel area but then keeps clicking the minimap around the center of the wheelarea.
It doesn't seem to click on the Spinning wheel. However if I open up the spinning interface myself by manually clicking on the spinning wheel it will proceed to spin them and then move to the bank when finished, bank and return to the flax field and gather again all the way upto the wheelarea I guess.

I'm thinking it is having trouble clicking the spinning wheel or finding it near. It gets to the center of the area fine but then just keeps clicking on the minimap endlessly.
 
Joined
Oct 2, 2015
Messages
31
I'm not sure.

After gathering a full inventory of flax is walks to the wheel area but then keeps clicking the minimap around the center of the wheelarea.
It doesn't seem to click on the Spinning wheel. However if I open up the spinning interface myself by manually clicking on the spinning wheel it will proceed to spin them and then move to the bank when finished, bank and return to the flax field and gather again all the way upto the wheelarea I guess.

I'm thinking it is having trouble clicking the spinning wheel or finding it near. It gets to the center of the area fine but then just keeps clicking on the minimap endlessly.
there's something wrong with your
>Walk To Wheel Area
>Open Interface
Bit
Maybe your checks are a bit iffy on it?
 
Joined
Nov 2, 2015
Messages
17
there's something wrong with your
>Walk To Wheel Area
>Open Interface
Bit
Maybe your checks are a bit iffy on it?

Yeah I'm not quite sure though. Everything works apart from this one thing.

Java:
package com.sinatra.bots.sFlaxNSpin;

import com.runemate.game.api.client.paint.PaintListener;
import com.runemate.game.api.hybrid.entities.GameObject;
import com.runemate.game.api.hybrid.entities.Player;
import com.runemate.game.api.hybrid.entities.definitions.ItemDefinition;
import com.runemate.game.api.hybrid.local.Camera;
import com.runemate.game.api.hybrid.local.Skill;
import com.runemate.game.api.hybrid.local.hud.interfaces.*;
import com.runemate.game.api.hybrid.location.Area;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.location.navigation.Traversal;
import com.runemate.game.api.hybrid.location.navigation.basic.BresenhamPath;
import com.runemate.game.api.hybrid.location.navigation.web.WebPath;
import com.runemate.game.api.hybrid.region.GameObjects;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.hybrid.util.StopWatch;

import com.runemate.game.api.hybrid.util.calculations.CommonMath;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.LoopingScript;
import com.runemate.game.api.script.framework.listeners.InventoryListener;
import com.runemate.game.api.script.framework.listeners.SkillListener;
import com.runemate.game.api.script.framework.listeners.events.ItemEvent;
import com.runemate.game.api.script.framework.listeners.events.SkillEvent;


import java.awt.*;
import java.util.concurrent.TimeUnit;

public class sFlaxNSpin extends LoopingScript implements PaintListener, InventoryListener, SkillListener {

    private final static Player player = Players.getLocal();
    private final static StopWatch runtime = new StopWatch();
    private final static Area flaxArea = new Area.Rectangular(new Coordinate(2886, 3464, 0), new Coordinate(2886, 3460, 0));
    private final static Area bankArea = new Area.Rectangular(new Coordinate(2888, 3536, 0), new Coordinate(2888, 3538, 0));
    private final static Area wheelArea = new Area.Rectangular(new Coordinate(2890, 3495, 0), new Coordinate(2880, 3495, 0));
    private static int pickedFlax = 0;
    private static int spunBowstrings = 0;
    public int startExp = -1;
    public int expGained = 0;

    enum State{
        WALK_TO_BANK, WALK_TO_FIELD, WALK_TO_WHEEL, PICK, SPIN, BANK

    }

    @Override
    public void onStart(String... args) {
        getEventDispatcher().addListener(this);
        setLoopDelay(250, 500);
        runtime.start();
    }

    @Override
    public void onLoop() {
    switch (currentState()){
        case PICK:
            handlePick();
            break;
        case WALK_TO_FIELD:
            walkToField();
        case SPIN:
            handleSpin();
        case WALK_TO_WHEEL:
            walkToWheel();
        case BANK:
            handleBank();
            break;
        case WALK_TO_BANK:
            walkToBank();
            break;
        }
    }


    private void handlePick() {
        GameObject flax = GameObjects.getLoaded(67263, 67264, 67265).nearestTo(player);

        if (!Inventory.isFull() && flaxArea.contains(player) && isIdle()) { // Picking Flax
            if (flax != null && flax.isValid()) {
                flax.interact("Pick");
            }
        }
    }

    private void walkToField() {
        if (!Inventory.isFull() && !flaxArea.contains(player)) {
            final WebPath flaxPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(flaxArea.getCenter());
            final BresenhamPath failFlaxPath = BresenhamPath.buildTo(flaxArea.getCenter());

            if (flaxPath != null) {
                flaxPath.step();
            } else if (failFlaxPath != null) {
                failFlaxPath.step();
            }
        }
    }

    private void handleSpin() {
        GameObject spinningWheel = GameObjects.newQuery().within(wheelArea).names("Spinning wheel").results().nearest();

        final InterfaceComponent spinInterface = Interfaces.newQuery().texts("Spin").visible().results().first();
        final Player local = Players.getLocal();

        if(spinInterface != null && spinInterface.isVisible()){
            if(spinInterface.click()){
                Execution.delayUntil(() -> !Inventory.contains("Flax"), () -> local != null && local.getAnimationId() != -1, 3000);
            }
        }else{
            if(spinningWheel != null){
                if(spinningWheel.isVisible()){
                    if(spinningWheel.interact("Spin")){
                        Execution.delayUntil(() -> spinInterface != null && spinInterface.isVisible(), 2500, 3500);
                    }
                }else{
                    Camera.turnTo(spinningWheel);
                }
            }
        }
    }

    private void walkToWheel() {
        if (Inventory.isFull() && !wheelArea.contains(player)) {
            final WebPath wheelPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(wheelArea.getCenter());
            final BresenhamPath failWheelPath = BresenhamPath.buildTo(wheelArea.getCenter());

            if (wheelPath != null) {
                wheelPath.step();
            } else if (failWheelPath != null) {
                failWheelPath.step();
            }
        }
    }

    private void handleBank() {
        if (Inventory.isFull() && bankArea.contains(player)) { //Banking
            if (!Bank.isOpen()) {
                Bank.open();
                Execution.delay(250, 450);
            } else {
                Bank.depositInventory();
                Execution.delay(200, 500);
            }
        }
    }

    private void walkToBank() {
        if (Inventory.isFull() && !bankArea.contains(player)) { // Walking to Bank
            final WebPath bankPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(bankArea.getCenter());
            final BresenhamPath failBankPath = BresenhamPath.buildTo(bankArea.getCenter());

            if (bankPath != null) {
                bankPath.step();
            } else if (failBankPath != null) {
                failBankPath.step();
            }
        }
    }

    private State currentState(){
        if (Inventory.isFull()){
            if(Inventory.containsAnyOf("Flax")){
                if(wheelArea.contains(Players.getLocal())){
                    return State.SPIN;
                }else{
                    return State.WALK_TO_WHEEL;
                }
            }

            else {
                if (bankArea.contains(Players.getLocal())) {
                    return State.BANK;
                } else {
                    return State.WALK_TO_BANK;
                }
            }
        }else{
            if (flaxArea.contains(Players.getLocal())){
                return State.PICK;
            }else{
                return State.WALK_TO_FIELD;
            }
        }
    }


    @Override
    public void onPaint(Graphics2D g) {

        Color transBlack = new Color(0, 0, 0, 150);
        //Draw trans rect
        g.setColor(transBlack);
        g.fillRect(0, 0, 200, 100);
        //Draw border of rect
        g.setColor(Color.blue);
        g.drawRect(0, 0, 200, 100);
        //Draw green underline under title
        g.drawLine(5, 20, 190, 20);
        //Draw text
        g.setColor(Color.white);

        g.drawString("sFlaxNSpin", 50, 15);
        g.drawString("Run time: " + runtime.getRuntimeAsString(), 5, 35);
        g.drawString("Picked Flax: " + pickedFlax + " ,P/H: " + (int) CommonMath.rate(TimeUnit.HOURS, runtime.getRuntime(), pickedFlax), 5, 50);
        g.drawString("Bowstrings: " + spunBowstrings + " ,P/H: " + (int) CommonMath.rate(TimeUnit.HOURS, runtime.getRuntime(), spunBowstrings), 5, 65);
        g.drawString("Experience Gained: " + expGained + " ,P/H: " + (int) CommonMath.rate(TimeUnit.HOURS, runtime.getRuntime(), expGained), 5, 80);
    }

    @Override
    public void onItemAdded(ItemEvent event) {
        ItemDefinition definition = event.getItem().getDefinition();

        if (definition != null && definition.getName().equals("Flax")) {
            ++pickedFlax;
        }

        if (definition != null && definition.getName().equals("Bowstring")) {
            ++spunBowstrings;
        }
    }

    @Override
    public void onExperienceGained(SkillEvent event) {
        expGained = startExp == -1 ? 0 : Skill.CRAFTING.getExperience() - startExp;
    }

    private boolean isIdle() {
        return player.getAnimationId() == -1 && !player.isMoving();
    }

    @Override
    public void onPause() {
        runtime.stop();
    }

    @Override
    public void onResume() {
        runtime.start();
    }

    @Override

public void onStop() {
System.out.println("Thank you for using sFlaxNSpin");
System.out.println("Author: Sinatra");
System.out.println("Massive thanks to DarkenedSoul for helping me out!");
System.out.println("Total Runtime: " + runtime.getRuntimeAsString());
}


}
 
Last edited by a moderator:
Top