Jump to content

CoffeeNow

Members
  • Posts

    4
  • Joined

  • Last visited

  • Feedback

    0%

Profile Information

  • Gender
    Male

CoffeeNow's Achievements

Newbie

Newbie (1/10)

0

Reputation

  1. Hey everyone! Thanks for being patient with me on my learning adventure. I'm making a begger script that is basically an excuse to practice playing with the osbot API and get more comfortable. I have two scripts below, one which handles the main operation (BeggingScript.java) and one that handles trade (Trader.java). Everything is working wonderfully EXCEPT trade requests. I can't seem to get the API surrounding identifying trade requests to work. I have no problem accepting them once I identify the trade request in the chat, but I only got that working once accidently. Any ideas on how to recognize trade requests or use the API in this way? Love you all, Trader.java import org.osbot.rs07.api.Trade; import org.osbot.rs07.script.MethodProvider; import org.osbot.rs07.utility.ConditionalSleep; public class Trader { private MethodProvider api; public Trader(MethodProvider api) { this.api = api; } // Detects if a trade has been initiated public boolean isInTrade() { boolean tradingStatus = api.getTrade().isCurrentlyTrading(); api.log("Trade status detected: " + tradingStatus); return tradingStatus; } public void handleTrade() { Trade trade = api.getTrade(); // Attempt to accept on first trade interface if (trade.isFirstInterfaceOpen()) { api.log("First trade interface detected; attempting to accept."); new ConditionalSleep(2000) { @Override public boolean condition() { return trade.acceptTrade(); } }.sleep(); api.log("Accepted trade on first interface."); // Attempt to accept on second trade interface } else if (trade.isSecondInterfaceOpen()) { api.log("Second trade interface detected; attempting to accept."); new ConditionalSleep(2000) { @Override public boolean condition() { return trade.acceptTrade(); } }.sleep(); api.log("Accepted trade on second interface."); } else { api.log("No trade interface detected; awaiting trade."); } } } BeggingScript.java import org.osbot.rs07.api.Keyboard; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(name = "BeggingScript", author = "Assistant", version = 1.1, info = "Begging and trade handling script", logo = "") public class BeggingScript extends Script { private Trader trader; private long lastMessageTime = 0; private static final int MESSAGE_INTERVAL = 6000; // 6 seconds between messages private String[] messages = {"Can anyone spare 5k?", "Can anyone spare some gp?"}; @Override public void onStart() { trader = new Trader(this); log("BeggingScript started."); } @Override public int onLoop() throws InterruptedException { if (trader.isInTrade()) { log("In trade; pausing messages."); trader.handleTrade(); } else { log("Not in trade; sending messages."); sendMessage(); } return 1000; } private void sendMessage() { if (System.currentTimeMillis() - lastMessageTime > MESSAGE_INTERVAL) { int index = random(0, messages.length); String message = messages[index]; getKeyboard().typeString(message); log("Sent message: " + message); lastMessageTime = System.currentTimeMillis(); } } }
  2. Code if I didn't like it properly. My bad! import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.util.concurrent.TimeUnit; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "You", info = "Begging Script", name = "BeggingScript", version = 0, logo = "") public class Main extends Script { private static final Position START_POSITION = new Position(3200, 3200, 0); // replace with actual coordinates private long lastMessageTime = System.currentTimeMillis(); private static final long MESSAGE_INTERVAL = TimeUnit.SECONDS.toMillis(30); // send a message every 30 seconds private boolean isInTrade = false; @Override public void onStart() { log("Begging Script Started!"); } @Override public int onLoop() throws InterruptedException { if (!isInTrade) { checkAndSendMessage(); } checkForTrade(); handleInventory(); return random(200, 300); } // Sends a begging message at intervals private void checkAndSendMessage() { if (System.currentTimeMillis() - lastMessageTime > MESSAGE_INTERVAL) { getKeyboard().typeString("Can anyone spare 5k?", true); // type the begging message lastMessageTime = System.currentTimeMillis(); } } // Check if we are in a trade, handle it private void checkForTrade() throws InterruptedException { if (getTrade().isCurrentlyTrading()) { isInTrade = true; log("Trade detected, handling trade..."); handleTrade(); } else { isInTrade = false; } } // Handles the trade interaction private void handleTrade() throws InterruptedException { long tradeStartTime = System.currentTimeMillis(); while (getTrade().isCurrentlyTrading()) { if (getTrade().isFirstInterfaceOpen()) { getTrade().acceptTrade(); // click accept in the first trade window } else if (getTrade().isSecondInterfaceOpen()) { getTrade().acceptTrade(); // click accept in the second trade window } // If the trade takes too long, decline it if (System.currentTimeMillis() - tradeStartTime > 60000) { log("Trade taking too long, declining..."); getTrade().declineTrade(); break; } // Check if the player is dragged more than 3 tiles away and cancel the trade if (myPlayer().getPosition().distance(START_POSITION) > 3) { log("Trade dragging detected, cancelling trade..."); getTrade().declineTrade(); getWalking().webWalk(START_POSITION); break; } } } // Handle full inventory, banking, and returning to start position private void handleInventory() throws InterruptedException { if (getInventory().isFull()) { log("Inventory full, heading to bank..."); getBank().open(); if (getBank().isOpen()) { getBank().depositAll(); getKeyboard().pressKey(KeyEvent.VK_ESCAPE); // exit the bank } } // Return to start position if moved away if (myPlayer().getPosition().distance(START_POSITION) > 3) { log("Returning to start position..."); getWalking().webWalk(START_POSITION); } } @Override public void onExit() { log("Thanks for running the Begging Script!"); } @Override public void onPaint(Graphics2D g) { // You can add any on-screen painting here for debugging } }
  3. Hey! First attempt at developing scripts and I've worked through most issues: 1. The code compiles without errors. 2. When building the artifact, I have it set up correctly so that the import features from osbot work properly. 3. The jar file does appear in the OSbot script folder but does not appear in the OsBot's script list. Here is the code. Any suggestions are greatly appreciated! PS: my goal is to make a script function, then I will return and actually make it a good script. Therefore, don't worry too much about the code logic but rather that it will load in osbot. BeggingScript.java
×
×
  • Create New...