Welcome!

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

Sign up now!

Keyboard interaction

Joined
Jan 8, 2015
Messages
1,427
When I try to teleport this is what happens when the following code is executed;

http://puu.sh/fhIh5/cf9d4b480c.gif
cf9d4b480c.gif


Full code can be found on here
 
Engineer
Joined
Jul 28, 2013
Messages
2,777
My first question is why are you using the numbers 49 and 50 instead of using KeyEvent.VK_KEY.
Now, as you can see it presses the second one after the first which means it is releasing it properly to begin with (not an api bug then).
Also, show me the code that's calling each of those methods so I can try and see where your logic error is.
 
Joined
Jan 8, 2015
Messages
1,427
This is my current code;

Code:
package com.runemate.geashawscripts.banana;//Imports are all the classes that we are going to use methods fromimport com.runemate.game.api.client.paint.PaintListener;import com.runemate.game.api.hybrid.RuneScape;import com.runemate.game.api.hybrid.entities.Actor;import com.runemate.game.api.hybrid.entities.GameObject;import com.runemate.game.api.hybrid.entities.Npc;import com.runemate.game.api.hybrid.entities.Player;import com.runemate.game.api.hybrid.input.Keyboard;import com.runemate.game.api.hybrid.local.Camera;import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;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.Path;import com.runemate.game.api.hybrid.location.navigation.Traversal;import com.runemate.game.api.hybrid.region.GameObjects;import com.runemate.game.api.hybrid.region.Npcs;import com.runemate.game.api.hybrid.region.Players;import com.runemate.game.api.hybrid.util.StopWatch;import com.runemate.game.api.rs3.local.hud.interfaces.eoc.ActionBar;import com.runemate.game.api.rs3.local.hud.interfaces.eoc.SlotAction;import com.runemate.game.api.rs3.net.GrandExchange;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.awt.event.KeyEvent;import java.text.NumberFormat;public class bananapicker extends LoopingScript implements PaintListener, InventoryListener {

private String status = "Starting up..."; private final StopWatch runtime = new StopWatch(); private final String BANANA = "Banana"; private final String BASKET = "Basket"; private final String FILLED_BASKET = "Bananas (5)"; private final String GLORY = "Amulet of glory"; private int BANANA_COUNT, BANANA_BASKET_PRICE, PROFIT_MADE; final Area KARAMJA_AREA = new Area.Rectangular(new Coordinate(2905, 3154), new Coordinate(2935, 3180, 0)); final Area EDGEVILLE_AREA = new Area.Rectangular(new Coordinate(3084, 3488, 0), new Coordinate(3097, 3499, 0)); final Player player = Players.getLocal(); private Path walkToTree;@Overridepublic void onStart(String... args) {
setLoopDelay(100, 200);getEventDispatcher().addListener(this);BANANA_BASKET_PRICE = GrandExchange.lookup(5416).getPrice();runtime.start();debug("Test.");}

@Overridepublic void onLoop() {

// Check if the user is logged in.if (RuneScape.isLoggedIn()) {
if (atEdgeville()) {
if (gotFilledBaskets()) {
Npc banker = Npcs.newQuery().names("Banker").results().nearest(); if (banker != null) {
if (banker.isVisible()) {
if (Bank.isOpen()) {
performBankPreset();} else {
openBank();}
} else {
debug("Turning camera to banker");Camera.setPitch(0.234);Camera.turnTo(banker);}
}
} else if (gotAllEmptyBaskets()) {
teleportToKaramja();}
} else if (atKaramja()) {
if (gotFilledBaskets()) {
teleportToEdgeville();} else if (canPutBananasInBasket()) {
putBananasIntoBasket();} else if (canPickBananasFromTree()) {
pickBananasFromTree();}
}
}
}

/** * Teleport to Edgeville. */private boolean teleportToEdgeville() {
SlotAction action = ActionBar.getFirstAction(GLORY); if (action != null) {
status = "Activating glory."; if (action.activate()) {
if (teleportToEdgevilleOptionIsVisible()) {
// A little extra delay.status = "Selecting Edgeville teleport.";debug("Typing key 49"); if (Keyboard.pressKey(KeyEvent.VK_1)) {
Keyboard.releaseKey(KeyEvent.VK_1);Execution.delayUntil(() -> !teleportToEdgevilleOptionIsVisible(), 3000, 4000); return true;}
} else {
Execution.delayUntil(() -> teleportToEdgevilleOptionIsVisible(), 1000, 1500);}
}
}

return false;}

/** * Teleport to Karamja. */private boolean teleportToKaramja() {
SlotAction action = ActionBar.getFirstAction(GLORY); if (action != null) {
status = "Activating glory."; if (action.activate()) {
if (teleportToKaramjaOptionIsVisible()) {
// A little extra delay.status = "Selecting Karamja teleport.";debug("Typing key 50"); if (Keyboard.pressKey(KeyEvent.VK_2)) {
Keyboard.releaseKey(KeyEvent.VK_2);Execution.delayUntil(() -> !teleportToKaramjaOptionIsVisible(), 3000, 4000); return true;}
} else {
Execution.delayUntil(() -> teleportToKaramjaOptionIsVisible(), 1000, 1500);}
}
}

return false;}


/** * Perform quick banking with a bank preset. */private boolean performBankPreset() {
InterfaceComponent component = Interfaces.getAt(762, 41); if (component != null && component.isVisible()) {
if (component.click()) {
status = "Performing bank preset";debug("Performing bank preset");Execution.delayUntil(() -> !Bank.isOpen(), 0, 1000); return true;}
}

return false;}

/** * Open the bank. */private boolean openBank() {
status = "Opening the bank.";debug("Opening the bank"); if (Bank.open()) {
if (!Bank.isOpen()) {
Execution.delayUntil(() -> Bank.isOpen(), 500); return true;}
}
return false;}

/** * Pick bananas from a tree. */private boolean pickBananasFromTree() {
GameObject tree = GameObjects.newQuery().names("Banana Tree").actions("Pick").results().nearest(); if (tree != null) {
if (tree.distanceTo(player) > 7) {
debug("Tree is further than 7 steps");status = "Tree is further than 7 steps";walkToTree = Traversal.getDefaultWeb().getPathBuilder().buildTo(tree); if (walkToTree != null) {
status = "Walking to tree";walkToTree.step(true);} else {
debug("Can't walk to tree...");status = "Can't walk to tree...";}
} else {
if (tree.isVisible()) {
if (!isBusy(player)) {
if (Camera.getPitch() < 0.35) {
Camera.setPitch(0.60, 0.65);} else {
status = "Picking bananas."; return tree.interact("Pick");}
}
} else {
debug("Turning camera to tree");Camera.turnTo(tree);}
}
}

return false;}

/** * Put banana into an empty basket using the action bar. */private boolean putBananasIntoBasket() {
SlotAction action = ActionBar.getFirstAction("Basket"); if (action != null) {
status = "Putting bananas into basket."; if (Keyboard.typeKey(action.getSlot().getKeyBind())) {
if (gotBananas()) {
Execution.delayUntil(() -> !gotBananas(), 0, 500); return true;}
}
}

return false;}

/** * Check if whether the player is at Edgeville or not. */private boolean atEdgeville() {
return EDGEVILLE_AREA.contains(player);}

/** * Check if the player is at Karamja or not. */private boolean atKaramja() {
return KARAMJA_AREA.contains(player);}

/** * Check if the player has at least 5 bananas in inventory. */private boolean gotBananas() {
return (Inventory.contains(BANANA) && Inventory.getQuantity(BANANA) >= 5);}

/** * Check if the player has at least one empty basket */private boolean gotEmptyBaskets() {
return (Inventory.contains(BASKET) && Inventory.getQuantity(BASKET) >= 1);}

/** * Check if the player has at least 23 empty baskets */private boolean gotAllEmptyBaskets() {
return (Inventory.contains(BASKET) && Inventory.getQuantity(BASKET) >= 23);}

/** * Check if the the player has at least 23 filled baskets. */private boolean gotFilledBaskets() {
return (Inventory.contains(FILLED_BASKET) && Inventory.getQuantity(FILLED_BASKET) >= 23);}

/** * Check if the player can pick bananas from a tree. */private boolean canPickBananasFromTree() {
return !Inventory.isFull() && !gotBananas();}

/** * Check if the player can put bananas into an empty basket. */private boolean canPutBananasInBasket() {
return gotBananas() && gotEmptyBaskets();}

/** * Check if the teleport interface is visible. */private boolean teleportToEdgevilleOptionIsVisible() {
InterfaceComponent component = Interfaces.newQuery().texts("Edgeville.").visible().results().first(); return (component != null && component.isValid());}


private boolean teleportToKaramjaOptionIsVisible() {
InterfaceComponent component = Interfaces.newQuery().texts("Karamja.").visible().results().first(); return (component != null && component.isValid());}

private boolean isBusy(final Actor player) {
return player.isMoving() || player.getAnimationId() != -1;}

/** * Turn amount gained into amount gained per hour. * * @param amount The amount of experience. * @param elapsed The elapsed time. * @return Returns the int amount per hour. */public int getHourly(final int amount, final long elapsed) {
return (int) (amount * 3600000.0D / elapsed);}

/** * Method to format thousands decimal. * * @param i The integer to format. * @return Returns the integer as formatted number. */protected String formatNumber(int i) {
return NumberFormat.getIntegerInstance().format(i);}

/** * Helper method used to replace System.out.println(text); * * @param text The text to send to the console. */private void debug(String text) {
System.out.println(text);}

/** * Count items that are added to inventory. */@Overridepublic void onItemAdded(ItemEvent arg0) {
if (arg0.getItem().getDefinition().getName().equals("Banana")) {
BANANA_COUNT++;}
}

/* * This is where we put everything that we want to draw to the screen. * Graphics2D is the class that contains all the paint methods. */@Overridepublic void onPaint(Graphics2D g) {
int x = 5, y = 15;PROFIT_MADE = BANANA_COUNT / 5 * BANANA_BASKET_PRICE;g.drawString("Version " + getMetaData().getVersion(), x, y);g.drawString("Run time: " + runtime.getRuntimeAsString(), x, y + 15);g.drawString("Status: " + status, x, y + 30);g.drawString("Bananas: " + formatNumber(BANANA_COUNT) + " (" + formatNumber(getHourly(BANANA_COUNT, runtime.getRuntime())) + ")", x, y + 45);g.drawString("Baskets: " + formatNumber(BANANA_COUNT / 5) + " (" + formatNumber(getHourly(BANANA_COUNT /5, runtime.getRuntime())) + ")", x, y + 60);g.drawString("Profits: " + formatNumber(PROFIT_MADE) + " (" + formatNumber(getHourly(PROFIT_MADE, runtime.getRuntime())) + ")", x, y + 75);}

@Overridepublic void onPause() {
runtime.stop();}

@Overridepublic void onResume() {
runtime.start();}

}
 
Engineer
Joined
Jul 28, 2013
Messages
2,777
This is my current code;

Code:
package com.runemate.geashawscripts.banana;//Imports are all the classes that we are going to use methods fromimport com.runemate.game.api.client.paint.PaintListener;import com.runemate.game.api.hybrid.RuneScape;import com.runemate.game.api.hybrid.entities.Actor;import com.runemate.game.api.hybrid.entities.GameObject;import com.runemate.game.api.hybrid.entities.Npc;import com.runemate.game.api.hybrid.entities.Player;import com.runemate.game.api.hybrid.input.Keyboard;import com.runemate.game.api.hybrid.local.Camera;import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;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.Path;import com.runemate.game.api.hybrid.location.navigation.Traversal;import com.runemate.game.api.hybrid.region.GameObjects;import com.runemate.game.api.hybrid.region.Npcs;import com.runemate.game.api.hybrid.region.Players;import com.runemate.game.api.hybrid.util.StopWatch;import com.runemate.game.api.rs3.local.hud.interfaces.eoc.ActionBar;import com.runemate.game.api.rs3.local.hud.interfaces.eoc.SlotAction;import com.runemate.game.api.rs3.net.GrandExchange;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.awt.event.KeyEvent;import java.text.NumberFormat;public class bananapicker extends LoopingScript implements PaintListener, InventoryListener {

private String status = "Starting up..."; private final StopWatch runtime = new StopWatch(); private final String BANANA = "Banana"; private final String BASKET = "Basket"; private final String FILLED_BASKET = "Bananas (5)"; private final String GLORY = "Amulet of glory"; private int BANANA_COUNT, BANANA_BASKET_PRICE, PROFIT_MADE; final Area KARAMJA_AREA = new Area.Rectangular(new Coordinate(2905, 3154), new Coordinate(2935, 3180, 0)); final Area EDGEVILLE_AREA = new Area.Rectangular(new Coordinate(3084, 3488, 0), new Coordinate(3097, 3499, 0)); final Player player = Players.getLocal(); private Path walkToTree;@Overridepublic void onStart(String... args) {
setLoopDelay(100, 200);getEventDispatcher().addListener(this);BANANA_BASKET_PRICE = GrandExchange.lookup(5416).getPrice();runtime.start();debug("Test.");}

@Overridepublic void onLoop() {

// Check if the user is logged in.if (RuneScape.isLoggedIn()) {
if (atEdgeville()) {
if (gotFilledBaskets()) {
Npc banker = Npcs.newQuery().names("Banker").results().nearest(); if (banker != null) {
if (banker.isVisible()) {
if (Bank.isOpen()) {
performBankPreset();} else {
openBank();}
} else {
debug("Turning camera to banker");Camera.setPitch(0.234);Camera.turnTo(banker);}
}
} else if (gotAllEmptyBaskets()) {
teleportToKaramja();}
} else if (atKaramja()) {
if (gotFilledBaskets()) {
teleportToEdgeville();} else if (canPutBananasInBasket()) {
putBananasIntoBasket();} else if (canPickBananasFromTree()) {
pickBananasFromTree();}
}
}
}

/** * Teleport to Edgeville. */private boolean teleportToEdgeville() {
SlotAction action = ActionBar.getFirstAction(GLORY); if (action != null) {
status = "Activating glory."; if (action.activate()) {
if (teleportToEdgevilleOptionIsVisible()) {
// A little extra delay.status = "Selecting Edgeville teleport.";debug("Typing key 49"); if (Keyboard.pressKey(KeyEvent.VK_1)) {
Keyboard.releaseKey(KeyEvent.VK_1);Execution.delayUntil(() -> !teleportToEdgevilleOptionIsVisible(), 3000, 4000); return true;}
} else {
Execution.delayUntil(() -> teleportToEdgevilleOptionIsVisible(), 1000, 1500);}
}
}

return false;}

/** * Teleport to Karamja. */private boolean teleportToKaramja() {
SlotAction action = ActionBar.getFirstAction(GLORY); if (action != null) {
status = "Activating glory."; if (action.activate()) {
if (teleportToKaramjaOptionIsVisible()) {
// A little extra delay.status = "Selecting Karamja teleport.";debug("Typing key 50"); if (Keyboard.pressKey(KeyEvent.VK_2)) {
Keyboard.releaseKey(KeyEvent.VK_2);Execution.delayUntil(() -> !teleportToKaramjaOptionIsVisible(), 3000, 4000); return true;}
} else {
Execution.delayUntil(() -> teleportToKaramjaOptionIsVisible(), 1000, 1500);}
}
}

return false;}


/** * Perform quick banking with a bank preset. */private boolean performBankPreset() {
InterfaceComponent component = Interfaces.getAt(762, 41); if (component != null && component.isVisible()) {
if (component.click()) {
status = "Performing bank preset";debug("Performing bank preset");Execution.delayUntil(() -> !Bank.isOpen(), 0, 1000); return true;}
}

return false;}

/** * Open the bank. */private boolean openBank() {
status = "Opening the bank.";debug("Opening the bank"); if (Bank.open()) {
if (!Bank.isOpen()) {
Execution.delayUntil(() -> Bank.isOpen(), 500); return true;}
}
return false;}

/** * Pick bananas from a tree. */private boolean pickBananasFromTree() {
GameObject tree = GameObjects.newQuery().names("Banana Tree").actions("Pick").results().nearest(); if (tree != null) {
if (tree.distanceTo(player) > 7) {
debug("Tree is further than 7 steps");status = "Tree is further than 7 steps";walkToTree = Traversal.getDefaultWeb().getPathBuilder().buildTo(tree); if (walkToTree != null) {
status = "Walking to tree";walkToTree.step(true);} else {
debug("Can't walk to tree...");status = "Can't walk to tree...";}
} else {
if (tree.isVisible()) {
if (!isBusy(player)) {
if (Camera.getPitch() < 0.35) {
Camera.setPitch(0.60, 0.65);} else {
status = "Picking bananas."; return tree.interact("Pick");}
}
} else {
debug("Turning camera to tree");Camera.turnTo(tree);}
}
}

return false;}

/** * Put banana into an empty basket using the action bar. */private boolean putBananasIntoBasket() {
SlotAction action = ActionBar.getFirstAction("Basket"); if (action != null) {
status = "Putting bananas into basket."; if (Keyboard.typeKey(action.getSlot().getKeyBind())) {
if (gotBananas()) {
Execution.delayUntil(() -> !gotBananas(), 0, 500); return true;}
}
}

return false;}

/** * Check if whether the player is at Edgeville or not. */private boolean atEdgeville() {
return EDGEVILLE_AREA.contains(player);}

/** * Check if the player is at Karamja or not. */private boolean atKaramja() {
return KARAMJA_AREA.contains(player);}

/** * Check if the player has at least 5 bananas in inventory. */private boolean gotBananas() {
return (Inventory.contains(BANANA) && Inventory.getQuantity(BANANA) >= 5);}

/** * Check if the player has at least one empty basket */private boolean gotEmptyBaskets() {
return (Inventory.contains(BASKET) && Inventory.getQuantity(BASKET) >= 1);}

/** * Check if the player has at least 23 empty baskets */private boolean gotAllEmptyBaskets() {
return (Inventory.contains(BASKET) && Inventory.getQuantity(BASKET) >= 23);}

/** * Check if the the player has at least 23 filled baskets. */private boolean gotFilledBaskets() {
return (Inventory.contains(FILLED_BASKET) && Inventory.getQuantity(FILLED_BASKET) >= 23);}

/** * Check if the player can pick bananas from a tree. */private boolean canPickBananasFromTree() {
return !Inventory.isFull() && !gotBananas();}

/** * Check if the player can put bananas into an empty basket. */private boolean canPutBananasInBasket() {
return gotBananas() && gotEmptyBaskets();}

/** * Check if the teleport interface is visible. */private boolean teleportToEdgevilleOptionIsVisible() {
InterfaceComponent component = Interfaces.newQuery().texts("Edgeville.").visible().results().first(); return (component != null && component.isValid());}


private boolean teleportToKaramjaOptionIsVisible() {
InterfaceComponent component = Interfaces.newQuery().texts("Karamja.").visible().results().first(); return (component != null && component.isValid());}

private boolean isBusy(final Actor player) {
return player.isMoving() || player.getAnimationId() != -1;}

/** * Turn amount gained into amount gained per hour. * * @param amount The amount of experience. * @param elapsed The elapsed time. * @return Returns the int amount per hour. */public int getHourly(final int amount, final long elapsed) {
return (int) (amount * 3600000.0D / elapsed);}

/** * Method to format thousands decimal. * * @param i The integer to format. * @return Returns the integer as formatted number. */protected String formatNumber(int i) {
return NumberFormat.getIntegerInstance().format(i);}

/** * Helper method used to replace System.out.println(text); * * @param text The text to send to the console. */private void debug(String text) {
System.out.println(text);}

/** * Count items that are added to inventory. */@Overridepublic void onItemAdded(ItemEvent arg0) {
if (arg0.getItem().getDefinition().getName().equals("Banana")) {
BANANA_COUNT++;}
}

/* * This is where we put everything that we want to draw to the screen. * Graphics2D is the class that contains all the paint methods. */@Overridepublic void onPaint(Graphics2D g) {
int x = 5, y = 15;PROFIT_MADE = BANANA_COUNT / 5 * BANANA_BASKET_PRICE;g.drawString("Version " + getMetaData().getVersion(), x, y);g.drawString("Run time: " + runtime.getRuntimeAsString(), x, y + 15);g.drawString("Status: " + status, x, y + 30);g.drawString("Bananas: " + formatNumber(BANANA_COUNT) + " (" + formatNumber(getHourly(BANANA_COUNT, runtime.getRuntime())) + ")", x, y + 45);g.drawString("Baskets: " + formatNumber(BANANA_COUNT / 5) + " (" + formatNumber(getHourly(BANANA_COUNT /5, runtime.getRuntime())) + ")", x, y + 60);g.drawString("Profits: " + formatNumber(PROFIT_MADE) + " (" + formatNumber(getHourly(PROFIT_MADE, runtime.getRuntime())) + ")", x, y + 75);}

@Overridepublic void onPause() {
runtime.stop();}

@Overridepublic void onResume() {
runtime.start();}

}
Can you please fix your formatting?
 
Joined
Jan 8, 2015
Messages
1,427
Can you please fix your formatting?

Would this work? @Cloud

Code:
package com.runemate.geashawscripts.banana; //Imports are all the classes that we are going to use methods fromimport com.runemate.game.api.client.paint.PaintListener;import com.runemate.game.api.hybrid.RuneScape;import com.runemate.game.api.hybrid.entities.Actor;import com.runemate.game.api.hybrid.entities.GameObject;import com.runemate.game.api.hybrid.entities.Npc;import com.runemate.game.api.hybrid.entities.Player;import com.runemate.game.api.hybrid.input.Keyboard;import com.runemate.game.api.hybrid.local.Camera;import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;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.Path;import com.runemate.game.api.hybrid.location.navigation.Traversal;import com.runemate.game.api.hybrid.region.GameObjects;import com.runemate.game.api.hybrid.region.Npcs;import com.runemate.game.api.hybrid.region.Players;import com.runemate.game.api.hybrid.util.StopWatch;import com.runemate.game.api.rs3.local.hud.interfaces.eoc.ActionBar;import com.runemate.game.api.rs3.local.hud.interfaces.eoc.SlotAction;import com.runemate.game.api.rs3.net.GrandExchange;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.awt.event.KeyEvent;import java.text.NumberFormat;public class bananapicker extends LoopingScript implements PaintListener, InventoryListener {

private String status = "Starting up...";
private final StopWatch runtime = new StopWatch();
private final String BANANA = "Banana";
private final String BASKET = "Basket";
private final String FILLED_BASKET = "Bananas (5)";
private final String GLORY = "Amulet of glory";
private int BANANA_COUNT, BANANA_BASKET_PRICE, PROFIT_MADE;
final Area KARAMJA_AREA = new Area.Rectangular(new Coordinate(2905, 3154), new Coordinate(2935, 3180, 0));
final Area EDGEVILLE_AREA = new Area.Rectangular(new Coordinate(3084, 3488, 0), new Coordinate(3097, 3499, 0));
final Player player = Players.getLocal();
private Path walkToTree;@Overridepublic void onStart(String...args) {
    setLoopDelay(100, 200);
    getEventDispatcher().addListener(this);
    BANANA_BASKET_PRICE = GrandExchange.lookup(5416).getPrice();
    runtime.start();
    debug("Test.");
}

@Overridepublic void onLoop() {

    // Check if the user is logged in.if (RuneScape.isLoggedIn()) {
    if (atEdgeville()) {
        if (gotFilledBaskets()) {
            Npc banker = Npcs.newQuery().names("Banker").results().nearest();
            if (banker != null) {
                if (banker.isVisible()) {
                    if (Bank.isOpen()) {
                        performBankPreset();
                    } else {
                        openBank();
                    }
                } else {
                    debug("Turning camera to banker");
                    Camera.setPitch(0.234);
                    Camera.turnTo(banker);
                }
            }
        } else if (gotAllEmptyBaskets()) {
            teleportToKaramja();
        }
    } else if (atKaramja()) {
        if (gotFilledBaskets()) {
            teleportToEdgeville();
        } else if (canPutBananasInBasket()) {
            putBananasIntoBasket();
        } else if (canPickBananasFromTree()) {
            pickBananasFromTree();
        }
    }
}
}

/** * Teleport to Edgeville. */
private boolean teleportToEdgeville() {
    SlotAction action = ActionBar.getFirstAction(GLORY);
    if (action != null) {
        status = "Activating glory.";
        if (action.activate()) {
            if (teleportToEdgevilleOptionIsVisible()) {
                // A little extra delay.status = "Selecting Edgeville teleport.";debug("Typing key 49"); if (Keyboard.pressKey(KeyEvent.VK_1)) {
                Keyboard.releaseKey(KeyEvent.VK_1);
                Execution.delayUntil(() - > !teleportToEdgevilleOptionIsVisible(), 3000, 4000);
                return true;
            }
        } else {
            Execution.delayUntil(() - > teleportToEdgevilleOptionIsVisible(), 1000, 1500);
        }
    }
}

return false;
}

/** * Teleport to Karamja. */
private boolean teleportToKaramja() {
    SlotAction action = ActionBar.getFirstAction(GLORY);
    if (action != null) {
        status = "Activating glory.";
        if (action.activate()) {
            if (teleportToKaramjaOptionIsVisible()) {
                // A little extra delay.status = "Selecting Karamja teleport.";debug("Typing key 50"); if (Keyboard.pressKey(KeyEvent.VK_2)) {
                Keyboard.releaseKey(KeyEvent.VK_2);
                Execution.delayUntil(() - > !teleportToKaramjaOptionIsVisible(), 3000, 4000);
                return true;
            }
        } else {
            Execution.delayUntil(() - > teleportToKaramjaOptionIsVisible(), 1000, 1500);
        }
    }
}

return false;
}


/** * Perform quick banking with a bank preset. */
private boolean performBankPreset() {
    InterfaceComponent component = Interfaces.getAt(762, 41);
    if (component != null && component.isVisible()) {
        if (component.click()) {
            status = "Performing bank preset";
            debug("Performing bank preset");
            Execution.delayUntil(() - > !Bank.isOpen(), 0, 1000);
            return true;
        }
    }

    return false;
}

/** * Open the bank. */
private boolean openBank() {
    status = "Opening the bank.";
    debug("Opening the bank");
    if (Bank.open()) {
        if (!Bank.isOpen()) {
            Execution.delayUntil(() - > Bank.isOpen(), 500);
            return true;
        }
    }
    return false;
}

/** * Pick bananas from a tree. */
private boolean pickBananasFromTree() {
    GameObject tree = GameObjects.newQuery().names("Banana Tree").actions("Pick").results().nearest();
    if (tree != null) {
        if (tree.distanceTo(player) > 7) {
            debug("Tree is further than 7 steps");
            status = "Tree is further than 7 steps";
            walkToTree = Traversal.getDefaultWeb().getPathBuilder().buildTo(tree);
            if (walkToTree != null) {
                status = "Walking to tree";
                walkToTree.step(true);
            } else {
                debug("Can't walk to tree...");
                status = "Can't walk to tree...";
            }
        } else {
            if (tree.isVisible()) {
                if (!isBusy(player)) {
                    if (Camera.getPitch() < 0.35) {
                        Camera.setPitch(0.60, 0.65);
                    } else {
                        status = "Picking bananas.";
                        return tree.interact("Pick");
                    }
                }
            } else {
                debug("Turning camera to tree");
                Camera.turnTo(tree);
            }
        }
    }

    return false;
}

/** * Put banana into an empty basket using the action bar. */
private boolean putBananasIntoBasket() {
    SlotAction action = ActionBar.getFirstAction("Basket");
    if (action != null) {
        status = "Putting bananas into basket.";
        if (Keyboard.typeKey(action.getSlot().getKeyBind())) {
            if (gotBananas()) {
                Execution.delayUntil(() - > !gotBananas(), 0, 500);
                return true;
            }
        }
    }

    return false;
}

/** * Check if whether the player is at Edgeville or not. */
private boolean atEdgeville() {
    return EDGEVILLE_AREA.contains(player);
}

/** * Check if the player is at Karamja or not. */
private boolean atKaramja() {
    return KARAMJA_AREA.contains(player);
}

/** * Check if the player has at least 5 bananas in inventory. */
private boolean gotBananas() {
    return (Inventory.contains(BANANA) && Inventory.getQuantity(BANANA) >= 5);
}

/** * Check if the player has at least one empty basket */
private boolean gotEmptyBaskets() {
    return (Inventory.contains(BASKET) && Inventory.getQuantity(BASKET) >= 1);
}

/** * Check if the player has at least 23 empty baskets */
private boolean gotAllEmptyBaskets() {
    return (Inventory.contains(BASKET) && Inventory.getQuantity(BASKET) >= 23);
}

/** * Check if the the player has at least 23 filled baskets. */
private boolean gotFilledBaskets() {
    return (Inventory.contains(FILLED_BASKET) && Inventory.getQuantity(FILLED_BASKET) >= 23);
}

/** * Check if the player can pick bananas from a tree. */
private boolean canPickBananasFromTree() {
    return !Inventory.isFull() && !gotBananas();
}

/** * Check if the player can put bananas into an empty basket. */
private boolean canPutBananasInBasket() {
    return gotBananas() && gotEmptyBaskets();
}

/** * Check if the teleport interface is visible. */
private boolean teleportToEdgevilleOptionIsVisible() {
    InterfaceComponent component = Interfaces.newQuery().texts("Edgeville.").visible().results().first();
    return (component != null && component.isValid());
}


private boolean teleportToKaramjaOptionIsVisible() {
    InterfaceComponent component = Interfaces.newQuery().texts("Karamja.").visible().results().first();
    return (component != null && component.isValid());
}

private boolean isBusy(final Actor player) {
    return player.isMoving() || player.getAnimationId() != -1;
}

/** * Turn amount gained into amount gained per hour. * * @param amount The amount of experience. * @param elapsed The elapsed time. * @return Returns the int amount per hour. */
public int getHourly(final int amount, final long elapsed) {
    return (int)(amount * 3600000.0D / elapsed);
}

/** * Method to format thousands decimal. * * @param i The integer to format. * @return Returns the integer as formatted number. */
protected String formatNumber(int i) {
    return NumberFormat.getIntegerInstance().format(i);
}

/** * Helper method used to replace System.out.println(text); * * @param text The text to send to the console. */
private void debug(String text) {
    System.out.println(text);
}

/** * Count items that are added to inventory. */
@Overridepublic void onItemAdded(ItemEvent arg0) {
    if (arg0.getItem().getDefinition().getName().equals("Banana")) {
        BANANA_COUNT++;
    }
}

/* * This is where we put everything that we want to draw to the screen. * Graphics2D is the class that contains all the paint methods. */
@Overridepublic void onPaint(Graphics2D g) {
    int x = 5, y = 15;
    PROFIT_MADE = BANANA_COUNT / 5 * BANANA_BASKET_PRICE;
    g.drawString("Version " + getMetaData().getVersion(), x, y);
    g.drawString("Run time: " + runtime.getRuntimeAsString(), x, y + 15);
    g.drawString("Status: " + status, x, y + 30);
    g.drawString("Bananas: " + formatNumber(BANANA_COUNT) + " (" + formatNumber(getHourly(BANANA_COUNT, runtime.getRuntime())) + ")", x, y + 45);
    g.drawString("Baskets: " + formatNumber(BANANA_COUNT / 5) + " (" + formatNumber(getHourly(BANANA_COUNT / 5, runtime.getRuntime())) + ")", x, y + 60);
    g.drawString("Profits: " + formatNumber(PROFIT_MADE) + " (" + formatNumber(getHourly(PROFIT_MADE, runtime.getRuntime())) + ")", x, y + 75);
}

@Overridepublic void onPause() {
    runtime.stop();
}

@Overridepublic void onResume() {
    runtime.start();
}

}
 
Joined
Dec 24, 2014
Messages
81
I know I'm not a dev or script writer, but it appears to me that it's pressing both because both options are visible any time the interface is open...
Here's something to try if u think it might work... I don't see why it wouldn't... Just added a check to see if the player is not busy and an extra static delay...
Code:
/**
     * Teleport to Edgeville.
     */
    private boolean teleportToEdgeville() {
        SlotAction action = ActionBar.getFirstAction(GLORY);

        if (action != null) {
            status = "Activating glory.";
            if (action.activate()) {
                if (teleportToEdgevilleOptionIsVisible() && !isBusy()){
                        // A little extra delay.
                        status = "Selecting Edgeville teleport.";
                        debug("Typing key 49");
                        Keyboard.releaseKey(KeyEvent.VK_2);
                        Execution.delay(1000,2000);
                        Execution.delayUntil(() -> !teleportToEdgevilleOptionIsVisible(), 2000, 4000);
                        return true;
                    }
                } else {
                    Execution.delayUntil(() -> teleportToEdgevilleOptionIsVisible(), 1000, 1500);
                }
            }
        }

        return false;
    }

    /**
     * Teleport to Karamja.
     */
    private boolean teleportToKaramja() {
        SlotAction action = ActionBar.getFirstAction(GLORY);

        if (action != null) {
            status = "Activating glory.";
            if (action.activate()) {
                if (teleportToKaramjaOptionIsVisible() && !isBusy()){
                        // A little extra delay.
                        status = "Selecting Karamja teleport.";
                        debug("Typing key 50");
                        Keyboard.releaseKey(KeyEvent.VK_2);
                        Execution.delay(1000,2000);
                        Execution.delayUntil(() -> !teleportToKaramjaOptionIsVisible(), 2000, 4000);
                        return true;
                    }
                } else {
                    Execution.delayUntil(() -> teleportToKaramjaOptionIsVisible(), 1000, 1500);
                }
            }
        }

        return false;
    }
 
The only thing Alpha about me is my bots
Joined
Sep 22, 2014
Messages
618
I know I'm not a dev or script writer, but it appears to me that it's pressing both because both options are visible any time the interface is open...
Here's something to try if u think it might work... I don't see why it wouldn't... Just added a check to see if the player is not busy and an extra static delay...

I don't think that's the case - the code contains logic with the effect that the Karamja and Edgeville teleports can only be activated if the player is in a certain area each time.
 
Joined
Dec 24, 2014
Messages
81
Yes, but he is checking for the option to tele to each place to be on screen and both are on screen at the same time, every time... Both the "teleportToKaramjaOptionIsVisible" and "teleportToEdgeville" check for the same thing...
 
Joined
Dec 10, 2014
Messages
3,255
Yes, but he is checking for the option to tele to each place to be on screen and both are on screen at the same time, every time... Both the "teleportToKaramjaOptionIsVisible" and "teleportToEdgeville" check for the same thing...

You may be overlooking his atEdgeville() and atKaramja() checks.

@Arbiter
@ciresiuol is having trouble replying to this thread, but can reply fine to any others.

@Geashaw
Are you sure it's not trying to reactivate the Glory again, hence it typing 1? Try chucking it on a non-bound slot or something and seeing if the problem persists and then we can work from there
 
Last edited:
Top