Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need a lil bit of help Strings / Ints from line of text!

Featured Replies

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 :)

 

onMessage() is for text appearing over character text i think

  • 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 :/

onMessage() is for text appearing over character text i think

nope.

 

also there are different types of Message.Type

  • 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

 

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 

  • 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 :)

 

thanks, gunna look into this right away, much appreciated, il let you no how I get on, thanks again smile.png

 

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 smile.png

 

 @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 by Isolate

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

use regex

 

String str = getMessage().replaceAll("\\D+", "");

Integer.parseInt(str); 

Edited by Precise

  • 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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.