- Joined
- Nov 2, 2015
- Messages
- 17
- Thread Author
- #1
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.
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: