pokemonhuang 1 Share Posted October 12, 2018 lets say i want to check my chat box for a trade option. how do i do that? Link to comment Share on other sites More sharing options...
None 227 Share Posted October 12, 2018 by implementing the AdvancedMessageListener class main implements AdvancedMessageListener @Override public void onTradeMessage(Message paramMessage) { } Link to comment Share on other sites More sharing options...
pokemonhuang 1 Author Share Posted October 12, 2018 @None can u give me a code example of how to do that? i'm not sure how to implement a listener Link to comment Share on other sites More sharing options...
None 227 Share Posted October 12, 2018 13 minutes ago, pokemonhuang said: @None can u give me a code example of how to do that? i'm not sure how to implement a listener package test; import java.awt.Graphics; import org.dreambot.api.methods.Calculations; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.script.listener.AdvancedMessageListener; import org.dreambot.api.wrappers.widgets.message.Message; @ScriptManifest(author = "None", category = Category.MISC, description = "Message Test", name = "Message Test", version = 1.0) public class test extends AbstractScript implements AdvancedMessageListener { @Override public void onAutoMessage(Message arg0) { // TODO Auto-generated method stub } @Override public void onClanMessage(Message arg0) { // TODO Auto-generated method stub } @Override public void onGameMessage(Message arg0) { // TODO Auto-generated method stub } @Override public void onPlayerMessage(Message arg0) { // TODO Auto-generated method stub } @Override public void onPrivateInMessage(Message arg0) { // TODO Auto-generated method stub } @Override public void onPrivateInfoMessage(Message arg0) { // TODO Auto-generated method stub } @Override public void onPrivateOutMessage(Message arg0) { // TODO Auto-generated method stub } @Override public void onTradeMessage(Message arg0) { String personToTrade = "JimmonySmicket"; if (arg0.getMessage().toLowerCase().contains("wants to trade") && arg0.getMessage().toLowerCase().contains(personToTrade)) { if (getPlayers().closest(personToTrade) !=null) getTrade().tradeWithPlayer(personToTrade); } } @Override public int onLoop() { // TODO Auto-generated method stub return 0; } } Link to comment Share on other sites More sharing options...
pokemonhuang 1 Author Share Posted October 12, 2018 @none where would i get the argument for onTradeMessage method? Link to comment Share on other sites More sharing options...
None 227 Share Posted October 12, 2018 23 minutes ago, pokemonhuang said: @none where would i get the argument for onTradeMessage method? not sure what you mean, after implementing the listener the different void messages types are required, i posted a full class though so you could just copy them all from what i posted Link to comment Share on other sites More sharing options...
pokemonhuang 1 Author Share Posted October 12, 2018 i don't use event Listener often. the time i used it, was when i had to detect mouse click or move, you know stuff like that. From my understanding, in this case i have to call "OnTradeMessage" and constantly provide a message. right? How to i extract the message from the chat box? im not sure if my understanding of using event listener is correct. 😅 But right now im trying to different approach. im using the widgetChild class to extract the message. Link to comment Share on other sites More sharing options...
None 227 Share Posted October 12, 2018 3 minutes ago, pokemonhuang said: i don't use event Listener often. the time i used it, was when i had to detect mouse click or move, you know stuff like that. From my understanding, in this case i have to call "OnTradeMessage" and constantly provide a message. right? How to i extract the message from the chat box? im not sure if my understanding of using event listener is correct. 😅 But right now im trying to different approach. im using the widgetChild class to extract the message. Listeners ...listen.. they would flag every time they detect the type of message its supposed to find. so onTradeMessage would alert the class everytime there was any kind of trade message. so if you review the code i posted, every time theres a trade message on the chat box if it contains the pharase wants to trade and also contains the name of the player you want to trade with it will execute. Link to comment Share on other sites More sharing options...
pokemonhuang 1 Author Share Posted October 12, 2018 ohhh, this works! thank you so much. this is much easier than using widetChild. thank you thank you thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.