Templates: Difference between revisions
No edit summary |
|||
Line 17: | Line 17: | ||
{{codebox|height=200px|width=98%||<pre lang="yaml"> | {{codebox|height=200px|width=98%||<pre lang="yaml"> | ||
towninfo: | towninfo: | ||
yaml_replace: | |||
replacements: | |||
name: Town Crier | |||
traits: | |||
type: VILLAGER | |||
override: true | |||
commands: | commands: | ||
on_spawn: | on_spawn: |
Revision as of 12:25, 5 January 2025
Templates are a simple way to share NPC configuration across NPCs and servers.
Layout
Templates are stored in the plugins/Citizens/templates folder.
Each template consists of a namespace or a folder to group related templates together and a bunch of template files.
Example
Let's build a quick example.
Make a folder called plugins/Citizens/templates/awesometemplates.
Inside this, create a .yml file. This can have any file name - the file name is just for helping you organise complicated templates. Let's call the first one info.yml.
Inside info.yml, put the following template:
Code: |
towninfo:
yaml_replace:
replacements:
name: Town Crier
traits:
type: VILLAGER
override: true
commands:
on_spawn:
- say Hello!
|
This creates a template with the namespace awesometemplates and the template name towninfo. We can reference this in game with the combined key awesometemplates:towninfo or by just the template name towninfo. If there could be duplicate template names in different namespaces, then use the full reference.
Now, we can create an NPC with our desired template using
/npc create Helpful Guard --templates awesometemplates:towninfo
Other commands
You can generate a copy of another NPC's save data directly using for example /template generate awesometemplates:towninfocopy. This will save it into a file called towninfocopy.yml.
You can apply a template to an existing NPC by using /template apply awesometemplates:towninfo.