Jump to content

Who is interacting with me ? (OSB2)


Botre

Recommended Posts

Mainly useful for combat situations with aggressive monsters:

package myplayer.Botrepreneur;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;

public class WhoIsInteractingWithMe {

	/**
	 * @author Botrepreneur
	 * @Version: 00.21
	 */

	public static List<NPC> getList(Script script) {
		List<NPC> returnList = new ArrayList<NPC>();
		List<NPC> allList = script.npcs.getAll();
		if (allList != null && !allList.isEmpty()) {
			for (NPC npc : allList) {
				if (npc != null && npc.getInteracting() != null && npc.getInteracting().getName().equals(script.myPlayer().getName())) {
					returnList.add(npc);
				}
			}
		}
		return returnList;
	}

	public static NPC getRandom(Script script) {
		List<NPC> list = WhoIsInteractingWithMe.getList(script);
		return list != null && !list.isEmpty() ? list.get(new Random().nextInt(list.size()) - 1) : null;
	}

	public static NPC getClosest(Script script) {
		double lowestDistance = Double.MAX_VALUE;
		List<NPC> allList = script.npcs.getAll();
		List<NPC> closestList = new ArrayList<NPC>();
		if (allList != null && !allList.isEmpty()) {
			for (NPC npc : allList) {
				if (npc == null || !npc.exists() || npc.getInteracting() == null || !npc.getInteracting().getName().equals(script.myPlayer().getName())) {
					continue;
				}
				if (npc.getPosition().distance(script.myPosition()) < lowestDistance) {
					closestList.clear();
					closestList.add(npc);
					lowestDistance = npc.getPosition().distance(script.myPosition());
				} else if (npc.getPosition().distance(script.myPosition()) == lowestDistance) {
					closestList.add(npc);
				}
			}
		}
		return closestList != null && !closestList.isEmpty() ? closestList.get(new Random().nextInt(closestList.size()) - 1) : null;
	}

}
Edited by Botrepreneur
Link to comment
Share on other sites

Or can't you just do player/character.getInteracting()?

 

No, he wants to get all the NPCs attacking him, useful when you've got a lot of them and they're agressive.

 

player get interacting wouldn't do the job, because: 1. you may not be interacting 2. if interacting, it's one NPC, and it's not used for the same purpose.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Possible solutions:
Mulit area:

A filter all npcs that are interacting with you, when you're not interacting any and you're under attack.
A result - the npc you want to attack first.

B filter all npcs that are interacting you, when you're attacking npc.

B result - now you have npc that you want to attack next (after killing the current one)

 

Single area
A simply filter all npcs that are interacting with you when you're not interacting any and you're under attack.
A result - the npc you want to attack, or run away from it.


You want to make such things in other thread.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...