Jump to content
Sign in to follow this  
TheKillerAurial

TSRunner - Need some feedback

Recommended Posts

Hi Scripting Community,

I would like to get some feedback on my first script TSRunner (Trout Salmon Runner).

I have some background in software development and testing but would not consider myself a developer.

I have written the below script to run to the fishing spot in barb village and collect fish on the ground , then head to the GE to bank and repeat (I chose not to go to edge bank)- I have tested it for 2hrs+ and seems to be working (20-25k per hour)- albeit it seems to be competing with many looting bots in the area.

One problem I have been experiencing is if there is a large loot pile on the floor, it always seems to try and "take" the first one. I'm guessing it is trying to "take" index 0. Can you specify the index in anyway so say if there is a pile on the floor it will take the 6th or 7th item if it exists?

529794267_ScreenShot2020-04-02at7_55_29am.png.34c5c1aec0333776131df701a16b94ed.png

Code:

import java.awt.Graphics2D;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.event.WebWalkEvent;
import org.osbot.rs07.event.webwalk.PathPreferenceProfile;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Aurial", info = "Trout - Salmon Runner", logo = "", name = "TSRunner", version = 1)
public class TSRunnerScript extends Script {

    private Area fishLocation = new Area(3104, 3435, 3109, 3431);
    private Area bankLocation = new Area(3161, 3492, 3168, 3486);

    enum State {
        RUNNING2BANK, RUNNING2FISH, LOOTING;
    }

    private State currentState;

    private Boolean checkInventoryIsEmpty(){
        if(inventory.isEmpty()){
            log("TSRunner || Inventory IS empty.");
            return true;
        }
        else {
            log("TSRunner || Inventory IS NOT empty!");
            log("TSRunner || Will attempt to Bank items");
            return false;
        }
    }

    private void goToFishSpot() throws InterruptedException {
        if(!inventory.isEmpty()){
            currentState = State.RUNNING2BANK;
        }
        else {
            log("TSRunner || Heading to fishing location...");
            WebWalkEvent webEvent = new WebWalkEvent(fishLocation);
            webEvent.useSimplePath();
            PathPreferenceProfile ppp = new PathPreferenceProfile();
            ppp.setAllowTeleports(false);
            webEvent.setPathPreferenceProfile(ppp);
            execute(webEvent);
            log("TSRunner || Arrived at fishing location...");
            sleep(random(300,500));
        }
    }

    private void lootFish() throws InterruptedException {
        log("TSRunner || Looting fish...");
        while (!inventory.isFull()){
            if(!myPlayer().isAnimating() || !myPlayer().isMoving() || !myPlayer().isUnderAttack()){
                GroundItem fishies = getGroundItems().closest("Salmon", "Trout", "Raw salmon", "Raw trout");
                if(fishies != null){
                    if(inventory.isEmpty()){
                        fishies.interact("Walk here");
                    }
                    sleep(random(20, 333));
                    fishies.interact("Take");
                    sleep(random(20, 333));
                }
            }
        }
        if(inventory.isFull()){
            log("TSRunner || Inventory is full.");
            currentState = State.RUNNING2BANK;
        }
    }

    private void goToBankAndDepositFish() throws InterruptedException {
        log("TSRunner || Heading to bank location...");
        WebWalkEvent webEvent = new WebWalkEvent(bankLocation);
        webEvent.useSimplePath();
        PathPreferenceProfile ppp = new PathPreferenceProfile();
        ppp.setAllowTeleports(false);
        webEvent.setPathPreferenceProfile(ppp);
        execute(webEvent);
        log("TSRunner || Arrived at bank location...");
        sleep(random(300,500));
        if (!myPlayer().isAnimating() || !myPlayer().isMoving() || !myPlayer().isUnderAttack()) {
            log("TSRunner || Attempting to deposit all...");
            sleep(random(300,500));
            if (inventory.isFull()) {
                if (getBank().isOpen()) {
                    sleep(random(200,300));
                    getBank().depositAll();
                    sleep(random(50, 100));
                    log("TSRunner || Banking finished...");
                    currentState = State.RUNNING2FISH;
                }
                else {
                    sleep(random(300,500));
                    getBank().open();
                    sleep(random(200,300));
                    getBank().depositAll();
                    sleep(random(50, 100));
                    log("TSRunner || Banking finished...");
                    currentState = State.RUNNING2FISH;
                }
            }
        }
    }

    @Override
    public void onStart(){
        log("-----------------------");
        log("TSRunner || Starting...");
        log("-----------------------");
        if (checkInventoryIsEmpty()){
            currentState = State.RUNNING2FISH;
        }
        else {
            currentState = State.RUNNING2BANK;
        }
    }

    @Override
    public int onLoop() throws InterruptedException{
        switch (currentState){
            case RUNNING2FISH:
                return first();
            case LOOTING:
                return second();
            case RUNNING2BANK:
                return third();
        }
        return random(200, 300);
    }

    private int first() throws InterruptedException {
        goToFishSpot();
        currentState = State.LOOTING;
        return random(200, 300);
    }

    private int second() throws InterruptedException{
        lootFish();
        return random(200,300);
    }

    private int third() throws InterruptedException{
        goToBankAndDepositFish();
        return random(200,300);
    }

    @Override
    public void onExit(){
        log("---------------------");
        log("TSRunner || Ending...");
        log("---------------------");
    }

    @Override
    public void onPaint(Graphics2D g){
    }
}

Share this post


Link to post
Share on other sites

Made a script that does the same exact thing, just had it spam the hell out of the loot pile. Seems to work well. Maybe you can just have it click the ground-tile with loot on it if it keeps insisting on rightclicking and doing index 0?
 

Another option would be to add all grounditems to a list, then have it do a different index from that list when looting.

Share this post


Link to post
Share on other sites
34 minutes ago, botelias said:

Made a script that does the same exact thing, just had it spam the hell out of the loot pile. Seems to work well. Maybe you can just have it click the ground-tile with loot on it if it keeps insisting on rightclicking and doing index 0?
 

Another option would be to add all grounditems to a list, then have it do a different index from that list when looting.

Thanks for the advice - really appreciate it.

Could you show me an example for the grounditems -> list option?

Share this post


Link to post
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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...