Jump to content

Any way to check how many hours on account?


sudoinit6

Recommended Posts

Yeah, I can figure out for a single session. I was hoping for the lifetime of the bot which it sounds like isn't possible. I can go to hans in lumby but I don't know how to capture that data and make decisions based on it. I don't think OSB can do that but I was hoping for a way I don't know about.

Link to comment
Share on other sites

4 hours ago, IDontEB said:

on OSB I don't think so, but the reflection check packet has a counter in there and the number there is equal to ticks so you could just multiply by 0.6.

nerd

 

4 hours ago, sudoinit6 said:

Yeah, I can figure out for a single session. I was hoping for the lifetime of the bot which it sounds like isn't possible. I can go to hans in lumby but I don't know how to capture that data and make decisions based on it. I don't think OSB can do that but I was hoping for a way I don't know about.

Just read the widget in the chatbox :)

Link to comment
Share on other sites

4 hours ago, sudoinit6 said:

Yeah, I can figure out for a single session. I was hoping for the lifetime of the bot which it sounds like isn't possible.

In the onExit() method you can log the time of that session (this would be session botted not actually logged in assuming you have breaks set).  You can have that sent to a discord server you own for your bots and then manually add up the times every day/week/month.  More advanced version of this would be to send the session data to a web server and have it do the additions for you. This post is on the featured section about that. 

Link to comment
Share on other sites

4 hours ago, sudoinit6 said:

Yeah, I can figure out for a single session. I was hoping for the lifetime of the bot which it sounds like isn't possible. I can go to hans in lumby but I don't know how to capture that data and make decisions based on it. I don't think OSB can do that but I was hoping for a way I don't know about.

 

No easy way to do it, you will have to grab the text from hans and parse it.

Example this returns the lifetime of the account in milliseconds.

 

Quote

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.utility.ConditionalSleep;

import java.util.function.BooleanSupplier;

public class AccountLifetimeChecker extends MethodProvider {
    public long getAccountLifetime() {
        NPC hans = getNpcs().closest(npc -> npc.getName().toLowerCase().equalsIgnoreCase("hans") && npc.hasAction("Age"));
        if (hans == null)
            getWalking().webWalk(new Position(3220, 3222, 0));
        else if (!getDialogues().isPendingContinuation() && hans.interact("Age"))
            sleepUntil(() -> getDialogues().isPendingContinuation(), 10000, 100);
        else if (getDialogues().isPendingContinuation() && getWidgets().getWidgetContainingText("you arrived") != null)
            return parseDialogueData(getWidgets().getWidgetContainingText("you arrived").getMessage());
        return -1;
    }

    private long parseDialogueData(String data) {
        final char[] dataChars = data.toCharArray();
        final String[] times = new String[4];
        final StringBuilder timeWord = new StringBuilder();
        long totalTime = 0;
        boolean creatingWord = false;
        int currentTimeWord = 0;

        // Construct the different time strings.
        for (char c : dataChars) {
            if (isCharNumber(c)) {
                creatingWord = true;
                timeWord.append(c);
            } else if (creatingWord) {
                creatingWord = false;
                times[currentTimeWord] = timeWord.toString();
                currentTimeWord++;
                timeWord.delete(0, timeWord.length());
            }
        }

        if (times[3] != null) {
            totalTime += getMillisFromDays(Integer.parseInt(times[0])); // Parse days
            totalTime += getMillisFromHours(Integer.parseInt(times[1])); // Parse hours
            totalTime += getMillisFromMinutes(Integer.parseInt(times[2])); // Parse minutes
        } else {
            totalTime += getMillisFromHours(Integer.parseInt(times[0])); // Parse hours
            totalTime += getMillisFromMinutes(Integer.parseInt(times[1])); // Parse minutes
        }

        return totalTime;
    }

    private boolean isCharNumber(char c) {
        try {
            Integer.parseInt(c + "");
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    private long getMillisFromDays(int days) {
        return days * 24 * 60 * 60 * 1000;
    }

    private long getMillisFromHours(int hours) {
        return hours * 60 * 60 * 1000;
    }

    private long getMillisFromMinutes(int minutes) {
        return minutes * 60 * 1000;
    }

    private boolean sleepUntil(BooleanSupplier condition, int maxTime, int checkInterval) {
        new ConditionalSleep(maxTime, checkInterval) {
            @Override
            public boolean condition() throws InterruptedException {
                return condition.getAsBoolean();
            }
        }.sleep();
        return condition.getAsBoolean();
    }
}

Use getAccountLifetime method to retrieve the time. You will need to check if it doesn't return -1 before using the result as it is set up in a way to only execute one action each time it is called.

So if the dialogue is not visible it will talk to or walk to hans than you will have to call it again for it to either talk to hans, or retrieve the lifetime.

Example usage.

Quote

@Override
public int onLoop() throws InterruptedException {

    long lifeTime = getAccountLifetime();

    if (lifeTime != -1) {
        log(lifeTime);
    }

    return random(800, 3000);
}

 

Link to comment
Share on other sites

5 hours ago, BravoTaco said:

 

No easy way to do it, you will have to grab the text from hans and parse it.

Example this returns the lifetime of the account in milliseconds.

 

Use getAccountLifetime method to retrieve the time. You will need to check if it doesn't return -1 before using the result as it is set up in a way to only execute one action each time it is called.

So if the dialogue is not visible it will talk to or walk to hans than you will have to call it again for it to either talk to hans, or retrieve the lifetime.

Example usage.

 

Wow, thanks for this. Very helpful!

Link to comment
Share on other sites

  • 3 years later...
  • 2 weeks later...
On 6/22/2023 at 2:40 PM, TeamSSL said:

I just used the widget from the osbot but weird no1 posted that before 😉

I assume you're reading the widget in the account tab? 

this is a way to do it .

        RS2Widget playtime = getWidgets().get(712, 2, 100);
        RS2Widget yes = getWidgets().get(219, 1, 1);
        if (playtime == null) {
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() {
                    return playtime.isVisible();
                }
            }.sleep();
        } else {
            playtime.interact("Reveal");
        }
        if (dialogues.inDialogue()){
            yes.interact("Continue");
        }

 

Edited by BananaTown459
added cdoe
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...