Class NpcQuery

    • Constructor Summary

      Constructors 
      Constructor Description
      NpcQuery​(Context ctx)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      NpcQuery alive()
      Filters the query to include only NPCs that are currently alive.
      NpcQuery at​(net.runelite.api.coords.WorldPoint location)
      Filters and returns an NpcQuery containing NPCs located at the specified world point.
      NpcQuery attackable()
      Returns Attackable NPC within the scene.
      NpcQuery idle()
      Filters for NPCs that are not interacting with anyone (null interaction).
      NpcQuery interacting()
      Filters the query to include only NPCs that are currently interacting with any entity other than the local player.
      NpcQuery interactingWith​(net.runelite.api.Actor actor)
      Filters the query to include only NPCs that are currently interacting with the specified actor.
      NpcQuery interactingWithPlayer()
      Filters the query to include only NPCs that are currently interacting with the local player.
      NpcEntity nearest()
      Retrieves the nearest NPC entity to the local player's current position.
      NpcQuery nearestTo​(net.runelite.api.coords.WorldPoint location)
      Sorts the current query results by determining the distance of each NPC's WorldPoint to a specified WorldPoint location and arranging them in ascending order of proximity.
      NpcQuery reachable()
      Filters the NPCs to include only those that are reachable based on their world location.
      NpcQuery sortByDistance()
      Sorts the NPC stream by distance from the local players' current location.
      protected java.util.function.Supplier<java.util.stream.Stream<NpcEntity>> source()  
      NpcQuery withAction​(java.lang.String action)
      Filters the query for NPCs that have a specific menu option available.
      NpcQuery within​(int distance)
      Filters the NPCs in the query to include only those within a specified distance from the local player's position.
      NpcQuery withinArea​(net.runelite.api.coords.WorldPoint min, net.runelite.api.coords.WorldPoint max)
      Filters the query to include only NPCs that are located within a specified rectangular area.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NpcQuery

        public NpcQuery​(Context ctx)
    • Method Detail

      • at

        public NpcQuery at​(net.runelite.api.coords.WorldPoint location)
        Filters and returns an NpcQuery containing NPCs located at the specified world point.

        This method applies a filter to include only NPCs whose world location matches the given location.

        Parameters:
        location - the WorldPoint representing the target location to filter NPCs by.
        Returns:
        an NpcQuery containing NPCs at the specified location.
      • attackable

        public NpcQuery attackable()
        Returns Attackable NPC within the scene. NPC's are considered attackable when: - They are not dead - Their menu options contain an "Attack" option

        Combat level is not taken into consideration since there are many NPC's without a combat level that are attackable. i.e. Yama's void flares

        Returns:
        NpcQuery
      • reachable

        public NpcQuery reachable()
        Filters the NPCs to include only those that are reachable based on their world location.

        This method applies a filter to the NPC query, ensuring that each NPC's raw data existence is validated and their world location is checked for reachability using the tile service.

        Returns:
        A @NpcQuery containing only the NPCs that are reachable.
      • idle

        public NpcQuery idle()
        Filters for NPCs that are not interacting with anyone (null interaction). This covers "not interacting with me" AND "not interacting with others".
        Returns:
        NpcQuery
      • nearest

        public NpcEntity nearest()
        Retrieves the nearest NPC entity to the local player's current position.

        This method determines the NPC closest to the local player by comparing the distances between each NPC's local location and the local player's local location. The comparison is performed by sorting the NPCs based on their proximity, and the first (closest) NPC is selected.

        The result is typically used to quickly identify and interact with the most immediate NPC relative to the player's current position, which can assist in various gameplay interactions.

        Returns:
        The NpcEntity nearest to the local player's current position, as determined based on the shortest distance in the local coordinate system. If no NPCs are available, the return value may be null.
      • nearestTo

        public NpcQuery nearestTo​(net.runelite.api.coords.WorldPoint location)
        Sorts the current query results by determining the distance of each NPC's WorldPoint to a specified WorldPoint location and arranging them in ascending order of proximity.

        This method calculates the distance between the provided location and each NPC's world location. The resulting query will contain NPCs sorted such that those closest to the specified location appear first.

        Parameters:
        location - The WorldPoint to which NPCs' distances will be calculated. This parameter defines the point of reference for sorting NPCs by proximity.
        Returns:
        A NpcQuery containing NPCs sorted by their proximity to the specified location.
      • sortByDistance

        public NpcQuery sortByDistance()
        Sorts the NPC stream by distance from the local players' current location.
        Returns:
        NpcQuery
      • within

        public NpcQuery within​(int distance)
        Filters the NPCs in the query to include only those within a specified distance from the local player's position.

        This method calculates the distance between each NPC's world location and the local player's current world location, including only those NPCs with a distance less than or equal to the specified value.

        Parameters:
        distance - The maximum distance (in tiles) from the local player within which NPCs should be included. This value must be greater than or equal to 0.
        Returns:
        A filtered NpcQuery containing only the NPCs within the specified distance from the local player.
      • withAction

        public NpcQuery withAction​(java.lang.String action)
        Filters the query for NPCs that have a specific menu option available.

        This method checks the list of actions associated with each NPC's composition. If the specified option matches any of the available actions (case-insensitive), the NPC will be included in the resulting query.

        Parameters:
        action - The menu option to check for, e.g., @Attack, @Talk-to, @Use, etc... The input is case-insensitive.
        Returns:
        A filtered NpcQuery containing only the NPCs that match the specified menu option.
      • withinArea

        public NpcQuery withinArea​(net.runelite.api.coords.WorldPoint min,
                                   net.runelite.api.coords.WorldPoint max)
        Filters the query to include only NPCs that are located within a specified rectangular area. The area is defined by two corner points, min (lower-left) and max (upper-right), in the world map grid.

        NPCs are included in the resulting query if their world point lies within the bounds created by the two corner points. The bounds are inclusive of the edges. This allows querying NPCs that exist within a specific area of interest.

        Parameters:
        min - The WorldPoint representing the lower-left corner of the area. This defines one bound of the rectangular query range.
        max - The WorldPoint representing the upper-right corner of the area. This defines the opposite bound of the rectangular query range.
        Returns:
        A filtered NpcQuery containing only the NPCs located within the specified area.
      • interactingWithPlayer

        public NpcQuery interactingWithPlayer()
        Filters the query to include only NPCs that are currently interacting with the local player.

        An NPC is considered to be interacting with the local player if the NPC's interacting target is non-null and matches the client’s local player.

        • This method allows narrowing down the query to find NPCs that are actively engaged with the local player, whether by combat, dialogue, or other forms of interaction.
        Returns:
        A filtered NpcQuery containing only the NPCs that are interacting with the local player.
      • interacting

        public NpcQuery interacting()
        Filters the query to include only NPCs that are currently interacting with any entity other than the local player.

        An NPC is considered to be interacting if its interacting target is non-null and does not match the local player. This includes NPCs that are engaged with other players, NPCs, or other entities in any form of interaction (e.g., combat, dialogue, etc.).

        • This method helps identify NPCs that are actively engaged in an interaction within the game world, excluding those interacting directly with the local player.
        Returns:
        A filtered NpcQuery containing only the NPCs that are interacting with entities other than the local player.
      • interactingWith

        public NpcQuery interactingWith​(net.runelite.api.Actor actor)
        Filters the query to include only NPCs that are currently interacting with the specified actor.

        An NPC is considered to be interacting with the given actor if the NPC's interacting target is non-null and matches the provided actor.

        • This method is useful for identifying NPCs actively engaging with a specific actor, such as another player, NPC, or inanimate entity.
        Parameters:
        actor - The Actor that the NPCs being searched for should be interacting with. Passing null as the parameter is not allowed.
        Returns:
        A filtered NpcQuery containing only the NPCs that are interacting with the specified actor.
      • alive

        public NpcQuery alive()
        Filters the query to include only NPCs that are currently alive.

        An NPC is considered to be alive if its internal state indicates it is not dead. This method applies a filter to exclude NPCs marked as dead from the result set.

        • NPCs included in the resulting query are capable of interaction or action within the game environment.
        • This filter helps narrow the query to focus only on viable, active NPCs.
        Returns:
        A filtered NpcQuery containing only the NPCs that are alive.