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
  • Getting total time played on an account


    420x69x420

    Recommended Posts

    Here is some code I wrote to interpret the total age of an account based on the text in the new account mini-tab in the Quests main tab. It assumes you already have the playtime tab open, and the chat dialogue to Reallyreallyreallyreally view your playtime really for sure has been gone through already. At the end of the code block the int variable "gameTimeHours" has either 0 hours, 1-19 hours, or 20-24 hours. These correspond to less than 1 hour playtime, less than 20 hours playtime, and over 20 hours playtime respectively, even if the playtime has one or more days. If you want the formatted text to display in your Paint for example "2 days, 4 hours, 39 minutes" then you can use the String variable "timePlayed" afterwards.

     

    int gameTimeHours;
    String timeplayed = Widgets.getWidgetChild(712,2,100).getText();
    int hoursplayed = 0;
    int daysplayed = 0;
    int minutesplayed = 0;
    String[] t1 = timeplayed.split(">", 2); //t1[1] = text after <color=shit>
    String[] t2 = t1[1].split("<", 2); //t2[0] = text before </col>
    timeplayed = t2[0];
    MethodProvider.log("Total Time played: " + timeplayed);
    if(timeplayed.contains("day"))
    {//Time played is at least one day and dont need to wait any longer
        t1 = timeplayed.split(" day", 2);
        daysplayed = Integer.parseInt(t1[0]);
    } else {
        if(timeplayed.contains("hour")) {
            t1 = timeplayed.split(" hour", 2);
            hoursplayed = Integer.parseInt(t1[0]);
        } else {//Time played is less than one hour and need to wait
            if(timeplayed.contains("minute")) {
                t1 = timeplayed.split(" minute", 2);
                minutesplayed = Integer.parseInt(t1[0]);
            } 
        }
    }
    if(daysplayed > 0)
    {
        gameTimeHours = 24;
    }
    if(hoursplayed > 0)
    {
        gameTimeHours = hoursplayed;
    }
    Link to comment
    Share on other sites

    On 11/28/2021 at 4:56 PM, Pandemic said:

    Thanks! Hope you don't mind but I put your code into a code block instead of a quote block, it was showing up really strangely for me (black text with lines all around it haha).

    In fact I appreciate this 🙂

    Link to comment
    Share on other sites

    • 6 months later...
        public static int totalTimePlayed() { 
            int minutesPlayed = 0;
            String[] splitArr = Widgets.getWidgetChild(712, 2, 100).getText().split(">", 2)[1].split("<", 2)[0].split(",");
            HashMap<String, Integer> timeWordsKey = new HashMap<>();
            timeWordsKey.put("day", 24*60);
            timeWordsKey.put("hour", 60);
            timeWordsKey.put("minute", 1);
            for (String time: splitArr) {
                for (String timeWord : timeWordsKey.keySet()) {
                    if (time.contains(timeWord)) {
                        time = time.split(" "+timeWord, 2)[0];
                        if (time.charAt(0) == ' ') {
                            time = time.substring(1);
                        }
                        minutesPlayed += Integer.parseInt(time)*timeWordsKey.get(timeWord);
                    }
                }
            }
    
            return minutesPlayed;
        }

    Hi. I saw this and rewrote it as a method that returns the time played in minutes.

    I have to say my version doesn't really feel very clean due to the weird string manipulation at the top with a ton of splits, the hashMap makes it kind of unclear, and the weird char selection in the double for loop, but it works.

    I will warn you that both my and 420x69x420's version only update the widget text when the time text is viewed or when the account is logged into, so this method doesn't exactly give the most accurate data.

    Edited by TheHero
    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • 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.