Jump to content

Problem with making Quest script


slazter

Recommended Posts

Hello guys, so im fairly new to scripting but think im starting to get a hang of it, So anyways i fucking hate questing so i figured i'd make a script for questing so i don't have to do them manually, aswell as have some fun doing them. Anyways when coding the Witch's potion i ran into some trouble, Here's the problem:

I want my character to talk to Hetty to start the quest - Because you can't get the Rat's tail before the quest is started. So i figured i'd go to the api and use the, Quests.isStarted. But it didn't work, whenever i tryed to call if(getQuests.isStarted(WITCHS_POTION) so i went to the api, and the description says exactly thesame for both IsComplete, and IsStarted.

isComplete
public boolean isComplete(Quests.Quest quest)
Returns:
False if the quest was not complete or there was an issue caching.
isStarted
public boolean isStarted(Quests.Quest quest)
Returns:
False if the quest was not complete or there was an issue caching.

Therefore i don't really know how to check if the quest is marked yellow so i can go for the rat's tail. So any ideas on how to fix this? 

My code: 

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import static org.osbot.rs07.api.Quests.Quest.WITCHS_POTION;

@ScriptManifest(author = "Slazter", name = "An Example Script", info = "Teamplate", version = 0.1, logo = "")

public final class OsBotFråga extends Script  {

    @Override
    public final int onLoop() throws InterruptedException {

        if(canWitch()){
            questWitchPotion();
        }

        return 150;
    }

    public boolean canWitch(){
        if (!quests.isComplete(WITCHS_POTION)) {
            return true;
        } else return false;
    }
    public void questWitchPotion() throws InterruptedException {
        NPC witch = getNpcs().closest("Hetty");
        Platser plat = new Platser();
        NPC rat = getNpcs().closest("Rat");
        RS2Object range = getObjects().closest("Range");
        RS2Object cauldron = getObjects().closest(2024);
        String[] startitems = {"Onion","Eye of newt"};
        String[] allQItems = {"Onion","Eye of newt","Burnt meat","Rat's tail"};
        GroundItem tail = getGroundItems().closest("Rat's tail");
        Filter<Item> meat = new Filter<Item>() {
            @Override
            public boolean match(Item item) {
                return item.getName().contains("meat");
            }
        };

        if(!inventory.contains(startitems)){
            if(cauldron!=null && plat.witchs_potion.contains(myPosition())){
                if(!dialogues.inDialogue()){
                    cauldron.interact("Drink From");
                    sleep(random(1200,1800));
                } else if(dialogues.inDialogue()){
                    dialogueHandling();
                }
            }
            else if (!getBank().isOpen()) {
                getWalking().webWalk(Banks.DRAYNOR);
                getBank().open();
            } else {
                getBank().depositAll();
                getBank().withdraw("Onion",1);
                getBank().withdraw("Eye of newt", 1);
                getBank().withdraw(meat,1);
            }
        }
        //Start quest
        else if(inventory.contains(startitems)){
            //start quest
            if(!getQuests().isStarted(WITCHS_POTION) && !witch.isVisible()){ // Won't work
                getWalking().webWalk(plat.witchs_potion);
            } else if(witch!=null && !dialogues.inDialogue()){
                witch.interact("Talk-to");
                sleep(random(1200,1800));
            } else if(dialogues.inDialogue()){
                dialogueHandling();
            }
            
            //get Rat's tail
            else if(!inventory.contains("Rat's tail")){
                getWalking().webWalk(new Position(2957,3204,0));
                rat.interact("Attack");
                Sleep.sleepUntil(()-> rat.getHealthPercent()==0 || tail!=null,5000);
                if(tail!=null){
                    tail.interact("Take");
                    Sleep.sleepUntil(()-> !tail.isVisible(),5000);
                }
                // Cook the meat
            } else if(!inventory.contains("Burnt meat")){
                getWalking().webWalk(new Position(2969,3210,0));
                getInventory().getItem(meat).interact("Use");
                sleep(random(1250,1900));
                range.interact("Use");
                Sleep.sleepUntil(()-> !myPlayer().isAnimating(),5000);
                
                //walk back to witch
            } else if(getInventory().contains(allQItems) && !witch.isVisible()){
                getWalking().webWalk(plat.witchs_potion);
                
                //talk to witch
            } else if(witch!=null && getMap().canReach(witch) && !getDialogues().inDialogue()){
                witch.interact("Talk-to");
                Sleep.sleepUntil(()-> getDialogues().inDialogue(),5000);
            } else if(getDialogues().inDialogue()){
                dialogueHandling();
            }
        }
    }

    public void dialogueHandling() throws InterruptedException {
        String[] options = {""};
        if(dialogues.isPendingContinuation()){
            dialogues.clickContinue();
        } else if(dialogues.isPendingOption()){
            dialogues.completeDialogue(options);
        }
    }
}

Also if anyone have any feedback for me on how to improve my coding, i'd be super happy for any input :)

Edited by slazter
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...