Jump to content

if player is in closest bank


Lewis

Recommended Posts

looking for my script to run to the closest bank, but i dont know how to get if closest bank contains myplayer

 

code is:

private final Area[] BANKS = { (Banks.DRAYNOR),
		    (Banks.AL_KHARID),
		    (Banks.LUMBRIDGE_UPPER),
		    (Banks.FALADOR_EAST),
		    (Banks.FALADOR_WEST),
		    (Banks.FALADOR_EAST),
		    (Banks.VARROCK_WEST),
		    (Banks.CAMELOT),
		    (Banks.CATHERBY),
		    (Banks.EDGEVILLE),
		    (Banks.YANILLE),
		    (Banks.GNOME_STRONGHOLD),
		    (Banks.ARDOUGNE_NORTH),
		    (Banks.ARDOUGNE_SOUTH),
		    (Banks.CASTLE_WARS),
		    (Banks.DUEL_ARENA),
		    (Banks.PEST_CONTROL),
		    (Banks.CANIFIS),
		    (Banks.TZHAAR)}; 

&&
 
if (!BANKS.contains(myPlayer())) {
				walking.webWalk(BANKS);
				sleep(random(250, 300));
			
Edited by Lewis
Link to comment
Share on other sites

		List<Area> closestArea = new ArrayList<Area>();
		
		closestArea.add(Banks.AL_KHARID);
		
		closestArea.sort(new Comparator<Area>() {
			public int compare(Area entry1, Area entry2) {
				return entry1.getRandomPosition().distance(myPlayer()) - entry2.getRandomPosition().distance(myPlayer());
			}
		});
		getWalking().webWalk(closestArea.get(0));
		
		if(!closestArea.get(0).contains(myPlayer())
		    getWalking().webWalk(closestArea.get(0));

here you go man, just add more banks to the ArrayList

 

closestArea.get(0) returns the closest area.

Edited by Vilius
Link to comment
Share on other sites

 

looking for my script to run to the closest bank, but i dont know how to get if closest bank contains myplayer

 

code is:

private final Area[] BANKS = { (Banks.DRAYNOR),
		    (Banks.AL_KHARID),
		    (Banks.LUMBRIDGE_UPPER),
		    (Banks.FALADOR_EAST),
		    (Banks.FALADOR_WEST),
		    (Banks.FALADOR_EAST),
		    (Banks.VARROCK_WEST),
		    (Banks.CAMELOT),
		    (Banks.CATHERBY),
		    (Banks.EDGEVILLE),
		    (Banks.YANILLE),
		    (Banks.GNOME_STRONGHOLD),
		    (Banks.ARDOUGNE_NORTH),
		    (Banks.ARDOUGNE_SOUTH),
		    (Banks.CASTLE_WARS),
		    (Banks.DUEL_ARENA),
		    (Banks.PEST_CONTROL),
		    (Banks.CANIFIS),
		    (Banks.TZHAAR)}; 

&&
 
if (!BANKS.contains(myPlayer())) {
				walking.webWalk(BANKS);
				sleep(random(250, 300));
			

 

Consider reading this tutorial on Arrays: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Edited by Explv
  • Like 2
Link to comment
Share on other sites

 

make a webwalk event and throw all the banks into the webwalk event and it'll walk to the closest one

 

(this is the solution for walking to the closest bank)

 

need to figure out how to return true if for example:

GE is closest, bank, it walks to ge // i got working

then

if GE contains myplayer { 

w.e

 

*GE will be closest bank

Link to comment
Share on other sites

need to figure out how to return true if for example:

GE is closest, bank, it walks to ge // i got working

then

if GE contains myplayer { 

w.e

 

*GE will be closest bank

 

All you need to do is check if any of the Areas in the Area[] contain your Position.

 

I'll give you a hint, you might want to use a for loop: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html

  • Like 2
Link to comment
Share on other sites

need to figure out how to return true if for example:

GE is closest, bank, it walks to ge // i got working

then

if GE contains myplayer { 

w.e

 

*GE will be closest bank

 

 

 

Link to comment
Share on other sites

Doesn't seem like you saw my post. 

List<Area> closestArea = new ArrayList<Area>();
		
		closestArea.add(Banks.AL_KHARID);
		closestArea.add(Banks.DRAYNOR);
		closestArea.add(Banks.VARROCK_WEST);

		closestArea.sort(new Comparator<Area>() {
			public int compare(Area entry1, Area entry2) {
				return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer());
			}
		});
		getWalking().webWalk(closestArea.get(0));
		
		if(!closestArea.get(0).contains(myPlayer())
		    getWalking().webWalk(closestArea.get(0));

just add more closestArea.add(Banks.DRAYNOR); ?

or do i need to add, entry 1,2,3,4 etc also?

Edited by Lewis
Link to comment
Share on other sites

List<Area> closestArea = new ArrayList<Area>();
		
		closestArea.add(Banks.AL_KHARID);
		closestArea.add(Banks.DRAYNOR);
		closestArea.add(Banks.VARROCK_WEST);

		closestArea.sort(new Comparator<Area>() {
			public int compare(Area entry1, Area entry2) {
				return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer());
			}
		});
		getWalking().webWalk(closestArea.get(0));
		
		if(!closestArea.get(0).contains(myPlayer())
		    getWalking().webWalk(closestArea.get(0));

just add more closestArea.add(Banks.DRAYNOR); ?

or do i need to add, entry 1,2,3,4 etc also?

 

Just do closestArea.add(...); no need to make more sorters.

Link to comment
Share on other sites

Just do closestArea.add(...); no need to make more sorters.

 

 

done like so:

List<Area> closestArea = new ArrayList<Area>();

@[member=Override]
	public void onStart() {
		gui = new GUI();
		closestArea.add(Banks.AL_KHARID);
		closestArea.add(Banks.DRAYNOR);
		closestArea.add(Banks.VARROCK_WEST);
		closestArea.sort(new Comparator<Area>() {
			public int compare(Area entry1, Area entry2) {
				return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer());
			}
		});
	}


although on line :

return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer());

 

it wants me to insert ; to complete the block (if i do insert ; then entry 2 gets full error)

Link to comment
Share on other sites

done like so:

List<Area> closestArea = new ArrayList<Area>();

@[member='Override']
	public void onStart() {
		gui = new GUI();
		closestArea.add(Banks.AL_KHARID);
		closestArea.add(Banks.DRAYNOR);
		closestArea.add(Banks.VARROCK_WEST);
		closestArea.sort(new Comparator<Area>() {
			public int compare(Area entry1, Area entry2) {
				return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer());
			}
		});
	}


although on line :

return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer());

 

it wants me to insert ; to complete the block (if i do insert ; then entry 2 gets full error)

oops should be:

return entry1.getRandomPosition().distance(myPlayer()) - entry2.getRandomPosition().distance(myPlayer());

you should only add the banks in on start, then sort the array list when you want to walk or do something.

Edited by Vilius
Link to comment
Share on other sites

oops should be:

return entry1.getRandomPosition().distance(myPlayer()) - entry2.getRandomPosition().distance(myPlayer());

you should only add the banks in on start, then sort the array list when you want to walk or do something.

 

Why would you sort the Areas to determine if you are in the closest bank? Just loop over the Area[]... if you are in one of the Areas, guess what? You are in the closest bank. 

 

To walk to the closest bank you can just call getWalking().webWalk(bankAreas)

Edited by Explv
Link to comment
Share on other sites

Why would you sort the Areas to determine if you are in the closest bank? Just loop over the Area[]... if you are in one of the Areas, guess what? You are in the closest bank. 

 

To walk to the closest bank you just call getWalking().webWalk(bankAreas)

Ofcourse, you can do that too, I'm not judging. I just find sorting the areas to be more useful rather than just iterating through them.

And for the new guy it will be easier to understand boolean logic, I guess.

Albeit this snippet I posted was for closest position finding from an array list, but it works for areas too, more versatile I suppose.

Edited by Vilius
Link to comment
Share on other sites


private enum Bank {

DRAYNOR(Banks.DRAYNOR),

AL_KHARID(Banks.AL_KHARID),

LUMBRIDGE(Banks.LUMBRIDGE_UPPER),

FALADOR_EAST(Banks.FALADOR_EAST),

FALADOR_WEST(Banks.FALADOR_WEST),

VARROCK_EAST(Banks.FALADOR_EAST),

VARROCK_WEST(Banks.VARROCK_WEST),

SEERS(Banks.CAMELOT),

CATHERBY(Banks.CATHERBY),

EDGEVILLE(Banks.EDGEVILLE),

YANILLE(Banks.YANILLE),

GNOME_STRONGHOLD(Banks.GNOME_STRONGHOLD),

ARDOUNGE_NORTH(Banks.ARDOUGNE_NORTH),

ARDOUNE_SOUTH(Banks.ARDOUGNE_SOUTH),

CASTLE_WARS(Banks.CASTLE_WARS),

DUEL_ARENA(Banks.DUEL_ARENA),

PEST_CONTROL(Banks.PEST_CONTROL),

CANIFIS(Banks.CANIFIS),

BLAST_FURNACE(new Area(1949, 4956, 1947, 4958)),

TZHAAR(Banks.TZHAAR);

private final Area area;

Bank(Area area) {

this.area = area;

}

}

public static Area closestTo(Entity e) {

HashMap<Bank, Integer> distMap = new HashMap<Bank, Integer>();

for (Bank b : Bank.values()) {

distMap.put(b, e.getPosition().distance(b.area.getRandomPosition()));

}

HashMap<Integer, Bank> distMapSorted = sortByDistance(distMap);

Area cBank = distMapSorted.values().toArray(new Bank[Bank.values().length])[0].area;

return cBank;

}

private static <K, V extends Comparable<? super V>> HashMap<V, K> sortByDistance(Map<K, V> map) {

HashMap<V, K> result = new LinkedHashMap<>();

Stream<Map.Entry<K, V>> st = map.entrySet().stream();

st.sorted(Map.Entry.comparingByValue()).forEachOrdered(e -> result.put(e.getValue(), e.getKey()));

return result;

}

@LP

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