Jump to content

Script only banks


nickeb0i

Recommended Posts

Hello I'm new around here and I'm trying to learn how to script.

I want to give something to the community but I have to learn to code first ;)

My problems:

  • I have to have a small fishing net in my inventory or it wont open bank and get one
  • If I have a small fishing net it opens bank then closes then opens and continues like that
	private enum State {
		FISH, BANK, WAIT
	};

	private State getState() {
		Entity stall = objects.closest("Fishing spot");
		if (inventory.isEmpty() && !inventory.contains("Small fishing net"))
			return State.BANK;
		if (stall != null && inventory.contains("Small fishing net"))
			return State.FISH;
		return State.WAIT;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case FISH:
			Entity spot = objects.closest("Fishing spot");
			if (spot != null) {
				inventory.interact("Use", "Small Fishing Net");
				if (inventory.isItemSelected() == true)
				spot.interact();
			}
			break;
		case BANK:
			Entity bank = objects.closest("Bank booth");
			if (!inventory.contains("Small fishing net"))
				getBank().withdraw("Small fishing net", 1);
			if (bank != null) {
				bank.interact("Bank");
				sleep(random(500, 700));
				getBank().depositAllExcept("Small fishing net");
			}
			break;
		case WAIT:
			sleep(random(500, 700));
			break;
		}
		return random(200, 300);
	}
Edited by nickeb0i
Link to comment
Share on other sites

It doesn't even get to the point where it should go to the fishing spot and fish? :/

 

Alright here in pseudo-code:

NPC spot = get NPC's nearby with a filter which have the name "Fishing spot" and have an action called "Net"
 
if (spot is not null)
 
if (spot is visible on our screen)
 
interact with the spot with action "Net"
 
else // so the spot isnt visible
walk to the spot

This isn't really pseudo-code, but it serves the purpose.

Edited by KEVzilla
  • Like 1
Link to comment
Share on other sites

 

Hello I'm new around here and I'm trying to learn how to script.

I want to give something to the community but I have to learn to code first wink.png

My problems:

  • I have to have a small fishing net in my inventory or it wont open bank and get one
  • If I have a small fishing net it opens bank then closes then opens and continues like that
	private enum State {
		FISH, BANK, WAIT
	}

	private State getState() {
		Entity stall = objects.closest("Fishing spot");
		if (inventory.isEmpty() && !inventory.contains("Small fishing net"))
			return State.BANK;
		if (stall != null && inventory.contains("Small fishing net"))
			return State.FISH;
		return State.WAIT;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case FISH:
			Entity spot = objects.closest("Fishing spot");
			if (spot != null) {
				inventory.interact("Use", "Small Fishing Net");
				if (inventory.isItemSelected() == true)
				spot.interact();
			}
			break;
		case BANK:
			Entity bank = objects.closest("Bank booth");
			if (!inventory.contains("Small fishing net"))
				getBank().withdraw("Small fishing net", 1);
			if (bank != null) {
				bank.interact("Bank");
				sleep(random(500, 700));
				getBank().depositAllExcept("Small fishing net");
			}
			break;
		case WAIT:
			sleep(random(500, 700));
			break;
		}
		return random(200, 300);
	}

 

Fishing spot is an NPC.

 

Also use the built in bank method:

if(!getBank().isOpen()){

    getBank().open();
    new ConditionalSleep(5000) {
        @Override
        public boolean condition() throws InterruptedException {
            return getBank().isOpen();
        }
    }.sleep();
} else if (!inventory.contains("Small fishing net")){
    getBank().withdraw("Small fishing net", 1);
} else {
    getBank().depositAllExcept("Small fishing net");
}
 

Also in your getState() method, State.BANK will not return if you have a full inventory.

You only bank when your inventory is empty.

if (inventory.isEmpty() && !inventory.contains("Small fishing net")){
    return State.BANK;
}

It should be:

if (inventory.isFull() || !inventory.contains("Small fishing net")){
    return State.BANK;
}

As a result of this, your WAIT state is redundant:

private enum State {
    FISH, BANK
}

private State getState() {

    if (inventory.isFull() || !inventory.contains("Small fishing net")){
	return State.BANK;
    }
    return State.FISH;
}
		
@Override
public int onLoop() throws InterruptedException {
    switch (getState()) {
	case FISH:
	    NPC spot = getNpcs().closest("Fishing spot");
	    if (spot != null) {
		spot.interact("Net");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return myPlayer().isAnimating();
                    }
                }.sleep();
            }
	    break;
	case BANK:
            if(!getBank().isOpen()){

                getBank().open();
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getBank().isOpen();
                    }
                }.sleep();
            } else if (!inventory.contains("Small fishing net")){
                getBank().withdraw("Small fishing net", 1);
            } else {
                getBank().depositAllExcept("Small fishing net");
            }
	    break;
    }		
    return random(200, 300);
}

To prevent spam clicking you may then want to wrap your onLoop code with a condition, where the script does nothing if the player is animating or moving:

private enum State {
    FISH, BANK
}

private State getState() {

    if (inventory.isFull() || !inventory.contains("Small fishing net")){
	return State.BANK;
    }
    return State.FISH;
}
		
@Override
public int onLoop() throws InterruptedException {

    if(!myPlayer().isAnimating() && !myPlayer().isMoving()){

        switch (getState()) {

	    case FISH:
	        NPC spot = getNpcs().closest("Fishing spot");
	        if (spot != null) {
		    spot.interact("Net");
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return myPlayer().isAnimating();
                        }
                    }.sleep();
                }
	        break;
	    case BANK:
                if(!getBank().isOpen()){

                    getBank().open();
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return getBank().isOpen();
                        }
                    }.sleep();
                } else if (!inventory.contains("Small fishing net")){
                    getBank().withdraw("Small fishing net", 1);
                } else {
                    getBank().depositAllExcept("Small fishing net");
                }
	        break;
        }		
    }
    return random(200, 300);
}

You will also need to handle the case where the bank does not contain a fishing net.

 

You may also want to include paths to and from the bank and fishing spot:

Area fishingArea = new Area(0, 0, 0, 0); // Define this
Area bankArea = new Area(0, 0, 0, 0); // Define this
Position[] pathToBank = new Position[]{ }; // Define this
Position[] pathToSpot = new Position[]{ }; // Define this

private enum State {
    FISH, BANK, WALK_TO_BANK, WALK_TO_SPOT
}

private State getState() {

    if (inventory.isFull() || !inventory.contains("Small fishing net")){

        if(bankArea.contains(myPosition())) return State.BANK;
        return State.WALK_TO_BANK;
    }

    if(!fishingArea.contains(myPosition())) return State.WALK_TO_SPOT;

    return State.FISH;
}
		
@Override
public int onLoop() throws InterruptedException {

    if(!myPlayer().isAnimating() && !myPlayer().isMoving()){

        switch (getState()) {

	    case FISH:
	        NPC spot = getNpcs().closest("Fishing spot");
	        if (spot != null) {
		    spot.interact("Net");
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return myPlayer().isAnimating();
                        }
                    }.sleep();
                }
	        break;
	    case BANK:
                if(!getBank().isOpen()){

                    getBank().open();
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return getBank().isOpen();
                        }
                    }.sleep();
                } else if (!inventory.contains("Small fishing net")){

                    if(getBank().contains("Small fishing net")) getBank().withdraw("Small fishing net", 1);
                    else stop(true);
                } else {
                    getBank().depositAllExcept("Small fishing net");
                }
	        break;

            case WALK_TO_BANK:
                getLocalWalker().walkPath(pathToBank);
                break;
            case WALK_TO_SPOT:
                getLocalWalker().walkPath(pathToSpot);
                break;
        }		
    }
    return random(200, 300);
}

doge.png

Edited by Explv
  • Like 4
Link to comment
Share on other sites

See my updated post, there are more errors tongue.png

 

Thank you, how do I fix this

        case FISH:
            Entity spot = objects.closest("Fishing spot");
            if (spot != null) {
                inventory.interact("Use", "Small Fishing Net");
                if (inventory.isItemSelected() == true)
                spot.interact();
            }

so it recognizes fishing spot as a NPC?

Link to comment
Share on other sites

Thank you, how do I fix this

        case FISH:
            Entity spot = objects.closest("Fishing spot");
            if (spot != null) {
                inventory.interact("Use", "Small Fishing Net");
                if (inventory.isItemSelected() == true)
                spot.interact();
            }

so it recognizes fishing spot as a NPC?

 

See updated post.

 

  • Like 1
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...