Jump to content

[Script Help Please] Simple Leather Tanner


Lol_marcus

Recommended Posts

First and foremost I'm new to JAVA coding having only coded with color bots before. What I've done here is taken 2 scripts and combined them to do more or less what I'd like, but now I'm stuck in a few things. I've tested both features for tanning and banking, and they both work like I want them to. Now I would like to combine them. Here's the full script:

package core;

import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import java.awt.*;

@ScriptManifest(name = "Tan", version = 1, author = "Marcus", logo = "", info = "")

public class Main extends Script {

    @Override
    public void onStart() throws InterruptedException {
        getExperienceTracker().start(Skill.MAGIC);
    }

    @Override
    public int onLoop() throws InterruptedException {

        if (canTan()) {
            clickTan();
        } else {
            bank();
        }
        return 700;
    }

    public boolean canTan() {
        return getEquipment().isWieldingWeaponThatContains("staff") &&
                getInventory().contains("Black dragonhide");
    }

    public void clickTan() {
        int rX = random(601, 603);
        int rY = random(322, 324);

        if (getTabs().magic.open()) {
            getMouse().click(rX, rY, false);
            new ConditionalSleep(2000, 500) {
                @Override
                public boolean condition() throws InterruptedException {
                    return getInventory().onlyContains("Black dragonleather");
                }
            }.sleep();
        }
    }
    
    private void bank() throws InterruptedException {
        if (!Banks.GRAND_EXCHANGE.contains(myPosition())) {
            getWalking().webWalk(Banks.GRAND_EXCHANGE);
        } else if (!getBank().isOpen()) {
            getBank().open();
            sleep(random(1300, 2300));
        } else if (!getInventory().isEmptyExcept("Black dragonhide", "Rune pouch")) {
            getBank().depositAll();
            sleep(random(1300, 2300));
        } else if (getBank().contains("Black dragonhide")) {
            getBank().withdrawAll("Black dragonhide");
            sleep(random(1300, 2300));
        } else {
            stop(true);
        }
    }

    @Override
    public void onPaint(Graphics2D paint) {
        int mXp = getExperienceTracker().getGainedXP(Skill.MAGIC);

        super.onPaint(paint);
        paint.drawString("Magic XP: " + mXp, 387, 328);
    }
}

My questions are:

1. What would be the best and most human-like way to make the script stop tanning, and bank? A few options I thought of would be:

  • Wait until the message "You don't have any hides in your inventory" appears in the game chat and bank.
  • Another one would be to simply remember that it's already cast the spell 5 times (although if I lag or something, I assume it wouldn't, and would maybe cast the spell fewer times?)
  • Check the inventory to see if there are any hides left, although how could I make this seem less bot-like? A human wouldn't check the inventory after the first cast..

2. How could I implement conditional sleeps to banking as well? I've read in other posts that it's always best to do conditional rather than random, but how would I do that in this case?

Comments and criticism is as always more than welcome. 

Anyway, thank you all for the help and the read, looking forward to learning more about scripting and hopefully contribute a little bit to the community. :) 

 

Edit1: Tweaked a few things in the script

Edited by Lol_marcus
Link to comment
Share on other sites

52 minutes ago, Gunman said:

@Lol_marcus I am like a god bro jeez 😔


 else if (!getBank().isOpen()) {
            if (getBank().open()) {
           	 new ConditionalSleep(8000) {
               	 @Override
               	 public boolean condition() throws InterruptedException {
                    	return getBank().isOpen();
                	}
            	}.sleep();
            }
 }

 

It seems so simple and obvious when I read it. The lack of knowledge of putting these things together is what I need to work on. Thanks for this. :)

1 hour ago, Chris said:

Thanks for the links.

 

  • Like 1
Link to comment
Share on other sites

11 hours ago, Gunman said:

@Lol_marcus I am like a god bro jeez 😔


 else if (!getBank().isOpen()) {
            if (getBank().open()) {
           	 new ConditionalSleep(8000) {
               	 @Override
               	 public boolean condition() throws InterruptedException {
                    	return getBank().isOpen();
                	}
            	}.sleep();
            }
 }

 

The conditional sleep isnt necessary for getBank().open() as the method already does that internally. getBank().open() will only return true if the bank was successfully opened (or already open), so there is actually nothing to wait for. If an interact() on a bank entity was performed, then it would be necessary to sleep until the bank is open.

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