NPC Commands

From Citizens Wiki
Revision as of 08:34, 20 April 2021 by Mcmonkey (Talk | contribs) (Other Options)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

NPC Click Commands

One of the common things Citizens users want is the ability to have NPCs run a command when right-clicked.

This is available within Citizens via the "/npc command" command. For details, refer to /npc help command.

Adding Click Commands

By default, "/npc command" will run commands as the server. Use "-p" to run as the player who clicked instead.

For example: Use /npc command add -p help to make an NPC automatically execute "/help" as the player when clicked.

To auto-fill the player name, use "<p>". To autofill the NPC ID, use "<n>".

For example: Use /npc command add kick <p> to make an NPC automatically kick the player when clicked.

Other Placeholders

Note as well that if you have PlaceholderAPI installed, you can use PAPI placeholders within commands.

Requiring Permissions

By default, anybody can click the NPC to cause a command to execute, without any permission requirement.

If -p is used, it will execute as-player, meaning any permissions check the command itself has will be required for the player.

If -o is used, it will execute as-op, meaning the player will be treated as if they were a server operator, and thus usually permissions won't be expected (unless you have a permissions plugin that doesn't respect op, or a protection plugin that disables op). Be warned that -o will tend to risk side effects or performance problems.

Generally, it's best to execute as-server (don't specify -p or -o to use the default as-server), which will not require any permissions. You will need to use <p> to fill in the playername wherever the command requires one.

If you want to add your own additional permissions requirement, use --permission when adding the command.

A Click Command To Speak

To make an NPC command that causes an NPC to speak to the player (if you don't need the full options of the NPC command feature, just use /npc text instead), you can do: /npc command add "npc speak MESSAGE HERE --target <p> --id <id>"

This uses the /npc speak command, targeted at the clicking player using --target <p>, speaking from the clicked NPC using --id <id>. The command needs "quotes" around it to prevent misinterpretation of the input arguments.


On Bungee servers, this supports the Bungee server command, like /npc command add -p server MyServerName. Note that this is a special case built into Citizens internally, and bypasses any normal permission requirements automatically.

Removing Commands

To remove a command, first type just /npc command to see the list of currently attached commands with ID numbers.

If you have for example a command with ID 0, you can then type /npc command remove 0.

Execution Order

By default, if you add multiple commands with /npc command, they will all run at once.

You can instead set them to happen one at a time, either in sequential order, or in random order.

To make the commands go in order, one at a time for each click, use /npc command sequential.

To make the commands go in a random order, but still only one at a time, use /npc command random.

To go back to all-at-once, simply redo whichever command you used to change it (for example if you set it to sequential, just do /npc command sequential again to disable it and go back to default).

Other Options

Other ways you can control /npc command include:

  • /npc command permissions x.y.z to attach temporary permissions to the player (generally don't use this, instead use -o ... or just execute as-server)
  • /npc command add -l somethinghere to make the command respond to left clicks (punch/attack). Note that this may not work if PvP is disabled.
  • /npc command add -r somethinghere to make the command respond to right clicks (standard interact).
  • /npc command add --n 5 somethinghere to make a command only usable a certain number of times per player (in this example, 5 usages).
  • /npc command add --cooldown 10 somethinghere to make the command only usable once per certain time period (in this example, 10 seconds), for each player.
  • /npc command add --gcooldown 10 somethinghere to make the command only usable once per certain time period (in this example, 10 seconds), globally (nobody can use the NPC again until the cooldown ends).
  • /npc command add --delay 40 somethinghere to make the command have a delay before it activates (in this example, 40 ticks, aka 2 seconds).
  • /npc command cost 50 to make the command have a cost using any Vault-compatible economy plugin (in this example, $50). This will refuse to run for players that don't have enough money, and automatically take the money before executing the command for those that do have enough.
  • /npc command itemcost to open a GUI to configure an item-cost (the player has to give the item for the command to execute).

There maybe be more options available for /npc command not yet explained here, so type /npc help command in-game to see any such options.

Additional Support

If confused, join the Citizens+Denizen shared Discord to ask for help!