Jump to content

Script wont start


Nym

Recommended Posts

Hey can anyone help me here I made a simple script and when I start to the script it doesnt start.

package core;


import org.osbot.rs07.api.Objects;
import org.osbot.rs07.api.map.Area;
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 org.osbot.rs07.utility.ConditionalSleep;

import static core.PestControl.State.*;

@ScriptManifest(version = 0, info = "Pest Control :D", logo = "", author = "Nimmogel", name = "Pest Control")
public class PestControl extends Script {

    final State state = getState();

    Area onBoatArea = new Area(2637, 2647, 2641, 2641);
    Area pcArea = new Area(2623, 2622, 2689, 2561);
    Area killArea = new Area(2627, 2596, 2640, 2587);
    Area outsideBoat = new Area(2644, 2646, 2644, 2642);

    String[] pestControlMonsters = {"Brawler","Defiler","Ravager","Shifter","Spinner","Torcher"};

    public void onStart() throws InterruptedException {
        log("Pest Control has started :D");
    }

    public enum State {
        ATTACK,
        ONBOAT,
        BOAT,
        WALKTOSPOT
    }

    private State getState() {

        if (!pcArea.contains(myPlayer()) && !onBoatArea.contains(myPlayer())) {
            return BOAT;
        }
        if (onBoatArea.contains(myPlayer())) {
            return ONBOAT;
        }
        if (pcArea.contains(myPlayer()) && !killArea.contains(myPlayer())) {
            return WALKTOSPOT;
        }
        if (killArea.contains(myPlayer())) {
            return ATTACK;
        }
        return null;
    }


    @Override
    public int onLoop() throws InterruptedException {

        switch (getState()) {

            case ATTACK:
                NPC monster = npcs.closest(pestControlMonsters);
                log("atack monsters");

                if (monster != null) {
                    if (monster.isVisible()) {
                        if (monster.interact("Attack")) {
                            new ConditionalSleep(5000) {
                                @Override
                                public boolean condition() throws InterruptedException {
                                    return !myPlayer().isAnimating();
                                }
                            }.sleep();
                        }
                    }
                }
                break;

            case ONBOAT:

                log("onBoat");

                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return pcArea.contains(myPlayer());
                    }
                }.sleep();

                break;

            case BOAT:
                RS2Object plank = new Objects().closest("Gangplank");

                log("boat case");

                if (plank != null) {
                    if (plank.isVisible()) {
                        if (plank.interact("Cross")) {
                            new ConditionalSleep(5000) {
                                @Override
                                public boolean condition() throws InterruptedException {
                                    return onBoatArea.contains(myPlayer());
                                }
                            }.sleep();
                        }
                    }
                } else {
                    getWalking().walk(outsideBoat);
                    sleep(random(650,900));
                }

                break;

            case WALKTOSPOT:
                log("walking to kill area");
                getWalking().webWalk(killArea);
                sleep(random(650,900));

                break;

        }
        return 120;
    }
    @Override
    public void onExit() {
        log("Thanks for running my Pest Control");
    }
}

 

Link to comment
Share on other sites

5 minutes ago, Stimpack said:


    final State state = getState();

 

try putting that  (getState() part) in onStart

also dont make it final

oh no, that part is not used, i just forgot to delete it

edit - took out now scripts starts but my script doesnt do anything and uses a shit ton of cpu and mem

Edited by Nimmogel
Link to comment
Share on other sites

You should use what I do.

private enum BotState {
 BANKING, LOOTING
}

private BotState getState()
{
 return getInventory.isFull ? BotState.BANKING : BotState.LOOTING;
}

then just call the getState() in the switch. Read some of my script releases for demo on this. Becomes a little cleaner and easy to read for everyone.

Edited by Booleans YAY
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...