Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Script can't properly identify 100% of the time what's attacking me

Featured Replies

Hey all

 

For the last couple of days I've been experimenting and trying to find out how to properly identify who's attacking me. My script is struggling differentiating between Mobs attacking me and Players.

 

Here's my code:

                        //Monster Attacking:			
                        NPC monster = getNpcs().closest(npc -> npc.getName().equals("Skeleton") || npc.getName().equals("Scorpion"));
			if (myPlayer().isUnderAttack() && (monster != null) && monster.isInteracting(myPlayer())) {
                        //stuff
                        }

                        //Player Attacking:
                        //Use to be more complex but after taking out the conditions I had for players
                        //attacking it seamed to work better. So its literally just:
                        }else {
                        //stuff
                        }
                        

                        

Edited by Mushphang

I'm not sure this will work i have not tested it but maybe:

myPlayer().getInteracting() instanceof Player

you could determine if its a player or an NPC this way

Give this a whirl:

public final List<NPC> whoIsPossiblyAttackingMe() {
		return npcs.getAll().stream()
				.filter((npc) -> npc.isInteracting(myPlayer()))
				.collect(java.util.stream.Collectors.toList());
	}

This gets a list of all NPCs interacting with you (e.g., a goblin attacking you, a shop keeper responding to you, a pet following you, etc.) You can then loop through and check each of those npcs for a specific name. For instance, you know that a goblin would only be interacting with you because it's attacking you. However, a guard may have knocked you for failing to pickpocket him. So bare that in mind. :)

Edited by liverare

  • Author

Give this a whirl:

public final List<NPC> whoIsPossiblyAttackingMe() {
		return npcs.getAll().stream()
				.filter((npc) -> npc.isInteracting(myPlayer()))
				.collect(java.util.stream.Collectors.toList());
	}

This gets a list of all NPCs interacting with you (e.g., a goblin attacking you, a shop keeper responding to you, a pet following you, etc.) You can then loop through and check each of those npcs for a specific name. For instance, you know that a goblin would only be interacting with you because it's attacking you. However, a guard may have knocked you for failing to pickpocket him. So bare that in mind. smile.png

 

Sorry for the late response! Thank you very much for both of your replies.

 

So far after implementing this all is working well so far! Thank you much. :)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.