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.

How can I get an action performed once then never again?

Featured Replies

Hi everyone, I'm very new to scripting and have been messing around by splicing together open source code. 

I want to enter a friend's house but once it has done this once, I want to enter using the House Advertisement object, ID:29091 and 'Visit-Last', or go back to entering the host name manually if this message appears "You haven't visited anyone this session." Anyone got any tips?

 

public void enter_house() {
    RS2Object portal = (RS2Object)this.getObjects().closest(this.OUTSIDE_HOUSE, new String[]{"Portal"});
    if (this.OUTSIDE_HOUSE.contains(this.myPlayer().getPosition();
        portal.interact(new String[]{"Friend's house"});
        (new ConditionalSleep(random(2000, 7500)) {
            public boolean condition() {
                return main.this.getDialogues().inDialogue();
            }
        }).sleep();
        if (this.getDialogues().inDialogue()) {
            this.getKeyboard().typeString(this.host_name, true);
                           sleep((long)random(2050, 1850));
                }

You can just set a boolean flag when you enter the house.

For example:

public class YourScript extends Script {
    private boolean hasEnteredHouse;

    @Override
    public int onLoop() throws InterruptedException {
        if (!inHouse()) {
            // If we're not in the house, enter it
            enterHouse();
        } else {
            // We are inside the house, so we can set hasEnteredHosue to true
            // so that next time we enter the house, we can use the last visit functionality
            hasEnteredHouse = true;
        }
        return 600;
    }

    public boolean enterHouse() {
        if (hasEnteredHouse) {
            // We have entered the house before, use the last visit functionality
        } else {
            // We have not entered the house before, use the search
        }
    }
}

 

Or alternatively, set a different flag when you see the "You haven't visited anyone this session." message.

For example:

public class YourScript extends Script {
    private boolean visitedPlayerHouse = true;

    @Override
    public int onLoop() throws InterruptedException {
        if (!inHouse()) {
            // If we're not in the house, enter it
            enterHouse();
        } else {
            // We have entered the house, so we set visitedPlayerHouse to true
            // so that next time we go to enter a house, we know that we can use the
            // last visit functionality
            visitedPlayerHouse = true; 
        }
        return 600;
    }

    public boolean enterHouse() {
        if (visitedPlayerHouse) {
            // We have entered the house before, use the last visit functionality
        } else {
            // We have not entered the house before, use the search
        }
    }
  
    @Override
    public void onMessage(Message message) {
        if (message.getType() != MessageType.GAME) {
            return; 
        }

      	// When we see this GAME message
        if (message.getMessage().contains("You haven't visited anyone this session.")) {
            // We set visitedPlayerHouse to false
            // So that we know to use the search functionality to enter the house next time
            visitedPlayerHouse = false; 
        }
    }
}

 

Note I have not tested any of the above code, but it should give you an idea how to do it.

  • 5 weeks later...

I'd just do a simple;

int visited = 0;
(somewhere that doesn't loop)

Then for the action:

if(visited == 0){
	//visit once
	visited = 1;
}else{
	//after first time, visit this way
}

 

  • 2 months later...
On 9/9/2020 at 10:21 PM, botelias said:

I'd just do a simple;

int visited = 0;
(somewhere that doesn't loop)

Then for the action:


if(visited == 0){
	//visit once
	visited = 1;
}else{
	//after first time, visit this way
}

 

This does look a lot simpler

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.