Class NPCs


  • public class NPCs
    extends java.lang.Object
    The NPCs class provides a high-level API for querying and interacting with NPCs (Non-Player Characters) in the RuneLite client.

    Features include:

    • Caching of NPC lists to reduce client calls
    • Line-of-sight checks between player and NPCs
    • Nearby player count detection
    • Item-on-NPC interaction
    • Constructor Summary

      Constructors 
      Constructor Description
      NPCs()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getNearbyPlayerCount​(net.runelite.api.NPC npc)
      Counts the number of nearby players (excluding the local player and friends) within a 10-tile radius of the given NPC.
      boolean hasLOS​(net.runelite.api.NPC npc)
      Determines if the specified NPC has line of sight (LOS) to the local player.
      void itemOnNpc​(KSNPC npc, KSItem item)
      Performs a "Use item on NPC" interaction.
      NPCQuery query()
      Queries all active NPCs in the game world and wraps them as KSNPC objects.
      • Methods inherited from class java.lang.Object

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

      • NPCs

        public NPCs()
    • Method Detail

      • query

        public NPCQuery query()
        Queries all active NPCs in the game world and wraps them as KSNPC objects. Results are cached per game tick for performance.
        Returns:
        an NPCQuery containing the list of active NPCs.
      • hasLOS

        public boolean hasLOS​(net.runelite.api.NPC npc)
        Determines if the specified NPC has line of sight (LOS) to the local player.
        Parameters:
        npc - the NPC to check
        Returns:
        true if LOS exists, otherwise false
      • getNearbyPlayerCount

        public long getNearbyPlayerCount​(net.runelite.api.NPC npc)
        Counts the number of nearby players (excluding the local player and friends) within a 10-tile radius of the given NPC.
        Parameters:
        npc - the NPC around which to count players
        Returns:
        the number of nearby players
      • itemOnNpc

        public void itemOnNpc​(KSNPC npc,
                              KSItem item)
        Performs a "Use item on NPC" interaction. Selects the item first (if not already), then triggers the interaction via MenuAction.WIDGET_TARGET_ON_NPC.
        Parameters:
        npc - the target NPC
        item - the item to use on the NPC