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.

How to tell if player is attacking me

Featured Replies

if(script.myPlayer().isUnderAttack()){
  for(Player p : script.getPlayers().getAll()){
	  if(p.isInteracting(script.myPlayer())){
	  	//Playyer attacking me
	  }
  }
}

This no work :(

Try just filtering the currently loaded players.

 

The code below was typed up in notepad and yes i know it doesn't compare properly.

players.getAll().stream().filter(p->p!=null && p.getInteracting() != null && p.getInteracting() == myPlayer()).findFirst()

 

script.players.getAll().stream().filter(x -> script.myPlayer().equals(x.getInteracting())).findFirst().isPresent(); 
// there is a player ATTEMPTING to attack, not necessarily already attacked

script.myPlayer().isHitBarVisible(); 
// only works if the attack triggered health bar display (not a splashed spell)

script.projectiles.getAll().stream().filter(x -> script.myPlayer().equals(x.getTargetEntity())).findFirst().isPresent();
// a ranged/magic attack was launched against the bot

Combining the 3 will give you a relatively good coverage on simple cases but unfortunately the topic of accurately determining combat is very complex. Imagine a player casts wind strike on you in the wilderness (he's interacting with you in this case) then quickly eats food (he's no longer interacting with you), the health bar is not visible but there is a projectile launched with your player as its target, if it hits then your health bar will be visible but if it splashes, your health bar will not be visible, the player is not interacting with you because the interaction was interrupted by eating and there is no projectile launched towards your player. But you are in combat with him for 8 seconds or whatever the timer is. The only way to determine if you really are under attack 100% is by caching this state once you detect an attacker and clearing the cache once the combat timer is up so if you want the maximum precision (eg pking scripts) you will have to multithread your script and dedicate a whole thread to managing the combat state and determining the opponent.

Edited by Token

  • Author
6 minutes ago, Token said:

script.players.getAll().stream().filter(x -> script.myPlayer().equals(x.getInteracting())).findFirst().isPresent(); 
// there is a player ATTEMPTING to attack, not necessarily already attacked

script.myPlayer().isHitBarVisible(); 
// only works if the attack triggered health bar display (not a splashed spell)

script.projectiles().getAll().stream().filter(x -> script.myPlayer().equals(x.getTargetEntity())).findFirst().isPresent();
// a ranged/magic attack was launched against the bot

Combining the 3 will give you a relatively good coverage on simple cases but unfortunately the topic of accurately determining combat is very complex. Imagine a player casts wind strike on you in the wilderness (he's interacting with you in this case) then quickly eats food (he's no longer interacting with you), the health bar is not visible but there is a projectile launched with your player as its target, if it hits then your health bar will be visible but if it splashes, your health bar will not be visible, the player is not interacting with you because the interaction was interrupted by eating and there is no projectile launched towards your player. But you are in combat with him for 8 seconds or whatever the timer is. The only way to determine if you really are under attack 100% is by caching this state once you detect an attacker and clearing the cache once the combat timer is up so if you want the maximum precision (eg pking scripts) you will have to multithread your script and dedicate a whole thread to managing the combat state and determining the opponent.

Thank you mr token <3

57 minutes ago, Token said:

script.players.getAll().stream().filter(x -> script.myPlayer().equals(x.getInteracting())).findFirst().isPresent(); 
// there is a player ATTEMPTING to attack, not necessarily already attacked

script.myPlayer().isHitBarVisible(); 
// only works if the attack triggered health bar display (not a splashed spell)

script.projectiles.getAll().stream().filter(x -> script.myPlayer().equals(x.getTargetEntity())).findFirst().isPresent();
// a ranged/magic attack was launched against the bot

Combining the 3 will give you a relatively good coverage on simple cases but unfortunately the topic of accurately determining combat is very complex. Imagine a player casts wind strike on you in the wilderness (he's interacting with you in this case) then quickly eats food (he's no longer interacting with you), the health bar is not visible but there is a projectile launched with your player as its target, if it hits then your health bar will be visible but if it splashes, your health bar will not be visible, the player is not interacting with you because the interaction was interrupted by eating and there is no projectile launched towards your player. But you are in combat with him for 8 seconds or whatever the timer is. The only way to determine if you really are under attack 100% is by caching this state once you detect an attacker and clearing the cache once the combat timer is up so if you want the maximum precision (eg pking scripts) you will have to multithread your script and dedicate a whole thread to managing the combat state and determining the opponent.

The master has answered

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.