Jump to content

get all bank booths


ni562

Recommended Posts

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

	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.

Edited by Nitrousek
Link to comment
Share on other sites

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

 

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

 

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.

Link to comment
Share on other sites

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

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