Jump to content

First quest script, all/any feedback welcome!


Vogelbekdier

Recommended Posts

Made a couple of quests script and they all work decently but are not as efficient as I would like them to be.

My waterfall Quest script is over 1k lines of code there is definitely room for improvement there....

Below my restless ghost script as it is fairly short. (Won't be troubling anyone with 1k+ lines of spaghetti code).

Currently, feel like my main method of sequencing the script by using Area's only to determine where my player is and what actions to complete next is not efficient.

Also, feel like I am losing a lot of lines due to a large number of conditional sleeps, tried using Explv's sleep method but it returns me with loads of errors sadly.

Any/All feedback welcome as the sole aim of this post is to try and improve!

 

Spoiler

public class RestlessGhost extends Script {

    private Area FATHERAERECK = new Area(3240, 3211, 3247, 3204);
    private Area LUMBRIDGE = new Area(3219, 3214, 3229, 3223);
    private Area FATHERURHNEY = new Area(3144, 3173, 3151, 3177);
    private Area RESTLESSGHOST = new Area(3252, 3195, 3248, 3190);
    private Area WIZARDTOWER = new Area(3118, 9565, 3121, 9568);
    private Area GE = new Area(3161, 3472, 3167, 3481);



    @Override
    public int onLoop() throws InterruptedException {

        stamina();

        switch (configs.get(107)) {
            case 0: // Start the quest by talking to Father Aereck
                startQuest();
                break;
            case 1:  // Speak to Father Urhney
                if (!FATHERURHNEY.contains(myPlayer())) {
                    walkToFatherUrhney();
                } else {
                    talkToFatherUrhney();
                }
                break;
            case 2: // Speak to the Restless ghost
                Entity restlessGhost = npcs.closest("Restless ghost");
                if (!LUMBRIDGE.contains(myPlayer()) && !RESTLESSGHOST.contains(myPlayer())) {
                    if (inventory.interact("Break", "Lumbridge teleport")) {
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return LUMBRIDGE.contains(myPlayer());
                            }
                        }.sleep();
                    }
                } else if (LUMBRIDGE.contains(myPlayer()) && !RESTLESSGHOST.contains(myPlayer())) {
                    log("Test");
                    walkToRestlessGhost();
                } else if (RESTLESSGHOST.contains(myPlayer()) && inventory.contains("Ghostspeak amulet")) {
                    wearAmulet();
                } else if (RESTLESSGHOST.contains(myPlayer()) && !inventory.contains("Ghostspeak amulet") && restlessGhost == null) {
                    RS2Object coffin = getObjects().closest("Coffin");
                    if (coffin != null) {
                        if (coffin.interact("Open")) {
                            new ConditionalSleep(5000) {
                                @Override
                                public boolean condition() throws InterruptedException {
                                    return restlessGhost != null;
                                }
                            }.sleep();
                        }
                    }
                } else if (restlessGhost != null && !getDialogues().inDialogue()) {
                    talkToRestlessGhost();
                }
            break;
            case 3: // Retrieve skull from Wizards Tower
                if(!WIZARDTOWER.contains(myPlayer())) {
                    walkToWizardsTower();
                } else if (WIZARDTOWER.contains(myPlayer())) {
                    searchAltar();
                    }
            break;
            case 4: // Bring skull back to the Restless Ghost.
                if (inventory.contains("Ghost's skull") && !LUMBRIDGE.contains(myPlayer()) && !RESTLESSGHOST.contains(myPlayer())) {
                    if(inventory.interact("Break", "Lumbridge teleport")) {
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return LUMBRIDGE.contains(myPlayer());
                            }
                        }.sleep();
                    }
                } else if (LUMBRIDGE.contains(myPlayer()) && !RESTLESSGHOST.contains(myPlayer())) {
                    walkToRestlessGhost();
                } else if (RESTLESSGHOST.contains(myPlayer())) {
                    finishQuest();
            }
                break;
            case 5: // Quest completed
                if (!GE.contains(myPlayer())) {
                    teleportToGE();
                } else {
                    log("Pausing script.");
                }
                break;
        }

        return random(250, 450);
    }

    private void startQuest() throws InterruptedException{
        if (!LUMBRIDGE.contains(myPlayer()) && !FATHERAERECK.contains(myPlayer())) {
            if(inventory.interact("Break", "Lumbridge teleport")) {
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return LUMBRIDGE.contains(myPlayer());
                    }
                }.sleep();
            }
        }
        if (!FATHERAERECK.contains(myPlayer()) && LUMBRIDGE.contains(myPlayer())) {
            getWalking().webWalk(FATHERAERECK);
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return FATHERAERECK.contains(myPlayer());
                }
            }.sleep();
        } else {
            talkToFatherAereck();
        }
    }

    private void talkToFatherAereck() throws InterruptedException {
        Entity fatherAereck = npcs.closest("Father Aereck");
        if (fatherAereck != null) {
            if (!getDialogues().inDialogue()) {
                log("Not talking to Father Aereck. Starting conversation.");
                fatherAereck.interact("Talk-to");
                log("Sleeping until conversation starts!");
                new ConditionalSleep(5000) {
                    @Override
                        public boolean condition() throws InterruptedException {
                        return getDialogues().inDialogue();
                    }
                }.sleep();
            }
            String[] options = new String[]{"Click here to continue",
                    "I'm looking for a quest!",
                    "Ok, let me help then."
            };
            if (getDialogues().completeDialogue(options)) {
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return !getDialogues().inDialogue();
                    }
                }.sleep();
                log("Dialogue complete successfully!");

            }
            log("Just spoke with Father Aereck!");
        }
    }


    private void walkToFatherUrhney() {
        getWalking().webWalk(FATHERURHNEY);
        new ConditionalSleep(5000) {
            @Override
            public boolean condition() throws InterruptedException {
                return FATHERURHNEY.contains(myPlayer());
            }
        }.sleep();
    }

    private void talkToFatherUrhney() throws InterruptedException {
        Entity fatherUrhney = npcs.closest("Father Urhney");
        if (fatherUrhney != null) {
            if (!getDialogues().inDialogue()) {
                log("Not talking to Father Urhney. Starting conversation.");
                fatherUrhney.interact("Talk-to");
                log("Sleeping until conversation starts!");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getDialogues().inDialogue();
                    }
                }.sleep();
            }
            String[] options = new String[]{"Click here to continue",
                    "Father Aereck sent me to talk to you.",
                    "He's got a ghost haunting his graveyard."
            };
            if (getDialogues().completeDialogue(options)) {
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return !getDialogues().inDialogue();
                    }
                }.sleep();
                log("Dialogue complete successfully!");

            }
            log("Just spoke with Father Urhney!");
        }
    }

    private void talkToRestlessGhost() throws InterruptedException {
        Entity restlessGhost = npcs.closest("Restless ghost");
        if (restlessGhost != null) {
            if (!getDialogues().inDialogue()) {
                log("Not talking to Restless ghost. Starting conversation.");
                restlessGhost.interact("Talk-to");
                log("Sleeping until conversation starts!");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getDialogues().inDialogue();
                    }
                }.sleep();
            }
            String[] options = new String[]{"Click here to continue",
                    "Yep, now tell me what the problem is."
            };
            if (getDialogues().completeDialogue(options)) {
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return !getDialogues().inDialogue();
                    }
                }.sleep();
                log("Dialogue complete successfully!");

            }
            log("Just spoke with the Restless ghost!");
        }
    }

    private void walkToRestlessGhost() {
        getWalking().webWalk(RESTLESSGHOST);
        new ConditionalSleep(5000) {
            @Override
            public boolean condition() throws InterruptedException {
                return RESTLESSGHOST.contains(myPlayer());
            }
        }.sleep();
    }

    private void wearAmulet() {
        if (inventory.contains("Ghostspeak amulet")) {
            if(inventory.interact("Wear", "Ghostspeak amulet")) {
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return !inventory.contains("Ghostspeak amulet");
                    }
                }.sleep();
            }
        }
    }

    private void walkToWizardsTower() {
        getWalking().webWalk(WIZARDTOWER);
        new ConditionalSleep(5000) {
            @Override
            public boolean condition() throws InterruptedException {
                return WIZARDTOWER.contains(myPlayer());
            }
        }.sleep();
    }

    private void searchAltar() {
        RS2Object altar = getObjects().closest("Altar");
        if (altar != null) {
            if (altar.interact("Search")) {
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return inventory.contains("Ghost's skull");
                    }
                }.sleep();
            }
        }
    }

    private void finishQuest() {
        RS2Object coffinOpen = getObjects().closest(15061);

        if(coffinOpen == null) {
            RS2Object coffin = getObjects().closest("Coffin");
            if (coffin != null) {
                if (coffin.interact("Open")) {
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return coffinOpen != null;
                        }
                    }.sleep();
                }
            }
        } else if (coffinOpen != null && !getDialogues().inDialogue()) {
            RS2Object coffin = getObjects().closest("Coffin");
            if(inventory.interact("Use", "Ghost's skull")) {
                if(coffin != null) {
                    if(coffin.interact("Use")) {
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return !inventory.contains("Ghost's skull");
                            }
                        }.sleep();
                    }
                }
            }
        }
    }

    private void teleportToGE() {
        if (!GE.contains(myPlayer())) {
            if (getEquipment().interact(EquipmentSlot.RING, "Grand Exchange")) {
                log("Teleporting to Grand Exchange.");
                new ConditionalSleep(7000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return GE.contains(myPlayer());
                    }
                }.sleep();
            }
        }
    }
    public boolean isStaminaPotionActive() {
        return getConfigs().get(1575) > 0;
    }

    public void stamina() throws InterruptedException {
        if (!isStaminaPotionActive()) {
            Item stamina = getInventory().getItem(item -> Arrays.asList(item.getActions()).contains("Drink"));
            if (stamina != null) {
                if (stamina.interact("Drink")) {
                    log("Drinking stamina.");
                    new ConditionalSleep(3600) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return isStaminaPotionActive();
                        }
                    }.sleep();
                }
            }
        }
    }
}

 

Edited by Vogelbekdier
Link to comment
Share on other sites

You would lose a huge number of lines & your code would be a lot more readable if you can get Explv's sleep method to work, so might want to look into that first.

Did you copy his class & put into a java file called Sleep.java? Make sure that the class/constructor name is the same as whatever your file is called.
Then import said file to your script & use it as shown in his post.

If it still doesn't work, post here what errors it gives you so I know what the actual problem is :)

Neanel

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