Class NPCPackets


  • public class NPCPackets
    extends java.lang.Object
    A static utility class for sending packets related to Non-Player Character (NPC) interactions to the game server.

    This class handles various forms of NPC interaction, including standard action clicks (e.g., Talk-to, Attack) and "use-with" actions (e.g., using an item on an NPC). It uses a PacketDefFactory to determine the correct packet type and a PacketClient to send the raw data.

    • Constructor Summary

      Constructors 
      Constructor Description
      NPCPackets()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void queueNPCAction​(int actionFieldNo, int npcIndex, boolean ctrlDown)
      Queues the low-level packet to perform a generic action click on an NPC.
      void queueNPCAction​(net.runelite.api.NPC npc, java.lang.String... actionList)
      Queues an NPC action by matching a human-readable action string (e.g., "Talk-to", "Attack").
      void queueWidgetOnNPC​(int npcIndex, int sourceItemId, int sourceSlot, int sourceWidgetId, boolean ctrlDown)
      Queues the raw packet for using a widget (typically an item) on an NPC.
      void queueWidgetOnNPC​(net.runelite.api.NPC npc, net.runelite.api.widgets.Widget widget)
      Queues the packet for using a specific Widget (or item it represents) on a target NPC.
      • Methods inherited from class java.lang.Object

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

      • NPCPackets

        public NPCPackets()
    • Method Detail

      • queueNPCAction

        public void queueNPCAction​(int actionFieldNo,
                                   int npcIndex,
                                   boolean ctrlDown)
        Queues the low-level packet to perform a generic action click on an NPC.

        This method sends one of the OPNPC packets (e.g., OPNPC1 through OPNPC10), where the action is determined by the actionFieldNo.

        Parameters:
        actionFieldNo - The 1-based index of the action to execute (1-10).
        npcIndex - The server index of the target NPC.
        ctrlDown - If true, indicates the control key was held down (often used for force-attacking/force-clicking).
      • queueNPCAction

        public void queueNPCAction​(net.runelite.api.NPC npc,
                                   java.lang.String... actionList)
        Queues an NPC action by matching a human-readable action string (e.g., "Talk-to", "Attack").

        This is a high-level convenience method that inspects the target NPC's composition for a matching action and automatically determines the correct low-level action number (1-10) to use for the OPNPC packet. The search is case-insensitive.

        Parameters:
        npc - The target NPC object to interact with.
        actionList - A varargs list of action strings to search for. The first match found will be executed.
      • queueWidgetOnNPC

        public void queueWidgetOnNPC​(int npcIndex,
                                     int sourceItemId,
                                     int sourceSlot,
                                     int sourceWidgetId,
                                     boolean ctrlDown)
        Queues the raw packet for using a widget (typically an item) on an NPC.

        This method sends the OPNPCT (Use Widget on NPC) packet, which contains the details of the source item/widget and the target NPC.

        Parameters:
        npcIndex - The server index of the target NPC.
        sourceItemId - The ID of the item being used.
        sourceSlot - The slot index of the item being used (e.g., inventory slot).
        sourceWidgetId - The ID of the parent widget containing the item (e.g., inventory widget ID).
        ctrlDown - If true, indicates the control key was held down.
      • queueWidgetOnNPC

        public void queueWidgetOnNPC​(net.runelite.api.NPC npc,
                                     net.runelite.api.widgets.Widget widget)
        Queues the packet for using a specific Widget (or item it represents) on a target NPC.

        This is a convenience method that extracts the necessary item and widget details from the provided Widget object and calls the raw queueWidgetOnNPC method.

        Parameters:
        npc - The target NPC object.
        widget - The source Widget containing the item or action to be used on the NPC.