NPC Commands: Difference between revisions

From Citizens Wiki

No edit summary
(31 intermediate revisions by 2 users not shown)
Line 3: Line 3:
One of the common things Citizens users want is the ability to have NPCs run a command when right-clicked.
One of the common things Citizens users want is the ability to have NPCs run a command when right-clicked.


There is a limited version of this newly available in Citizens via the "/npc command" command. For details, refer to <code>/npc help command</code>.
This is available within Citizens via the "/npc command" command. For details, refer to <code>/npc help command</code>.
 
== Adding Click Commands ==


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


For example: Use <code>/npc command add -p help</code> to make an NPC automatically execute "/help" as the player when clicked.
For example: Use <code>/npc command add -p help</code> to make an NPC automatically execute "/help" as the player when clicked. Note that you don't type the "/" on the command name.


To auto-fill the player name, use "&lt;p&gt;". To autofill the NPC ID, use "&lt;n&gt;".
To auto-fill the player name, use "&lt;p&gt;". To autofill the NPC ID, use "&lt;npc&gt;".


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


== Bungee's /Server ==
As another common example: <code>/npc command add tp &lt;p&gt; 0 64 0</code> to automatically teleport the player that clicked the NPC to some coordinates (assumes the vanilla 'tp' command. If you use Essentials, use 'tppos' instead).
 
Note that this can be any command from minecraft or any plugin, so for example if you use Multiverse, <code>/npc command add mvtp &lt;p&gt; myworldname</code> will use the Multiverse world teleport command.
 
=== Other Placeholders ===
 
Note as well that if you have PlaceholderAPI installed, you can use PAPI placeholders within commands. For example, <code>/npc command add msg &lt;p&gt; The current TPS is %server_tps%</code>.
 
Consult [https://github.com/PlaceholderAPI/PlaceholderAPI/wiki PlaceholderAPI's own documentation] for details on available placeholders or how to format them.
 
=== Requiring Permissions ===
 
By default, anybody can click the NPC to cause a command to execute, without any permission requirement.
 
If <code>-p</code> is used, it will execute as-player, meaning any permissions check '''the command itself''' has will be required for the player.
 
If <code>-o</code> 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 <code>-o</code> will tend to risk side effects or performance problems.
 
Generally, it's best to execute as-server (don't specify <code>-p</code> or <code>-o</code> to use the default as-server), which will not require any permissions. You will need to use <code>&lt;p&gt;</code> to fill in the playername wherever the command requires one.
 
If you want to add your own additional permissions requirement, use <code>--permission my.perm.here</code> 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 <code>/npc text</code> instead), you can do:
<code>/npc command add "npc speak MESSAGE HERE --target &lt;p&gt; --id &lt;id&gt;"</code>
 
This uses the <code>/npc speak</code> command, targeted at the clicking player using <code>--target &lt;p&gt;</code>, speaking from the clicked NPC using <code>--id &lt;id&gt;</code>. The command needs "quotes" around it to prevent misinterpretation of the input arguments. Note that the only part of this you need to fill in yourself is the "MESSAGE HERE" part. The 'p' and 'id' bits should be left exactly as-is.
 
=== Bungee ===
 
On Bungee servers, this supports the Bungee <code>server</code> command, like <code>/npc command add -p server MyServerName</code>. Note that this is a special case built into Citizens internally, and bypasses any normal permission requirements automatically.
 
Note that other bungee-proxy commands (or commands on Velocity or other proxies) will not work. Only commands that can be ran within the confines of the Spigot server instance will function. If you need to execute commands from a Bungee plugin, it is necessary for that plugin to provide a Spigot plugin with interfacing commands of its own, or to use some generic Bungee control relay like [https://github.com/DenizenScript/Depenizen/blob/master/Docs/Bungee.md DepenizenBungee].
 
== Removing Commands ==


The Bungee "/server" command exists at the proxy level, not the Spigot server level. This means that it gets intercepted before the Spigot server ever sees it, and means that it cannot be ran from something on the server (like an NPC).
To remove a command, first type just <code>/npc command</code> to see the list of currently attached commands with ID numbers.


To work around this problem, we have provided a solution in [https://guide.denizenscript.com/guides/background/what-is-denizen.html Denizen]. To use this, first [https://ci.citizensnpcs.co/job/Denizen/ download Denizen here] and add it into your plugins folder. Then, [https://one.denizenscript.com/haste/67017 download the script from here] (via the "download the script" button at the top left) and save it into the folder path "plugins/Denizen/scripts". After you restart your server, you will have the "/sendplayer" command available.
If you have for example a command with ID 0, you can then type <code>/npc command remove 0</code>.


With this, you can do for example <code>/npc command add sendplayer &lt;p&gt; myservernamehere</code> to send any player that clicks the NPC to the Bungee server "myservernamehere".
== Execution Order ==


== Old Method ==
By default, if you add multiple commands with <code>/npc command</code>, they will all run at once.


The old method, which in some cases can still be the better method, is to use Denizen - information for that follows below.
You can instead set them to happen one at a time, either in sequential order, or in random order.


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


Denizen is a scripting engine that directly integrates Citizens to add more features and options to server owners. Learn about Denizen [https://guide.denizenscript.com/guides/background/what-is-denizen.html on the guides here] and download Denizen [https://ci.citizensnpcs.co/job/Denizen/ on the Citizens Jenkins build server here].
To make the commands go in a random order, but still only one at a time, use <code>/npc command random</code>.


=== How To Make a Click Command ===
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 <code>/npc command sequential</code> again to disable it and go back to default).


The standard way to get click-commands set up in Denizen is to write an assignment script with a click action or trigger. There's a [https://guide.denizenscript.com/guides/npcs/assignment-scripts.html guides page explaining how to do this here].
== Other Options ==


=== Easier Denizen-Based Option ===
Other ways you can control <code>/npc command</code> include:


If you'd rather not bother with scripting yourself and instead would prefer to use an in-game command, you can use a premade [https://forum.denizenscript.com/viewtopic.php?f=13&t=149 script available here]. Simply download the script linked in that forum post, save it into "plugins/Denizen/scripts" as a .dsc file, and then use "/ex reload" to load the script. At that point, you can select any NPC and use "/npccommand set [command]" (view the forum post linked previously for additional command usage information).
* <code>/npc command permissions x.y.z</code> to attach temporary permissions to the player (generally don't use this, instead use <code>-o</code> ... or just execute as-server)
* <code>/npc command add -l somethinghere</code> to make the command respond to left clicks (punch/attack). Note that this may not work if PvP is disabled.
* <code>/npc command add -r somethinghere</code> to make the command respond to right clicks (standard interact).
* <code>/npc command add --n 5 somethinghere</code> to make a command only usable a certain number of times per player (in this example, 5 usages).
* <code>/npc command add --cooldown 10 somethinghere</code> to make the command only usable once per certain time period (in this example, 10 seconds), for each player.
* <code>/npc command add --gcooldown 10 somethinghere</code> 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).
* <code>/npc command add --delay 40 somethinghere</code> to make the command have a delay before it activates (in this example, 40 ticks, aka 2 seconds).
* <code>/npc command cost 50</code> 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.
* <code>/npc command expcost 50</code> to make the command have an experience level cost. Works similar to 'cost', but for XP levels.
* <code>/npc command itemcost</code> to open a GUI to configure an item-cost (the player has to give the item for the command to execute).
* <code>/npc command hideErrors</code> to hide all error message (no permission, no money, etc.) from players.


This is more or less equivalent to a slightly more advanced version of the "/npc command" option.
There maybe be more options available for <code>/npc command</code> not yet explained here, so type <code>/npc help command</code> in-game to see any such options.


== Additional Support ==
== Additional Support ==


If confused, join the [https://discord.gg/Q6pZGSR Citizens+Denizen shared Discord] to ask for help!
If confused, join the [https://discord.gg/Q6pZGSR Citizens+Denizen shared Discord] to ask for help!

Revision as of 08:32, 16 February 2022

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. Note that you don't type the "/" on the command name.

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

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

As another common example: /npc command add tp <p> 0 64 0 to automatically teleport the player that clicked the NPC to some coordinates (assumes the vanilla 'tp' command. If you use Essentials, use 'tppos' instead).

Note that this can be any command from minecraft or any plugin, so for example if you use Multiverse, /npc command add mvtp <p> myworldname will use the Multiverse world teleport command.

Other Placeholders

Note as well that if you have PlaceholderAPI installed, you can use PAPI placeholders within commands. For example, /npc command add msg <p> The current TPS is %server_tps%.

Consult PlaceholderAPI's own documentation for details on available placeholders or how to format them.

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 my.perm.here 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. Note that the only part of this you need to fill in yourself is the "MESSAGE HERE" part. The 'p' and 'id' bits should be left exactly as-is.

Bungee

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.

Note that other bungee-proxy commands (or commands on Velocity or other proxies) will not work. Only commands that can be ran within the confines of the Spigot server instance will function. If you need to execute commands from a Bungee plugin, it is necessary for that plugin to provide a Spigot plugin with interfacing commands of its own, or to use some generic Bungee control relay like DepenizenBungee.

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 expcost 50 to make the command have an experience level cost. Works similar to 'cost', but for XP levels.
  • /npc command itemcost to open a GUI to configure an item-cost (the player has to give the item for the command to execute).
  • /npc command hideErrors to hide all error message (no permission, no money, etc.) from players.

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!