Jump to content

Need help with script


Abysm

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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);
        }
    }
}

 

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