Jump to content

How to detect how you are being attacked.


Recommended Posts

Posted

I was wondering if there is a way to find out how i am being attacked.

For example, when being attacked by say a dragon, i want to be ranging it and praying mage.

How can i see whether my player is fighting it in melee range or ranging range, i looked at the API on Combat and couldn't see anything.

Currently, my only thought was to make a big array of 'safe' tiles and just force the bot to move to one of them.

However, if the player didn't need to move and it moved anyway, i feel that would look bot-like.

Anyway your feedback is appreciated.

Posted
final Player me = myPlayer();
		
		// Get all green dragons that are 'locked' on me
		List<NPC> greenDragonsFocusingOnMe = npcs.getAll().stream()
				.filter(npc -> me.equals(npc.getInteracting()))
				.filter(npc -> npc.getName().equals("Green dragon"))
				.collect(Collectors.toList());
		
		// Get the green dragon I'm locked on
		NPC greenDragonsImFocusedOn = greenDragonsFocusingOnMe.stream()
				.filter(npc -> npc.equals(me.getInteracting()))
				.findFirst()
				.orElse(null);
		
		if (greenDragonsFocusingOnMe != null && !greenDragonsFocusingOnMe.isEmpty()) {
			if (greenDragonsImFocusedOn != null) {
				// wait for dragon to die
				// heal if low on health
			} else {
				// pick one of those dragons that are focused on you
				greenDragonsImFocusedOn = greenDragonsFocusingOnMe.get(0);
				if (greenDragonsImFocusedOn.interact("Attack")) {
					// ... do stuff
				}
			}
		}

One thing I haven't included is the sorting of the green dragons by distance to you. I won't spoon feed you everything. :)

  • Like 1
Posted
6 minutes ago, liverare said:

One thing I haven't included is the sorting of the green dragons by distance to you. I won't spoon feed you everything. :)

 

List<NPC> greenDragonsFocusingOnMe = npcs.getAll().stream()
                .filter(npc -> myPlayer().equals(npc.getInteracting()))
                .filter(npc -> npc.getName().equals("Green dragon"))
                .sorted(Comparator.comparingInt(npc -> getMap().realDistance(npc)))
                .collect(Collectors.toList());

:doge:

  • Like 1

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