Jump to content

Need help with script


Recommended Posts

Posted (edited)

I need help with a script I'm trying to make. I'm having trouble collecting things from trees. The script collects for example apples from trees but after it has collected whole tree it just does nothing and doesnt continue collectig from other trees. Can anyone help me? :feels:

 

EDIT: HOLY SHIT I'M BLIND AND STUPID! TREE ID CHANGES :???:

Edited by Abysm
Posted (edited)
Spoiler

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "BananaPicker", author = "Abysm", info = "Picks bananas in karamja", version = 0.1, logo = "")
public final class BananaPicker extends Script {

    private final Area BananaArea = new Area(2914, 3161, 2926, 3154);
    private final Area DepositArea = new Area(3045, 3235, 3050, 3237);

    @Override

    public final int onLoop() throws InterruptedException {
        if (canPickBananas()) {
            Pick();
        } else {
            deposit();
        }
        return random(150, 200);
    }

    private void Pick() {
        RS2Object Bananatree1 = getObjects().closest("Banana tree");
        if (!BananaArea.contains(myPosition())) {
            getWalking().webWalk(BananaArea);
        } else if (!getInventory().isFull()) {
            Bananatree1.interact("Pick");
        }
    }

    private boolean canPickBananas() {
        return !getInventory().isFull();
    }

    private void deposit() throws InterruptedException {
        if (!DepositArea.contains(myPosition())) {
            getWalking().webWalk(DepositArea);
        } else if (!getDepositBox().isOpen()) {
            getDepositBox().open();
        } else if (!getInventory().isEmptyExcept("Coins")) {
            getDepositBox().depositAllExcept("Coins");
        } else {
            stop(true);
        }
    }
}

 

So here is basically the whole code, it goes to the deposit box in port sarim if inventory is full and deposits all the bananas, walks back to banana trees, picks one tree out of bananas then it just freezes. Could somebody help a noob? 

Edited by Abysm
Posted (edited)
3 minutes ago, d0zza said:

Because even when the banana tree runs out of bananas it's still called "Banana tree" in game, you need to check if the closest banana tree still has bananas to pick

Thats the problem, I dont know how :D I've been trying to use all sorts of filters but I cant get it to work

Edited by Abysm
Posted (edited)
3 hours ago, Abysm said:

Thats the problem, I dont know how :D I've been trying to use all sorts of filters but I cant get it to work

Bro, use IDs. The ID changes when it has bananas and when it doesn't.

The ID for the tree with bananas is 2073.

The ID for the tree without bananas is 2078.

So

int fullTree = 2073;
int emptyTree = 2078;

if (fullTree) {
  if (fullTree.interact("Pick")) {
    conditionalSleep -> emptyTree, 5000);
  }
}

You might want to play around with the conditional sleep to fit you.

Edited by Visty
Posted

So to edit your code, it should be something like this

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "BananaPicker", author = "Abysm", info = "Picks bananas in karamja", version = 0.1, logo = "")
public final class BananaPicker extends Script {

    private final Area BananaArea = new Area(2914, 3161, 2926, 3154);
    private final Area DepositArea = new Area(3045, 3235, 3050, 3237);

    @Override

    public final int onLoop() throws InterruptedException {
        if (canPickBananas()) {
            Pick();
        } else {
            deposit();
        }
        return random(150, 200);
    }

    private void Pick() {
        RS2Object fullTree = getObjects().closest(2073);

        if (!BananaArea.contains(myPosition())) {
            getWalking().webWalk(BananaArea);
        } else if (!getInventory().isFull()) {
            if (fullTree.interact("Pick") {
				//Conditionalsleep
        }
    }

    private boolean canPickBananas() {
        return !getInventory().isFull();
    }

    private void deposit() throws InterruptedException {
        if (!DepositArea.contains(myPosition())) {
            getWalking().webWalk(DepositArea);
        } else if (!getDepositBox().isOpen()) {
            getDepositBox().open();
        } else if (!getInventory().isEmptyExcept("Coins")) {
            getDepositBox().depositAllExcept("Coins");
        } else {
            stop(true);
        }
    }
}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...