Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • how to check if chat has a trade option?


    pokemonhuang

    Recommended Posts

    by implementing the AdvancedMessageListener

     

    class main implements AdvancedMessageListener

    @Override
        public void onTradeMessage(Message paramMessage) {
      

        }
     

    Link to comment
    Share on other sites

    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

    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

    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

    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

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.