Class PrivNPC
java.lang.Object
privbot.wrappers.PrivNPC
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 TypeMethodDescriptionbooleanattack()Attacks this NPC using its liveAttackmenu option.doubledistanceTo(net.runelite.api.coords.WorldPoint p) Tile-step distance from this NPC top.booleanexists()True if this NPC instance is still the live entry atNPC.getIndex().String[]The NPC's live menu actions, tags stripped.intgetId()intgetIndex()The NPC's index in the client's NPC array (the menu identifier), or -1 without an NPC.net.runelite.api.ActorReturns the actor this NPC is currently interacting with (targeting), or null if not interacting with anyone.getName()The NPC's name with tags stripped, falling back to the transformed composition's name.net.runelite.api.NPCgetNpc()The wrapped client NPC (may be null).intgetNpcId()Composition id (e.g.net.runelite.api.coords.WorldPointThe NPC's current world tile, or null when unknown.booleanWhether the NPC composition exposes this menu action (e.g.booleanDispatches the NPC menu option namedaction(exact match first, then the first option containing it, case-insensitive).booleanisAlive()True if the NPC is alive (not dead).booleanisDead()True if the NPC is dead (health depleted, death animation playing).booleanTrue if the local player is strictly east of this NPC (higher X).booleanTrue if the logged-in player's tile is strictly north of this NPC (higher map Y, same plane).booleanTrue if the local player is strictly south of this NPC (lower Y).booleanTrue if the local player is strictly west of this NPC (lower X).
-
Method Details
-
getNpc
public net.runelite.api.NPC getNpc()The wrapped client NPC (may be null). Raw reads on it are not marshalled. -
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() -
hasAction
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 atNPC.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 top.Integer.MAX_VALUEwhen on different planes,Double.MAX_VALUEwhen 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). SeePlayerRelativeToPoint. -
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
Dispatches the NPC menu option namedaction(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 liveAttackmenu option. -
getActions
The NPC's live menu actions, tags stripped. MirrorsPrivObject.getActions()so callers can decide which option to click (e.g.TradevsShop-with) instead of guessing.- Returns:
- a defensive copy; never null, empty when the composition is unavailable
-