Jump to content
Sign in to follow this  
sudoinit6

Any way to check how many hours on account?

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.

Share this post


Link to post
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 :)

Share this post


Link to post
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. 

Share this post


Link to post
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);
}

 

Share this post


Link to post
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!

Share this post


Link to post
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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...