Jump to content

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


Razzel

Recommended Posts

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));
                }
Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

  • 5 weeks later...
  • 2 months later...

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