Templates: Difference between revisions

From Citizens Wiki

No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 11: Line 11:
Make a folder called plugins/Citizens/templates/awesometemplates.  
Make a folder called plugins/Citizens/templates/awesometemplates.  


Inside this, create a .yml file. This can have any file name, and the file name is just for your grouping purposes. The first one is info.yml.
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:
Inside info.yml, put the following template:
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:
Line 22: Line 28:
</pre>
</pre>
}}
}}
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 <pre>/npc create Helpful Guard --templates awesometemplates:towninfo</pre>
Now, we can create an NPC with our desired template using <pre>/npc create NPC --templates awesometemplates:towninfo</pre>
 
You should see a new villager NPC called Town Crier appear that broadcasts the message Hello! every time it spawns.


== Other commands ==
== Other commands ==

Latest revision as of 12:26, 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 NPC --templates awesometemplates:towninfo

You should see a new villager NPC called Town Crier appear that broadcasts the message Hello! every time it spawns.

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.