October 25, 20241 yr 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(); } } }
December 14, 20241 yr Never really checked out trading stuff, but u can get information from the chat and act upon it: So if someone said 'hi' in chat, the bot will log 'sup', hook some methods to it and yey? @Override public final void onMessage(final Message message) { if (message == null) { return; } if (message.getMessage().toLowerCase().contains("hi")) { log("sup"); } }
Create an account or sign in to comment