moler Posted September 12, 2015 Share Posted September 12, 2015 I'm struggling with my onMessage(), this is what I wont - e.g. when it comes up in chat box - your ring of dueling has 6 charges remaining. how do I go about storing only certain parts of that text e.g. ringName = ""Ring of dueling"; chargesLeft = 6. thanks in advance to anyone that can help me Quote Link to comment Share on other sites More sharing options...
Chris Posted September 12, 2015 Share Posted September 12, 2015 onMessage() is for text appearing over character text i think Quote Link to comment Share on other sites More sharing options...
moler Posted September 12, 2015 Author Share Posted September 12, 2015 umm, so is there no way to grab the server messages? and if so I still need help on how to grab the text I need from it Quote Link to comment Share on other sites More sharing options...
Extreme Scripts Posted September 12, 2015 Share Posted September 12, 2015 public void onMessage(Message message){ String msg = message.getMessage(); //gets the raw message from the chatbox //perform trimming } Quote Link to comment Share on other sites More sharing options...
Joseph Posted September 12, 2015 Share Posted September 12, 2015 onMessage() is for text appearing over character text i think nope. also there are different types of Message.Type Quote Link to comment Share on other sites More sharing options...
moler Posted September 12, 2015 Author Share Posted September 12, 2015 public void onMessage(Message message){ String msg = message.getMessage(); //gets the raw message from the chatbox //perform trimming } yes I have that part, its mainly the trimming part I'm struggling with, is there anywhere I can read up? can some1 pnt me in the right direction? I'm not really sure what I need to read up on when it comes to trimming text :p Quote Link to comment Share on other sites More sharing options...
Joseph Posted September 12, 2015 Share Posted September 12, 2015 get the substring of the string. then convert the string into an int http://www.tutorialspoint.com/java/java_string_substring.htm 1 Quote Link to comment Share on other sites More sharing options...
empathy Posted September 12, 2015 Share Posted September 12, 2015 get the substring of the string. then convert the string into an int http://www.tutorialspoint.com/java/java_string_substring.htm You could also split the string, which would be easier. Quote Link to comment Share on other sites More sharing options...
Isolate Posted September 12, 2015 Share Posted September 12, 2015 Why not do everything the hard way. private int ringUsesLeft(){ Item inventoryItem = inventory.getItem(new Filter<Item>() { @Override public boolean match(Item item) { return item != null && item.getName().contains("Ring of dueling"); } }); Item wornItem = equipment.getItem(new Filter<Item>() { @Override public boolean match(Item item) { return item != null && item.getName().contains("Ring of dueling"); } }); if(inventoryItem != null){ String toRip = inventoryItem.getName(); String butchered = toRip.replace("Ring of duelling(", "").replace(")", "").replace(" ", ""); if(butchered != null) { return Integer.valueOf(butchered); }else{ log("We Fucked Up!"); } }else if(wornItem != null){ String toRip = wornItem.getName(); String butchered = toRip.replace("Ring of duelling(", "").replace(")", "").replace(" ", ""); if(butchered != null) { return Integer.valueOf(butchered); }else{ log("We Fucked Up!"); } } return 0; } i'm like 99.99% sure I don't know the exact name spacing so it'll need tweaking Quote Link to comment Share on other sites More sharing options...
moler Posted September 12, 2015 Author Share Posted September 12, 2015 get the substring of the string. then convert the string into an int http://www.tutorialspoint.com/java/java_string_substring.htm thanks, gunna look into this right away, much appreciated, il let you no how I get on, thanks again Why not do everything the hard way. private int ringUsesLeft(){ Item inventoryItem = inventory.getItem(new Filter<Item>() { @Override public boolean match(Item item) { return item != null && item.getName().contains("Ring of dueling"); } }); Item wornItem = equipment.getItem(new Filter<Item>() { @Override public boolean match(Item item) { return item != null && item.getName().contains("Ring of dueling"); } }); if(inventoryItem != null){ String toRip = inventoryItem.getName(); String butchered = toRip.replace("Ring of duelling(", "").replace(")", "").replace(" ", ""); if(butchered != null) { return Integer.valueOf(butchered); }else{ log("We Fucked Up!"); } }else if(wornItem != null){ String toRip = wornItem.getName(); String butchered = toRip.replace("Ring of duelling(", "").replace(")", "").replace(" ", ""); if(butchered != null) { return Integer.valueOf(butchered); }else{ log("We Fucked Up!"); } } return 0; } i'm like 99.99% sure I don't know the exact name spacing so it'll need tweaking its not just about teleports, I wonted it for poison, antifire, kills remaining on slayer task ect... but thanks for the post appreciated, I just need to use the server messages for most of the things needed to be stored Quote Link to comment Share on other sites More sharing options...
Isolate Posted September 12, 2015 Share Posted September 12, 2015 (edited) thanks, gunna look into this right away, much appreciated, il let you no how I get on, thanks again its not just about teleports, I wonted it for poison, antifire, kills remaining on slayer task ect... but thanks for the post appreciated, I just need to use the server messages for most of the things needed to be stored @Override public void onMessage(Message m) throws InterruptedException { super.onMessage(m); /*message you want : our ring of dueling has 6 charges remaining. , cut it back to the number so you could do : our ring of dueling has or look for both halves exlcuding the number: "our ring of dueling has " , " charges remaining". but the first should work anyway */ String theMessage = "our ring of dueling has "; if(m.getMessage().contains(theMessage)){ String butcherMessage = m.getMessage().replace(theMessage, "").replace(" charges remaining.", ""); int result = Integer.valueOf(butcherMessage); //use result here } } Edited September 12, 2015 by Isolate Quote Link to comment Share on other sites More sharing options...
Joseph Posted September 12, 2015 Share Posted September 12, 2015 You could also split the string, which would be easier. if you split the string it will be harder for him to find what he wants. @Override public void onMessage(Message m) throws InterruptedException { super.onMessage(m); /*message you want : our ring of dueling has 6 charges remaining. , cut it back to the number so you could do : our ring of dueling has or look for both halves exlcuding the number: "our ring of dueling has " , " charges remaining". but the first should work anyway */ String theMessage = "our ring of dueling has "; if(m.getMessage().contains(theMessage)){ String butcherMessage = m.getMessage().replace(theMessage, "").replace(" charges remaining.", ""); int result = Integer.valueOf(butcherMessage); //use result here } } @op http://www.tutorialspoint.com/java/java_string_replace.htm Quote Link to comment Share on other sites More sharing options...
Isolate Posted September 13, 2015 Share Posted September 13, 2015 (edited) missunderstood, ignore Edited September 13, 2015 by Isolate Quote Link to comment Share on other sites More sharing options...
Precise Posted September 13, 2015 Share Posted September 13, 2015 (edited) use regex String str = getMessage().replaceAll("\\D+", ""); Integer.parseInt(str); Edited September 13, 2015 by Precise Quote Link to comment Share on other sites More sharing options...
moler Posted September 13, 2015 Author Share Posted September 13, 2015 use regex String str = getMessage().replaceAll("\\D+", ""); Integer.parseInt(str); iv accually just been looking at regex, iis there a method to only read numbers, then can I make that into and int for counting with? basicly like this = String text = "Hello, my name is bob, and I'm 37"; int age = 37; use regex String str = getMessage().replaceAll("\\D+", ""); Integer.parseInt(str); Thanks for this Quote Link to comment Share on other sites More sharing options...