September 12, 201510 yr 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
September 12, 201510 yr Author 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
September 12, 201510 yr public void onMessage(Message message){ String msg = message.getMessage(); //gets the raw message from the chatbox //perform trimming }
September 12, 201510 yr onMessage() is for text appearing over character text i think nope. also there are different types of Message.Type
September 12, 201510 yr Author 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
September 12, 201510 yr get the substring of the string. then convert the string into an int http://www.tutorialspoint.com/java/java_string_substring.htm
September 12, 201510 yr 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.
September 12, 201510 yr 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
September 12, 201510 yr Author 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
September 12, 201510 yr 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, 201510 yr by Isolate
September 12, 201510 yr 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
September 13, 201510 yr use regex String str = getMessage().replaceAll("\\D+", ""); Integer.parseInt(str); Edited September 13, 201510 yr by Precise
September 13, 201510 yr Author 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
Create an account or sign in to comment