Jump to content

get all bank booths


Recommended Posts

Posted (edited)
NPC spot = getNpcs().closest((Filter<NPC>) npc -> npc.getName().equals("Banker") && npc.hasAction("Bank"));

Use this for the closest NPC. Always do it by their name and actions because if you use the id of the bank etc, on each RS update, the ids do change so the bot will then be unsuccessful. 

 

For a bank booth...

             if (!getBank().isOpen())
                    getBank().open();

or try

Object bank = getBank().open();
Edited by Kenn
Posted
	public ArrayList<RS2Object> obj() {
		ArrayList<RS2Object> list = new ArrayList<>();
		for (RS2Object o : objects.getAll()) {
			if (o.getName().equalsIgnoreCase("bank booth")) {
				list.add(o);
			}
		}
		return list;
	}

Returns what you wanted.

From this you can choose a random one.

 

 

 

Exactly what i needed! thanks for the feedback. I modified it a little and am posting it here if anyone is interested.

 

 

public RS2Object randomBanker() {
       ArrayList<RS2Object> list = new ArrayList<>();
       RS2Object bank; // Our bank booth 


     for (RS2Object o : objects.getAll()) {
           if (o.getName().equalsIgnoreCase("Bank booth")) {
              list.add(o);
           }
      }


     bank = list.get(random(list.size() - 1)); //Chose a random booth 


  return bank;
}
Posted (edited)

 

Exactly what i needed! thanks for the feedback. I modified it a little and am posting it here if anyone is interested.

 

 

public RS2Object randomBanker() {
       ArrayList<RS2Object> list = new ArrayList<>();
       RS2Object bank; // Our bank booth 


     for (RS2Object o : objects.getAll()) {
           if (o.getName().equalsIgnoreCase("Bank booth")) {
              list.add(o);
           }
      }


     bank = list.get(random(list.size() - 1)); //Chose a random booth 


  return bank;
}

 

 

This is a bit shorter:

public RS2Object getRandomBank() {

    List<RS2Object> banks = getObjects().filter(obj -> obj.getName().equals("Bank booth"));
    return (banks == null || banks.size() == 0) ? null : banks.get(random(banks.size()-1));
}
Edited by Explv
  • Like 1
Posted

 

This is a bit shorter:

public RS2Object getRandomBank() {

    List<RS2Object> banks = getObjects().filter(obj -> obj.getName().equals("Bank booth"));
    return (banks == null || banks.size() == 0) ? null : banks.get(random(banks.size()-1));
}

 

Thanks man!! Always swooping in and shortening my code :p I'm not sure i understand all of that...you're knowledge of java/programming is greater than mine.

Posted (edited)

Thanks man!! Always swooping in and shortening my code tongue.png I'm not sure i understand all of that...you're knowledge of java/programming is greater than mine.

 

It just means:

 

-Get all objects and filter them so that the list only contains objects with the name "Bank booth"

-If the list is null, or there are no elements in the list, return null

 Otherwise return a random value from the list.

 

Edited by Explv
Posted

It just means:

 

-Get all objects and filter them so that the list only contains objects with the name "Bank booth"

-If the list is null, or there are no elements in the list, return null

 Otherwise return a random value from the list.

 

 

Eclipse is throwing up some warnings..What should i do?

Posted (edited)

Post em here, you need java 8 for the stuff they posted.

 

 

noob ^^

 

noob??  Learn to Java 8 m8

 

 

It is safe to ignore this warning. It is an unchecked generics array creation warning produced by getObjects().filter().

You can just supress it.

@SuppressWarnings("unchecked")
List<RS2Object> banks = getObjects().filter(obj -> obj.getName().equals("Bank booth"));

If you don't want a warning you can always do:

List<RS2Object> banks = getObjects().getAll().stream().filter(obj -> obj.getName().equals("Bank booth")).collect(Collectors.toList());

But the first way is perfectly fine and shorter.

 

"Type Safety: A generic array of Filter<RS2Object> is created for a varargs parameter."

 

anything to worry about?

 

No it is not anything to worry about.

Edited by Explv

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