Hey guys; Sorry to keep posting new threads this will be the last thread; I thought I might as well post it all so everyone can learn as there isnt to many open source scripts; I will keep this one open source but will not be adding anything else to the script as I just wanted to learn a few features for other scripts I want to release to the community;
I mainly made this script to test my cooking script which is finished I just have nothing to cook with lol. Its an AIO that supports lumby falador edgeville and alkharid which will also be released on SDN as soon as i can finish testing it; which is why i need this script finished lol
Everything works now; So mainly looking for feedback on how to improve this script; I will add a GUI within the day or so !
As i said this script will remain open source and free obviously as its open source !
Going over the script in the next few days to add comments to make it easier for someone to learn off;
here is the code so far:
import org.osbot.rs07.api.Bank;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;
@ScriptManifest(author = "Whipz", info = "Picks up Beef and trades to a Mule", logo = "", name = "BeefMule", version = 0.1)
public class main extends Script {
Area cowArea = new Area(
new int[][]{
{ 3253, 3255 },
{ 3265, 3255 },
{ 3265, 3296 },
{ 3263, 3298 },
{ 3260, 3299 },
{ 3257, 3299 },
{ 3256, 3298 },
{ 3241, 3298 },
{ 3240, 3296 },
{ 3241, 3295 },
{ 3241, 3294 },
{ 3242, 3293 },
{ 3242, 3292 },
{ 3242, 3290 },
{ 3242, 3288 },
{ 3241, 3287 },
{ 3241, 3286 },
{ 3241, 3284 },
{ 3242, 3283 },
{ 3243, 3282 },
{ 3244, 3281 },
{ 3245, 3280 },
{ 3246, 3278 },
{ 3247, 3278 },
{ 3248, 3278 },
{ 3249, 3278 },
{ 3250, 3278 },
{ 3251, 3276 },
{ 3253, 3272 }
}
);
Area muleArea = new Area(3265, 3173, 3272, 3161);
private enum State {
PICKUP, WALKTOMULE, TRADE, WALKTOPICKUP, BANK, STOP, WAIT
};
private State getState() {
if (!inventory.isFull() && cowArea.contains(myPlayer()))
return State.PICKUP;
if (inventory.isFull() && !muleArea.contains(myPlayer()))
return State.WALKTOMULE;
if(inventory.contains(2132, 1739) || bank.contains("Raw beef", "Cowhide") && muleArea.contains(myPlayer()))
return State.BANK;
if(inventory.contains(2133, 1740) || trade.isCurrentlyTrading() && muleArea.contains(myPlayer()))
return State.TRADE;
if (!inventory.isFull() && !bank.isOpen() && !bank.contains("Raw beef") && !cowArea.contains(myPlayer()))
return State.WALKTOPICKUP;
return State.WAIT;
}
public void onStart() throws InterruptedException {
}
public void onExit() {
log("Thanks for using beefMule");
}
@[member=Override]
public int onLoop() throws InterruptedException {
switch (getState()) {
case PICKUP:
doPickUp();
break;
case WALKTOMULE:
getWalking().webWalk(muleArea);
break;
case BANK:
getNotedItems();
break;
case TRADE:
tradeMule();
offerItems();
acceptTrade1();
acceptTrade2();
break;
case WALKTOPICKUP:
getWalking().webWalk(cowArea);
break;
case STOP:
this.stop();
break;
case WAIT:
sleep(random(200, 300));
break;
}
return random(200, 300);
}
private void doPickUp() throws InterruptedException {
GroundItem loot = getGroundItems().closest("Raw beef", "Cowhide");
if (!inventory.isFull() && cowArea.contains(myPlayer())
&& (loot != null) && !myPlayer().isAnimating()) {
loot.interact("Take");
log("Picking up Raw Beef");
sleep(random(750, 1500));
new ConditionalSleep(5000) {
@[member=Override]
public boolean condition() throws InterruptedException {
return !myPlayer().isMoving();
}
}.sleep();
}
}
private void tradeMule() throws InterruptedException {
@SuppressWarnings("unchecked")
Player muleAccount = getPlayers().closest(o -> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase("FlippingGold"));
if (muleAccount != null && muleAccount.isVisible()
&& muleArea.contains(myPlayer())
&& inventory.contains("Raw beef")) {
log("Trying to trade mule");
if(muleAccount.interact("Trade with")){
log("Waiting for other player to accept trade");
}
sleep(random(750, 1500));
new ConditionalSleep(5000) {
@[member=Override]
public boolean condition() throws InterruptedException {
return trade.isFirstInterfaceOpen();
}
}.sleep();
}
}
private void offerItems() throws InterruptedException {
if(trade.isFirstInterfaceOpen() && trade.isCurrentlyTrading()) {
log("Offering Loot");
getInventory().getItem("Raw beef").interact("Offer-All");
getInventory().getItem("Cowhide").interact("Offer-All");
sleep(random(750, 1500));
new ConditionalSleep(5000) {
@[member=Override]
public boolean condition() throws InterruptedException {
return trade.getOurOffers().toString() == "Raw beef";
}
}.sleep();
}
}
private void acceptTrade1() throws InterruptedException {
if(trade.isFirstInterfaceOpen()) {
trade.acceptTrade();
new ConditionalSleep(5000) {
@[member=Override]
public boolean condition() throws InterruptedException {
return trade.isSecondInterfaceOpen();
}
}.sleep();
}
}
private void acceptTrade2() {
if(trade.isSecondInterfaceOpen()) {
trade.acceptTrade();
new ConditionalSleep(5000) {
@[member=Override]
public boolean condition() throws InterruptedException {
return !trade.isCurrentlyTrading();
}
}.sleep();
}
}
private void getNotedItems() throws InterruptedException {
NPC closestBanker = getNpcs().closest("Banker");
Entity closestBankBooth = objects.closest("Bank Booth");
if (bank.isOpen()) {
if(inventory.isEmpty()) {
if (getBank().getWithdrawMode().equals(
Bank.BankMode.WITHDRAW_NOTE)) {
getBank().withdrawAll("Raw beef");
getBank().withdrawAll("Cowhide");
sleep(random(750, 1500));
bank.close();
log("Withdrawing Noted Beef");
sleep(random(750, 1500));
} else {
bank.enableMode(Bank.BankMode.WITHDRAW_NOTE);
log("changing to withdraw note mode");
sleep(random(750, 1500));
}
} else {
bank.depositAll();
}
sleep(random(1000, 2500));
} else {
int rand = random(3);
if (rand == 1) {
closestBankBooth.interact("Bank");
log("Using Bank Booth");
sleep(random(750, 1500));
} else {
closestBanker.interact("Bank");
log("Using NPC Banker");
sleep(random(750, 1500));
}
sleep(random(1000, 2500));
log("Opening Bank");
}
}
}
So any help is appreciated thanks to everyone who has helped so far;