Class PrivNPC

java.lang.Object
privbot.wrappers.PrivNPC

public final class PrivNPC extends Object
NPC wrapper returned by ctx.npcs.query(); interactions route through the game client.

Wraps the live client NPC: client-backed getters marshal through GameThread at call time, so a value can change between two reads and an NPC that despawned keeps answering stale values. Use exists() before acting on an old reference. interact(String) and the localPlayer*Of checks marshal through GameThread.ensure(java.util.function.Supplier<T>, T) themselves.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Attacks this NPC using its live Attack menu option.
    double
    distanceTo(net.runelite.api.coords.WorldPoint p)
    Tile-step distance from this NPC to p.
    boolean
    True if this NPC instance is still the live entry at NPC.getIndex().
    The NPC's live menu actions, tags stripped.
    int
    Alias for getNpcId() — consistent with PrivObject.getId() / PrivItem.getId().
    int
    The NPC's index in the client's NPC array (the menu identifier), or -1 without an NPC.
    net.runelite.api.Actor
    Returns the actor this NPC is currently interacting with (targeting), or null if not interacting with anyone.
    The NPC's name with tags stripped, falling back to the transformed composition's name.
    net.runelite.api.NPC
    The wrapped client NPC (may be null).
    int
    Composition id (e.g.
    net.runelite.api.coords.WorldPoint
    The NPC's current world tile, or null when unknown.
    boolean
    hasAction(String action)
    Whether the NPC composition exposes this menu action (e.g.
    boolean
    interact(String action)
    Dispatches the NPC menu option named action (exact match first, then the first option containing it, case-insensitive).
    boolean
    True if the NPC is alive (not dead).
    boolean
    True if the NPC is dead (health depleted, death animation playing).
    boolean
    True if the local player is strictly east of this NPC (higher X).
    boolean
    True if the logged-in player's tile is strictly north of this NPC (higher map Y, same plane).
    boolean
    True if the local player is strictly south of this NPC (lower Y).
    boolean
    True if the local player is strictly west of this NPC (lower X).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getNpc

      public net.runelite.api.NPC getNpc()
      The wrapped client NPC (may be null). Raw reads on it are not marshalled.
    • getName

      public String getName()
      The NPC's name with tags stripped, falling back to the transformed composition's name. Empty, never null, when it cannot be read.
    • getIndex

      public int getIndex()
      The NPC's index in the client's NPC array (the menu identifier), or -1 without an NPC.
    • getNpcId

      public int getNpcId()
      Composition id (e.g. for wiki lookups), not the live instance index.
    • getId

      public int getId()
      Alias for getNpcId() — consistent with PrivObject.getId() / PrivItem.getId().
    • hasAction

      public boolean hasAction(String action)
      Whether the NPC composition exposes this menu action (e.g. Talk-to, Attack).
    • isDead

      public boolean isDead()
      True if the NPC is dead (health depleted, death animation playing). Returns false if status cannot be determined.
    • isAlive

      public boolean isAlive()
      True if the NPC is alive (not dead).
    • getInteracting

      public net.runelite.api.Actor getInteracting()
      Returns the actor this NPC is currently interacting with (targeting), or null if not interacting with anyone.
    • exists

      public boolean exists()
      True if this NPC instance is still the live entry at NPC.getIndex().
    • getWorldLocation

      public net.runelite.api.coords.WorldPoint getWorldLocation()
      The NPC's current world tile, or null when unknown.
    • distanceTo

      public double distanceTo(net.runelite.api.coords.WorldPoint p)
      Tile-step distance from this NPC to p. Integer.MAX_VALUE when on different planes, Double.MAX_VALUE when either location is unknown.
    • localPlayerNorthOf

      public boolean localPlayerNorthOf()
      True if the logged-in player's tile is strictly north of this NPC (higher map Y, same plane). See PlayerRelativeToPoint.
    • localPlayerSouthOf

      public boolean localPlayerSouthOf()
      True if the local player is strictly south of this NPC (lower Y).
    • localPlayerWestOf

      public boolean localPlayerWestOf()
      True if the local player is strictly west of this NPC (lower X).
    • localPlayerEastOf

      public boolean localPlayerEastOf()
      True if the local player is strictly east of this NPC (higher X).
    • interact

      public boolean interact(String action)
      Dispatches the NPC menu option named action (exact match first, then the first option containing it, case-insensitive). Marshals onto the client thread when needed.
      Returns:
      true when the action was dispatched, which is not proof it happened: confirm the change (animation, interacting target, dialogue) with a later read. False when the option is not on the NPC's composition, the inputs are missing, or the marshalled call was dropped.
    • attack

      public boolean attack()
      Attacks this NPC using its live Attack menu option.
    • getActions

      public String[] getActions()
      The NPC's live menu actions, tags stripped. Mirrors PrivObject.getActions() so callers can decide which option to click (e.g. Trade vs Shop-with) instead of guessing.
      Returns:
      a defensive copy; never null, empty when the composition is unavailable