January 2, 201610 yr Hi, I have been searching round the API but can't seems to find a listener I could implement that gets executed when a game event (like A magical force stops you from moving) appears on the game log. Or is there some other way of reading these?
January 2, 201610 yr You need to get a message listener, the method is onMessage() if I recall correctly. EDIT: I.e private void onMessage(String message) { if(message.contains("You get some oak logs.")) { itemsMade ++; } } You can make specific message type listeners too: if you put that in the onMessage method if(getType().equals(Message.MessageType.GAME)) { // game message } if(getType().equals(Message.MessageType.PLAYER)) { // player message } and in the onStart() method: getBot().addMessageListener(this); Edited January 2, 201610 yr by Vilius
January 2, 201610 yr Script implements all listeners: abstract class Script extends MethodProvider implements Painter, MessageListener, ConfigListener, LoginResponseCodeListener, AudioListener So you just need to override public void onMessage(Message m) in your script
January 2, 201610 yr Hi, I have been searching round the API but can't seems to find a listener I could implement that gets executed when a game event (like A magical force stops you from moving) appears on the game log. Or is there some other way of reading these? You need to get a message listener, the method is onMessage() if I recall correctly. private void onMessage(String message) { if(message.contains("You get some oak logs.")) { itemsMade ++; } } You can do this, but this example is incorrect, the argument is not a String. It should be: @Override public void onMessage(Message message){ if(e.getType() == Message.MessageType.GAME && e.getMessage().equals("A magical force stops you from moving")){ // do something } } Edited January 2, 201610 yr by Explv
January 2, 201610 yr You can do this, but this example is incorrect, the argument is not a String. It should be: @Override public void onMessage(Message message){ if(e.getType() == Message.MessageType.GAME && e.getMessage().equals("A magical force stops you from moving")){ // do something } } Ah yes, been some time when I used message listeners :x
January 3, 201610 yr Author Brilliant guys thanks, also one last thing so I don't open an other thread, do you know how you can fetch if a player is skulled or not? NVM got it from Player.getSkullIcon() Edited January 3, 201610 yr by Tazmania
Create an account or sign in to comment