February 20, 20178 yr Hello, I am looking for a bit of help for player trading. i have this so far for the task import org.osbot.rs07.api.ui.Message; import org.osbot.rs07.script.MethodProvider; public class trade extends Task { public trade(MethodProvider api) { super(api); } @Override public boolean canProcess() { return Message.MessageType.RECEIVE_TRADE; (I need the right command to trigger the task, when it has seen that a player has traded do the task) } @Override public void process() { api.log("we have been traded"); (I need help with the bot clicking to start the trade, accepting both trade windows) } }
February 20, 20178 yr Use a message listener to check for trade messages. If it receives one set some boolean to true indicating that the script should begin the trading task. Also store the username of the player trading with you. Then interact with that player to commence trading. There are methods for interacting with the trade window in the API.
February 20, 20178 yr Author 11 minutes ago, Explv said: Use a message listener to check for trade messages. If it receives one set some boolean to true indicating that the script should begin the trading task. Also store the username of the player trading with you. Then interact with that player to commence trading. There are methods for interacting with the trade window in the API. is this the right command to listen for this? Message.MessageType.RECEIVE_TRADE; if so how do i set boolean to true?
February 20, 20178 yr 5 minutes ago, olstan said: is this the right command to listen for this? Message.MessageType.RECEIVE_TRADE; if so how do i set boolean to true? You need to use a MessageListener You can add one by calling api.getBot().addMessageListener(messageListener); Check that the message received is of type Message.MessageType.RECEIEVE_TRADE Then set a global boolean variable inside your Task class to true And return that boolean variable from your canProcess method
February 20, 20178 yr 12 minutes ago, olstan said: if so how do i set boolean to true? I suspect you may need to spend some more time learning Java, before writing scripts
February 20, 20178 yr Author is this close? @Override public boolean canProcess() { MessageListener MessageListener = null; api.getBot().addMessageListener(MessageListener); Message.MessageType.RECEIVE_TRADE; return true; 6 minutes ago, Explv said: I suspect you may need to spend some more time learning Java, before writing scripts The problem i have, is quite bad dyslexia, i had the same problems learning C with man pages. I struggle to interpret API But once i get to grips i find it easier
February 20, 20178 yr 5 minutes ago, olstan said: is this close? @Override public boolean canProcess() { MessageListener MessageListener = null; api.getBot().addMessageListener(MessageListener); Message.MessageType.RECEIVE_TRADE; return true; No that is not close. You have to create a new instance of MessageListener, how could a null MessageListener be of any use? You also only want to add a message listener once, not every time canProcess() is called. I understand you may have bad dyslexia, I am not trying to be rude, I am just saying that you may want to follow some Java tutorials before trying to write scripts, because it seems like you don't understand the fundamentals just yet.
February 20, 20178 yr Author 10 minutes ago, Explv said: No that is not close. You have to create a new instance of MessageListener, how could a null MessageListener be of any use? You also only want to add a message listener once, not every time canProcess() is called. I understand you may have bad dyslexia, I am not trying to be rude, I am just saying that you may want to follow some Java tutorials before trying to write scripts, because it seems like you don't understand the fundamentals just yet. I know wasn't trying to be rude. I have managed to search snippets of other peoples posts, and since then have progressed quite well. This is just a big part i am stuck with. @Override public boolean canProcess() { MessageListener MessageListener; api.getBot().addMessageListener(MessageListener); Message.MessageType.RECEIVE_TRADE; return true;