BASICFreak
Newcomer
- Joined
- Jan 3, 2009
- Sythe Gold
- 0
- Messages
- 2
Fixed almost flawless now
updated code now anyone should be able to use endlessly.
Updated again now my average is 880 instead of 600 on a level 50.
made it click directly on banker
Please report any bugs to me
updated code now anyone should be able to use endlessly.
Updated again now my average is 880 instead of 600 on a level 50.
made it click directly on banker
Please report any bugs to me
Code:
import java.awt.*;
import java.util.ArrayList;
import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.event.events.ServerMessageEvent;
import com.speljohan.rsbot.event.listeners.*;
import com.speljohan.rsbot.script.*;
import com.speljohan.rsbot.script.wrappers.*;
public class LumbFlaxSpinner extends Script implements PaintListener,
ServerMessageListener {
boolean proggy = false;
long startTime = System.currentTimeMillis();
int stringsBanked = 0;
int bankFail = 0;
int wlkedtobank = 0;
final int FLAX_ID = 1779;
final int BOW_STRING_ID = 1777;
final int DOOR_CLOSE_ID = 36831;
final int BOW_STRING_CHILD_ID = 17;
final int SPINNING_WHEEL_ID = 36785;
final int SPINNING_INTERFACE_ID = 459;
final int BANK_ID = 4907;
final Color BG = new Color(123, 123, 123, 100);
final Color GREEN = new Color(0, 255, 0, 255);
final Color RED = new Color(255, 0, 0, 255);
final RSTile DOOR_CLOSE_TILE = new RSTile(3207, 3214);
final RSTile STAIRCASE_TILE = new RSTile(3205, 3208);
public String getName() {
return "Lumby Flax Spinner";
}
public double getVersion() {
return 2.0;
}
public String getAuthor() {
return "Mike Fixed By BASICFreak";
}
public String getScriptCategory() {
return "Mike's and BASICFreak Scripts/Crafting";
}
public String getScriptDescription() {
return "<html>\n" + "<head></head>\n" + "<body>\n" + "<center>"
+ "<h2>"
+ getName()
+ "</h2>"
+ "</center>\n"
+ "<b>Author:</b> "
+ getAuthor()
+ "<br/>\n"
+ "<b>Version:</b> "
+ getVersion()
+ "+<br/>\n"
+ "<br/>\n BASIC Freak: Fixed not clicking on spinner and bank thread error."
+ "<br/>\n Errors Still Remaining: There are three IDs the same as the bank booth Clicks on closest one..."
+ "<br/>\n"
+ "<b>Starting Location:</b> Lumbridge Square OR Lumbridge Castle(any floor)<br/>"
+ "<b>Function:</b> Spins Flax."
+ "<br/>"
+ "<b>Version Notes:</b> "
+ "<ul>"
+ "<li>"
+ "<b>2.0+:</b> BASICFreak's edit"
+ "<br>"
+ "<b>2.0:</b> Total Rewrite"
+ "<br>"
+ " - Runs In Lumbridge"
+ "<br>"
+ " - Includes DeathWalk"
+ "</li>"
+ "<li>"
+ "<b>1.0:</b> First Version"
+ "<br>"
+ " - Runs in Camelot"
+ "<br>"
+ " - Short Lived. Horrible script that just did the job."
+ "</li>" + "<li>" + "<b>0.*:</b> Beta Versions" + "</li>" +
"</ul>" + "</body>\n" + "</html>";
}
public boolean onStart(String[] args) {
bankFail = 0;
proggy = true;
startTime = System.currentTimeMillis();
stringsBanked = 0;
Bot.getEventManager().addListener(PaintListener.class, this);
Bot.getEventManager().addListener(ServerMessageListener.class, this);
return true;
}
public void logoutFor(int i) {}
public void onFinish() {
Bot.getEventManager().removeListener(PaintListener.class, this);
Bot.getEventManager().removeListener(ServerMessageListener.class, this);
}
public RSTile bankTile() {
return new RSTile(random(3208, 3209), random(3215, 3220));
}
public RSTile staircaseTile() {
return new RSTile(random(3205, 3207), random(3205, 3211));
}
public boolean isInSpinningRoom() {
RSTile myLocation = getMyPlayer().getLocation();
int myX = myLocation.getX();
int myY = myLocation.getY();
if (myX >= 3208 && myX <= 3212 && myY >= 3212 && myY <= 3217
&& getPlane() == 1) {
return true;
}
return false;
}
public boolean isInBank() {
RSTile myLocation = getMyPlayer().getLocation();
int myX = myLocation.getX();
int myY = myLocation.getY();
if (myX >= 3207 && myX <= 3210 && myY >= 3215 && myY <= 3220
&& getPlane() == 2) {
return true;
}
return false;
}
public RSTile spinningRoomTile() {
return new RSTile(random(3208, 3212), random(3214, 3212));
}
public RSTile outsideDoor() {
return new RSTile(random(3205, 3207), random(3212, 3216));
}
public boolean isDoorClosed() {
if (getPlane() == 1 && !isInSpinningRoom()) {
if (Calculations.canReach(spinningRoomTile(), true)) {
return false;
}
}
if (getPlane() == 1 && isInSpinningRoom()) {
if (Calculations.canReach(staircaseTile(), true)) {
return false;
}
}
log("door is closed");
return true;
}
public boolean walkToTile(RSTile tile) {
if (walkPathMM2(generatePath(tile), 17)) {
return true;
}
return false;
}
public int flaxCount() {
return getInventoryCount(FLAX_ID);
}
public int bowstringCount() {
return getInventoryCount(BOW_STRING_ID);
}
public int loop() {
if (getMyPlayer().isMoving()) {
return random(300, 500);
}
try {
int height = getPlane();
if (!RSInterface.getInterface(SPINNING_INTERFACE_ID).isValid()) {
if (flaxCount() == 0) {
atInterface(SPINNING_INTERFACE_ID, 12);
} else if (!bank.getInterface().isValid()) {
if (getEnergy() >= random(50, 99)) {
setRun(true);
}
}
}
if (getPlane() == 0 || distanceTo(new RSTile(3211, 3219)) > 20) {
deathWalk();
}
if (height == 1) { // flax level
if (flaxCount() > 0 || getMyPlayer().isInCombat()) {
if (!isInSpinningRoom()) {
if (isDoorClosed()) {
if (walkToTile(outsideDoor())) {
RSObject door = getObjectAt(DOOR_CLOSE_TILE);
if (door == null
|| door.getID() != DOOR_CLOSE_ID) {
return random(300, 500);
}
atDoor(door, "east", "Open");
return random(300, 500);
}
} else {
walkToTile(spinningRoomTile());
}
} else {
for (int i = 0; i <= 10; i++) {
if (getMyPlayer().getAnimation() != -1) {
return random(300, 500);
} else {
wait(random(100, 150));
}
}
if (flaxCount() == 0) {
return random(300, 500);
}
if (RSInterface.getInterface(SPINNING_INTERFACE_ID)
.isValid()) {
atInterface(SPINNING_INTERFACE_ID,
BOW_STRING_CHILD_ID, "all");
return random(300, 500);
}
RSObject spinner = findObject(SPINNING_WHEEL_ID);
if (spinner == null) {
return random(300, 500);
}
if (!atObject(spinner, "Spin Spinning Wheel")) {
turnToTile(spinner.getLocation());
}
return random(300, 500);
}
} else {
if (isDoorClosed()) {
RSObject door = getObjectAt(DOOR_CLOSE_TILE);
if (door == null || door.getID() != DOOR_CLOSE_ID) {
return random(300, 500);
}
atDoor(door, "east", "Open");
return random(300, 500);
}
if (!walkToTile(staircaseTile())) {
return random(300, 500);
}
if (!atTile(STAIRCASE_TILE, "Climb-up")) {
turnToTile(STAIRCASE_TILE);
}
}
}
if (height == 2) { // bank level
if (flaxCount() > 0) {
if (!walkToTile(staircaseTile())) {
return random(300, 500);
}
if (!atTile(STAIRCASE_TILE, "Climb-down")) {
turnToTile(STAIRCASE_TILE);
}
} else {
if (!isInBank()) {
walkToTile(bankTile());
return random(300, 500);
}
if (bank.getInterface().isValid()) {
int temp = bowstringCount();
if (bank.depositAllExcept(FLAX_ID)) {
stringsBanked += temp;
moveMouse(random(38, 74), random(92, 124));
if (!getTopText().contains("flax")) {
bankFail++;
if (bankFail >= 10) {
log("Banking failed. Possibly ran out of flax!");
return -1;
}
return random(300, 500);
}
clickMouse(false);
if (atMenu("Withdraw-All Flax")) {
bankFail = 0;
return random(500, 1000);
}
}
return random(300, 500);
}
RSNPC banker = getNearestNPCByID(BANK_ID);
if (!atNPC(banker, "Bank Bank Tutor")) {
turnToTile(banker.getLocation());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return random(300, 500);
}
public void deathWalk() {
if (getPlane() != 0 && distanceTo(new RSTile(3211, 3219)) <= 20) {
return;
}
if (distanceTo(new RSTile(3211, 3219)) > 20) {
castSpell(1);
}
}
public void onRepaint(Graphics g) {
if (isLoggedIn() && proggy == true) {
long millis = System.currentTimeMillis() - startTime;
long seconds2 = millis / 1000;
long hours = millis / (1000 * 60 * 60);
millis -= hours * 1000 * 60 * 60;
long minutes = millis / (1000 * 60);
millis -= minutes * 1000 * 60;
long seconds = millis / 1000;
String hoursString = "";
String minutesString = "";
String secondsString = seconds + "";
String type = "seconds";
if (minutes > 0) {
minutesString = minutes + ":";
type = "minutes";
}
if (hours > 0) {
hoursString = hours + ":";
type = "hours";
}
if (minutesString.length() == 1) {
minutesString = "0" + minutesString;
}
if (hoursString.length() == 1) {
hoursString = "0" + hoursString;
}
if (secondsString.length() == 1) {
secondsString = "0" + secondsString;
}
int x = 18;
int y = 18;
g.setColor(BG);
g.fill3DRect(14, 25, 210, 165, true);
g.setColor(GREEN);
g.drawString(
getName() + " v" + getVersion() + "+ by " + getAuthor(), x,
y += 20);
g.drawString("Running for " + hoursString + minutesString
+ secondsString + " " + type + ".", x, y += 20);
g.setColor(RED);
g.drawString("Spun "
+ (stringsBanked + getInventoryCount(BOW_STRING_ID))
+ " flax.", x, y += 20);
if (seconds2 != 0) {
g.drawString("Averaging "
+ (stringsBanked + getInventoryCount(BOW_STRING_ID))
* 3600 / seconds2 + " strings per hour.", x, y += 20);
}
}
}
public void serverMessageRecieved(ServerMessageEvent e) {
String message = e.getMessage().toLowerCase();
if (message.contains("You need to wait another ")
&& message.contains(" to cast this spell.")) {
int num = Integer.parseInt(message.split(" ")[5]);
logoutFor(num * 1000 * 60 * 60);
}
}
public int getAngleToCoordinates(int x2, int y2) {
int x1 = getMyPlayer().getLocation().getX();
int y1 = getMyPlayer().getLocation().getY();
int x = x1 - x2;
int y = y1 - y2;
double angle = Math.toDegrees(Math.atan2(x, y));
if (x == 0 && y > 0) {
angle = 180;
}
if (x < 0 && y == 0) {
angle = 90;
}
if (x == 0 && y < 0) {
angle = 0;
}
if (x < 0 && y == 0) {
angle = 270;
}
if (x < 0 && y > 0) {
angle += 270;
}
if (x > 0 && y > 0) {
angle += 90;
}
if (x < 0 && y < 0) {
angle = Math.abs(angle) - 180;
}
if (x > 0 && y < 0) {
angle = Math.abs(angle) + 270;
}
if (angle < 0) {
angle = 360 + angle;
}
if (angle >= 360) {
angle -= 360;
}
return (int) angle;
}
public void turnToTile(RSTile tile) {
int angle = getAngleToCoordinates(tile.getX(), tile.getY());
angle = angle + random(-20, 20);
if (angle < 0) {
angle = 360 + angle;
}
if (angle >= 360) {
angle -= 360;
}
setCameraRotation2(angle);
}
public void setCameraRotation2(int degrees) {
// Made by aftermath. Was suggested into SVN and i just added it into
// here until somebody does the right thing
char left = 37;
char right = 39;
char whichDir = left;
int start = getCameraAngle();
if (start < 180) {
start += 360;
}
if (degrees < 180) {
degrees += 360;
}
if (degrees > start) {
if (degrees - 180 < start) {
whichDir = right;
}
} else if (start > degrees) {
if (start - 180 >= degrees) {
whichDir = right;
}
}
degrees %= 360;
Bot.getInputManager().pressKey(whichDir);
int timeWaited = 0;
while (getCameraAngle() > degrees + 5 || getCameraAngle() < degrees - 5) {
wait(10);
timeWaited += 10;
if (timeWaited > 500) {
int time = timeWaited - 500;
if (time == 0) {
Bot.getInputManager().pressKey(whichDir);
} else if (time % 40 == 0) {
Bot.getInputManager().pressKey(whichDir);
}
}
}
Bot.getInputManager().releaseKey(whichDir);
}
public RSTile[] generatePath(RSTile tile) {
return generatePath(tile.getX(), tile.getY());
}
public RSTile[] generatePath(int destinationX, int destinationY) { // Most
// credits
// go to
// aftermath...
// I
// asked
// for a
// theory
// and
// he
// gives
// me
// the
// whole
// method.
// ~Mike
int startX = getMyPlayer().getLocation().getX();
int startY = getMyPlayer().getLocation().getY();
double dx, dy;
ArrayList<RSTile> list = new ArrayList<RSTile>();
list.add(new RSTile(startX, startY));
while (Math.hypot(destinationY - startY, destinationX - startX) > 8) {
dx = destinationX - startX;
dy = destinationY - startY;
int gamble = random(14, 17);
while (Math.hypot(dx, dy) > gamble) {
dx *= .95;
dy *= .95;
}
startX += (int) dx;
startY += (int) dy;
list.add(new RSTile(startX, startY));
}
list.add(new RSTile(destinationX, destinationY));
return list.toArray(new RSTile[list.size()]);
}
public String getTopText() {
return getMenuItems().get(0).toLowerCase();
}
RSTile current2 = null;
public boolean walkPathMM2(RSTile[] path, int maxDist) {
try {
RSTile next = nextTile(path, maxDist);
if (next != null && !next.equals(current2)) {
walkTileMM(next);
current2 = next;
return false;
} else if (next != null && next.equals(current2)) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
public RSTile nextTile2(RSTile[] path, int maxDist) {
RSTile cur = getMyPlayer().getLocation();
for (int i = path.length - 1; i >= 0; i--) {
if (distanceBetween(cur, path[i]) <= maxDist) {
return path[i];
}
}
return null;
}
}