Razzel Posted August 10, 2020 Posted August 10, 2020 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)); }
Explv Posted August 10, 2020 Posted August 10, 2020 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. 2
botelias Posted September 9, 2020 Posted September 9, 2020 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 } 1
dubanon Posted December 6, 2020 Posted December 6, 2020 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