Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Buy OSRS Gold

Sell OSRS Gold
Sign in to follow this  
Guest

DVFisher

Recommended Posts

Guest

Hey guys, this is the first script I've created so far. I'm applying some concepts I've learned through Trilez's scripting tutorial, as well as reading through the API. I'm still a little confused as to how the Timing.waitCondition() function works, but what I've got seems to be working so far. Basically, I don't want the script to spam click a fishing spot. Another thing I'm still iffy about is the best way to get NPCs to interact with. Should I use NPCs.findNearest() or implement another function? Also, overall control flow in this script seems a little messy. I'm looking into implementing behavior trees in my next script. Feel free to give me any suggestions on what to improve for next time as well. Thanks.

 

This script supports: 

  1. starting from anywhere
  2. withdrawing net from bank
  3. walking back to spot on death

 

Spoiler
package scripts;

import org.tribot.api.DynamicClicking;
import org.tribot.api.General;
import org.tribot.api.Timing;
import org.tribot.api.interfaces.Positionable;
import org.tribot.api2007.*;
import org.tribot.api2007.types.RSArea;
import org.tribot.api2007.types.RSNPC;
import org.tribot.api2007.types.RSTile;
import org.tribot.script.Script;
import org.tribot.script.ScriptManifest;

import java.util.function.BooleanSupplier;


@ScriptManifest(authors = "Freaking09", name = "Draynor Village fisher", category = "Fishing")
public class DVFisher extends Script {

    //Bank area
    private final RSArea bank = new RSArea(
            new RSTile(3091, 3245, 0),
            new RSTile(3095, 3242, 0)
    );

    //Fishing area
    private final RSArea fishingSpot = new RSArea(
            new RSTile(3082, 3234, 0),
            new RSTile(3088, 3225, 0)
    );

    //only used on death
    private boolean walkToSpot(RSArea area) {
        return WebWalking.walkTo(area.getRandomTile());
    }

    //tries to deposite everything except net
    private boolean depositFish() {
        if (!Banking.isBankScreenOpen()){
            if (!Banking.openBank())
                return false;
            if (Banking.depositAllExcept(303) < 1)
                return false;
            if (!Banking.close())
                return false;
            if (Inventory.getAll().length > 1) {
                println("Something extra still in invent");
                return false;
            }
        }
        return true;
    }

    //gets the net from bank
    private boolean getNet() {
        if (!Banking.isBankScreenOpen()) {
            if (!Banking.openBank()) {
                return false;
            } else {
                if(!Banking.withdraw(1, 303))
                    return false;
                if (!Banking.close()) {
                    return false;
                } else return true;
            }
        } else return false;
    }

    //checks if player is at a fishing spot by looking for nearby spots
    private boolean isAtFishingSpot() {
        final RSNPC[] spots = NPCs.findNearest("Fishing Spot");
        if (spots.length < 1)
            return false;
        return spots[0].isOnScreen();
    }

    //checks if player is at bank by checking if current position is in bank area
    private boolean isInBank() {
        return bank.contains(Player.getPosition());
    }
    
    private boolean fish() {
        final RSNPC[] spots = NPCs.findNearest("Fishing Spot");
        if (spots.length == 0)
            return false;
        final RSNPC spot = spots[0];
        if (spot != null) {
            if (spot.isOnScreen()) {
                DynamicClicking.clickRSNPC(spot, "Small Net");
                return true;
            }
        } else
            return false;
        return true;
    }

    private boolean isFishing() {
        return Player.getAnimation() > 0;
    }

    @Override
    public void run() {
        while (true) {
            sleep(50);
            if (isInBank()) {
                println("In bank");
                if (Inventory.isFull()){
                    if(!depositFish()) {
                        println("something went wrong banking");
                        break;
                    }
                } else if (Inventory.find(303).length < 1) {
                    println("No net found");
                    if(!getNet())
                        break;
                } else if (!Inventory.isFull()){
                    final Positionable[] path = Walking.generateStraightPath(fishingSpot.getRandomTile());
                    Walking.walkPath(path);
                    General.sleep(100,200);
                    Timing.waitCondition(new BooleanSupplier() {
                        @Override
                        public boolean getAsBoolean() {
                            General.sleep(100);
                            return (fishingSpot.contains(Player.getPosition()) || !Player.isMoving());
                        }
                    }, General.random(1000,1200));
                }
            } else if (isAtFishingSpot()) {
                if (Inventory.isFull()) {
                    Walking.walkTo(bank.getRandomTile());
                    General.sleep(100,200);
                    Timing.waitCondition(new BooleanSupplier() {
                        @Override
                        public boolean getAsBoolean() {
                            General.sleep(100);
                            return (bank.contains(Player.getPosition()) || !Player.isMoving());
                        }
                    }, General.random(1000,1200));
                } else if (!isFishing()) {
                    fish();
                    Timing.waitCondition(new BooleanSupplier() {
                        @Override
                        public boolean getAsBoolean() {
                            General.sleep(100);
                            return isFishing();
                        }
                    }, General.random(1000,1200));
                }
            } else if (Inventory.isFull()) {
                walkToSpot(bank);
                Timing.waitCondition(new BooleanSupplier() {
                    @Override
                    public boolean getAsBoolean() {
                        General.sleep(100);
                        return (bank.contains(Player.getPosition()) || !Player.isMoving());
                    }
                }, General.random(1000,1200));
            } else if (!Inventory.isFull()) {
                walkToSpot(fishingSpot);
                Timing.waitCondition(new BooleanSupplier() {
                    @Override
                    public boolean getAsBoolean() {
                        General.sleep(100);
                        return (fishingSpot.contains(Player.getPosition()) || !Player.isMoving());
                    }
                }, General.random(1000,1200));
            }
        }
    }
}

 

 

 

  • Like 2

Share this post


Link to post
Share on other sites
1 hour ago, Freaking09 said:

Another thing I'm still iffy about is the best way to get NPCs to interact with. Should I use NPCs.findNearest() or implement another function?

You can decide which NPC to interact with by implementing AntiBanCompliance. To easily implement antiban, you can use starfox's antiban utility, i have taken the next target part from there for you.

public class Antiban {
 
    private static ABCUtil abc = new ABCUtil();
  
    public static <T extends Positionable> T selectNextTarget(Positionable[] rsnpc) {
        return (T) abc.selectNextTarget(rsnpc);
    }

}

//and then the find npc method you can do something like this:

public RSNPC findNpc(String name){
    RSNPC[] npcs = NPCs.findNearest(name);
    if(npcs.length > 0){
    	return AntiBan.selectNextTarget(npcs);
    }
    return null;
}

 

Edited by gef30

Share this post


Link to post
Share on other sites
Guest

Thanks for the suggestion gef30. Antiban is something I haven't really gotten into yet, but this looks like a great way to start. Thanks!

Share this post


Link to post
Share on other sites
Guest

For sure, I was taking a look a this framework and it looks pretty easy to implement. I'm just curious as to how specific each node would be. For example in my script, would it be wise to have the following nodes:

  • walking to bank
  • walking to spot
  • banking
  • fishing
  • depositing

or is each node too specific?

Share this post


Link to post
Share on other sites
8 minutes ago, Freaking09 said:

For sure, I was taking a look a this framework and it looks pretty easy to implement. I'm just curious as to how specific each node would be. For example in my script, would it be wise to have the following nodes:

  • walking to bank
  • walking to spot
  • banking
  • fishing
  • depositing

or is each node too specific?

public abstract class Node {

    public abstract boolean isValid();

    public abstract void execute();

}

public class Bank extends Node {
    @Override
    public boolean isValid() {
        return false;
    }

    @Override
    public void execute() {

    }
}

public class Fish extends Node {
    @Override
    public boolean isValid() {
        return false;
    }

    @Override
    public void execute() {

    }
}

public class Walk extends Node {
    @Override
    public boolean isValid() {
        return false;
    }

    @Override
    public void execute() {

    }
}

public class Variables {
    
    public static final RSArea bank = new RSArea(
            new RSTile(3091, 3245, 0),
            new RSTile(3095, 3242, 0)
    );

    public static final RSArea fishingSpot = new RSArea(
            new RSTile(3082, 3234, 0),
            new RSTile(3088, 3225, 0)
    );

    public static final int NET = 303;
    
}

public class Fisher extends Script {

    public ArrayList<Node> nodes = new ArrayList<>();

    @Override
    public void run() {
        init();
        while(true){
            if(Login.getLoginState().equals(Login.STATE.INGAME)){
                for(final Node n : nodes){
                    if(n.isValid())
                        n.execute();
                    else{
                        //AntiBan.timedActions();
                        General.sleep(100,200);
                    }

                    General.sleep(100, 200);
                }
            } else {
                Login.login();
            }
            General.sleep(20,40);
        }
    }

    public void init(){

    }
}

implement these node

Share this post


Link to post
Share on other sites
Guest
10 minutes ago, gef30 said:
public abstract class Node {

    public abstract boolean isValid();

    public abstract void execute();

}

public class Bank extends Node {
    @Override
    public boolean isValid() {
        return false;
    }

    @Override
    public void execute() {

    }
}

public class Fish extends Node {
    @Override
    public boolean isValid() {
        return false;
    }

    @Override
    public void execute() {

    }
}

public class Walk extends Node {
    @Override
    public boolean isValid() {
        return false;
    }

    @Override
    public void execute() {

    }
}

public class Variables {
    
    public static final RSArea bank = new RSArea(
            new RSTile(3091, 3245, 0),
            new RSTile(3095, 3242, 0)
    );

    public static final RSArea fishingSpot = new RSArea(
            new RSTile(3082, 3234, 0),
            new RSTile(3088, 3225, 0)
    );

    public static final int NET = 303;
    
}

public class Fisher extends Script {

    public ArrayList<Node> nodes = new ArrayList<>();

    @Override
    public void run() {
        init();
        while(true){
            if(Login.getLoginState().equals(Login.STATE.INGAME)){
                for(final Node n : nodes){
                    if(n.isValid())
                        n.execute();
                    else{
                        //AntiBan.timedActions();
                        General.sleep(100,200);
                    }

                    General.sleep(100, 200);
                }
            } else {
                Login.login();
            }
            General.sleep(20,40);
        }
    }

    public void init(){

    }
}

implement these node

Beautiful example, exactly what I was thinking as well. Thanks for your help, I'm gonna work on implementing this.

 

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

Sign in to follow this  

  • Our picks

    • Hello everyone,

      Last week we tried to roll out Auth0 Login, but we lost that battle. Now it's time to win the war!

      Important changes

      When logging into the client, you'll now have to enter your Auth0 account credentials instead of your forums credentials

      Note: 2FA is still handled through your forums account (for the time being)



      Changes for existing users

      You'll have to link your Auth0 account to your forums account here: https://tribot.org/forums/settings/login/?service=11


      Auth0 accounts have been created for most existing users. Please use your forums email address and password to login.



      Important notes

      Make sure to verify your email address upon creating a new Auth0 account


      When we mention your Auth0 account, we mean your account used for auth.tribot.org as displayed below
      • 56 replies
    • To better support the upcoming changes (TRiBot X, new repository), we're switching our login handler to Auth0. Instead of logging in with the standard form, you'll now be required to login through our Auth0 application.

      All existing accounts which have been used within approximately the past year have been imported into Auth0 using the same email and password combination which has been stored on the forums.

      What does this mean for users?

      Your account credentials are now even more securely stored


      You'll be able to login via Facebook, Google, and others in the future


      Is there anything users have to do differently now?

      Existing users: You'll have to login with the standard login, open your Account Settings, then link your Auth0 account


      New users: You'll be redirected to our Auth0 app (auth.tribot.org) where you'll be able to create an account


      Why was this change made?

      The new apps we are creating (such as the new repository) aren't able to use the forums to handle user logins


      To centralize all user accounts in one area


      To ensure that the client login doesn't go down when the forums are having problems


      To speed up our development


      Other considerations

      There's no documentation or official support for using Invision Community combined with Auth0, so there are still a few kinks we're working out


      We're in the works of creating an account management panel specifically for Auth0 accounts (ETA August)


      It's not possible to change email addresses for the time being (this will be resolved this August)


      Changing passwords is a weird process for the time being. To change your password, you'll have to use the "Don't remember your password" tool on the Auth0 login page
        • Like
      • 10 replies
    • Over the past month, we've been working hard on TRiBot's new repository - a much needed update. This change has been deemed necessary for TRiBot X, and will allow us to really speed up development of all aspects of TRiBot.

      Today we are going to share what we've been working on!


      Now you must be wondering what kind of features the new repository will have.... well, you'll have to be patient for a little while longer. We're still figuring out various technical aspects so we can't provide answers to all possible questions. We're also focusing on development rather than writing about it so that everyone can get access to our latest developments at lightning speed. I will however answer a few users' questions.

      We're planning on a release of this early to mid August, giving users some goodies before TRiBot X's release.

      Thank you all for being patient. I hope everyone is excited as much as I am!
        • Like
      • 17 replies
    • Over the past few months, I’ve been working diligently on a new project - TRiBot X. Everything has been written from the ground up, with all of the best practices of software engineering. Every aspect of TRiBot has been re-imagined to support three main goals: flexibility, useability, and reliability.
        • Like
      • 50 replies
    • Come give us feedback on the next version of TRiBot!
        • Thanks
        • Like
      • 86 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...