-
-
Notifications
You must be signed in to change notification settings - Fork 150
GH-511: NPC Instruction Component Guide #529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LordZibblington
wants to merge
1
commit into
HytaleModding:main
Choose a base branch
from
LordZibblington:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
content/docs/en/guides/npc-workings/npc-instruction-component-assets.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,121 @@ | ||||||
| --- | ||||||
| title: "NPCs: Instruction Component assets" | ||||||
| description: "Use Instruction Component assets to clean up your NPC and cut back on repetition." | ||||||
| authors: | ||||||
| - name: "Lord Zibblington" | ||||||
| --- | ||||||
|
|
||||||
| Introduction | ||||||
| In this guide we’ll walk through the process of using Instruction Component asset files, referred to as Instructions (capital I) going forward. Instructions allow you to use the same sensor/action pairing across many NPCs, which is extremely useful if you’re going to be reusing the same action a lot. They also allow you to decrease the bulk of your NPC Role files, which makes them much easier to read and digest going forward. | ||||||
|
|
||||||
| Creating the Instruction | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| This is an Instruction. It has a Class field, a Type field, a Parameters field, and a Content field. Below is a bare bones representation of the structure. | ||||||
|
|
||||||
| ``` | ||||||
| "Class": "Instruction", | ||||||
| "Type": "Component", | ||||||
| "Parameters": { | ||||||
|
|
||||||
| }, | ||||||
| "Content":{ | ||||||
|
|
||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| As it stands, this Instruction won’t run. On that note, always make sure you remove any invalid Instructions from your asset packs. Unlike other assets, where the game will ignore them and move on, your entire asset pack will be rejected due to a broken Instruction even if you never reference that file. The game will give an error with the name of your asset in the log, so it’s a good idea to check it first if your mod pack isn’t loading. | ||||||
|
|
||||||
| Instructions are comprised of four parts: Class, Type, Parameters, and Content. Class and Type are what let the game know this is an Instruction to be used for your NPC. We won’t be touching either of these fields in this tutorial. Parameters are where you define the customization settings of your Instruction. If it’s not in here, it can’t be changed. Finally, Content is where the magic happens. This is where you’ll put all of your Actions to be used later by your NPCs. | ||||||
|
|
||||||
| Parameters are comprised of two parts: The value, and the description. Both are necessary for the initial parameter declaration. | ||||||
|
|
||||||
| ``` | ||||||
| "Parameters":{ | ||||||
| "Example_Parameter_One":{ | ||||||
| "Value": 1, | ||||||
| "Description": "An example of storing a number with a parameter" | ||||||
| }, | ||||||
| "Example_Parameter_Two":{ | ||||||
| "Value": "Hello World", | ||||||
| "Description": "An example of storing a string with a parameter" | ||||||
| }, | ||||||
| "Example_Parameter_Three":{ | ||||||
| "Value": [ 1 , 7 , 9 ], | ||||||
| "Description": "An example of storing an array with a parameter" | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| The fields are self-explanatory, with the Value field stating what the parameter holds and the Description field describing the parameter. | ||||||
|
|
||||||
|
|
||||||
| Content is what tells the game what you want the Instruction to do, and when you want it to do it. You need a Sensor and Actions field, the same as when you outline your instructions in a normal NPC Role asset. | ||||||
|
|
||||||
|
|
||||||
| ``` | ||||||
| "Content":{ | ||||||
| "Sensor":{ | ||||||
| "Type": "Player", | ||||||
| "Range": "Compute": "Example_Parameter_One" | ||||||
| }, | ||||||
| Actions:[ | ||||||
| { | ||||||
| "Type": "Spawn", | ||||||
| "Kind": "Gecko", | ||||||
| "LaunchAtTarget": true | ||||||
| }, | ||||||
| ] | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| The Content field shown here will tell the game to launch a Gecko at the player when they get as close as defined in Example_Parameter_One. It’s important that you use Compute and pass a parameter value if you want someone to have the ability to adjust part of the instruction every time they call it. | ||||||
|
|
||||||
| Content is different from Actions and Instructions fields found in a normal NPC Role in that it is not an array. You cannot, to my knowledge, have multiple Sensor/Action pairings within the first level of the content section, and using square brackets will break it entirely. | ||||||
|
|
||||||
| BAD: | ||||||
| ``` | ||||||
| Content: [ | ||||||
| { | ||||||
| Sensor:{ | ||||||
|
|
||||||
| }, | ||||||
| Actions:[ | ||||||
| { | ||||||
|
|
||||||
| } | ||||||
| ] | ||||||
| } | ||||||
| ] | ||||||
| ``` | ||||||
|
|
||||||
| GOOD: | ||||||
| ``` | ||||||
| Content: { | ||||||
| Sensor:{ | ||||||
|
|
||||||
| }, | ||||||
| Actions:[ | ||||||
| { | ||||||
|
|
||||||
| } | ||||||
| ] | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| Calling the Instruction | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| To call your Instruction, you want it to place it inside an Instructions field like you would any Sensor/Actions pairing. You’re going to use the Reference and Modify fields instead of the usual Sensor and Actions fields, but otherwise it’s the same. Reference tells the game which file to use, and Modify allows you to customize the parameters inside this specific instance of your Instructions asset. | ||||||
|
|
||||||
| ``` | ||||||
| "Instructions": [ | ||||||
| { | ||||||
| "Reference": "Example_Instruction", | ||||||
| "Modify": { | ||||||
| "Example_Parameter_One": 20 | ||||||
| } | ||||||
| } | ||||||
| ] | ||||||
| ``` | ||||||
|
|
||||||
| If the Instruction has more parameters than you want to adjust, or if you want to run the Instruction exactly as is, fear not! You only need to include what you’re going to use and you can leave out the rest, even the Modify field! Hytale’s engine (or json in general?) is great because if you don’t need a field from an Instruction you can just leave it out. | ||||||
|
|
||||||
| That’s it for this guide. Now you should be able to confidently use Instructions to simplify your NPC assets and remove redundancy. Don’t forget that an invalid instruction stops the entire asset pack, and have fun being efficient! | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.