Line 7: |
Line 7: |
| ==Overview== | | ==Overview== |
| ===Introduction=== | | ===Introduction=== |
− | Each trigger action is comprised of three main parts:
| + | A ''trigger action'' consists of two main parts: |
− | * The '''trigger''' is when to apply the trigger action, either defined by the base game (like <samp>LocationChanged</samp>) or added by C# mods. | + | * The ''trigger'' is what causes the action to happen. This can be an entry in <samp>Data/TriggerActions</samp>, an event command, etc. See [[#Triggers|built-in triggers]]. |
− | * '''Actions''' are what to do (like send mail or start a quest). | + | * The ''action'' is a space-delimited string which defines what to do. For example, <code>AddMail Current Robin</code> adds the <samp>Robin</samp> letter to the player's [[Modding:Mail data|mailbox]] tomorrow. See [[#Argument format|argument format]] and [[#Actions|built-in actions]]. |
− | * '''Conditions''' are optional [[Modding:Game state queries|game state queries]] to decide whether the trigger action should be applied.
| |
| | | |
− | For example, consider this [[Modding:Content Patcher|Content Patcher]] patch:
| + | ===Argument format=== |
− | {{#tag:syntaxhighlight|<nowiki>
| + | Arguments are space-delimited. For example, <code>AddMail Current Abigail_LeoMoved Now</code> calls the <samp>AddMail</samp> action with three arguments (player: <samp>Current</samp>, mail ID: <samp>Abigail_LeoMoved</samp>, and mail type: <samp>Now</samp>). |
− | {
| |
− | "Format": "</nowiki>{{Content Patcher version}}<nowiki>",
| |
− | "Changes": [
| |
− | {
| |
− | "Action": "EditData",
| |
− | "Target": "Data/TriggerActions",
| |
− | "Entries": {
| |
− | "SomeMod.Id_OnLeoMoved": {
| |
− | "Id": "SomeMod.Id_OnLeoMoved",
| |
− | "Trigger": "DayEnding",
| |
− | "Condition": "PLAYER_HAS_FLAG Host leoMoved",
| |
− | "Actions": [
| |
− | "AddMail Current Abigail_LeoMoved",
| |
− | "AddConversationTopic LeoMoved 5"
| |
− | ]
| |
− | }
| |
− | }
| |
− | }
| |
− | ]
| |
− | }
| |
− | </nowiki>|lang=js}}
| |
− | | |
− | You can read that like: "''When the player is going to sleep, if Leo has moved to the valley, then [[Modding:Mail data|send a letter]] and start [[Modding:Dialogue#Conversation topics|a conversation topic]]''".
| |
− | | |
− | Actions only run once by default, though you can use the <samp>MarkActionApplied</samp> action to re-enable one.
| |
− | | |
− | ===Action format=== | |
− | An ''action'' consists of an action name with space-delimited arguments. For example, <code>AddMail Current Abigail_LeoMoved Now</code> has action name <samp>AddMail</samp> with three arguments (<samp>Current</samp>, <samp>Abigail_LeoMoved</samp>, and <samp>Now</samp>).
| |
| | | |
| If you have spaces within an argument, you can surround it with quotes to keep it together. For example, <code>AddFriendshipPoints "Mister Qi" 10</code> has two arguments (<samp>Mister Qi</samp> and <samp>10</samp>). You can escape inner quotes with backslashes, like <code>AddFriendshipPoints "Mister \"Qi\"" 10</code>. | | If you have spaces within an argument, you can surround it with quotes to keep it together. For example, <code>AddFriendshipPoints "Mister Qi" 10</code> has two arguments (<samp>Mister Qi</samp> and <samp>10</samp>). You can escape inner quotes with backslashes, like <code>AddFriendshipPoints "Mister \"Qi\"" 10</code>. |
Line 47: |
Line 18: |
| Remember that quotes and backslashes inside JSON strings need to be escaped too. For example, <code>"AddFriendshipPoints \"Mister Qi\" 10"</code> will send <code>AddFriendshipPoints "Mister Qi" 10</code> to the game code. Alternatively, you can use single-quotes for the JSON string instead, like <code>'AddFriendshipPoints "Mister Qi" 10'</code>. | | Remember that quotes and backslashes inside JSON strings need to be escaped too. For example, <code>"AddFriendshipPoints \"Mister Qi\" 10"</code> will send <code>AddFriendshipPoints "Mister Qi" 10</code> to the game code. Alternatively, you can use single-quotes for the JSON string instead, like <code>'AddFriendshipPoints "Mister Qi" 10'</code>. |
| | | |
− | ==Data format== | + | ==Actions== |
− | Trigger actions are stored in the <samp>Data/TriggerActions</samp> asset. This consists of a list of models with these fields:
| + | ===Built-in actions=== |
− | | + | These are the built-in actions which can be used by any [[#Triggers|trigger]]. (Other custom actions may be [[#For C# mod authors|added by C# mods]].) |
− | {| class="wikitable"
| |
− | |-
| |
− | ! field
| |
− | ! effect
| |
− | |-
| |
− | | <samp>Id</samp>
| |
− | | The [[Modding:Modder Guide/Game Fundamentals#Unique string IDs|unique string ID]] for this trigger action.
| |
− | |-
| |
− | | <samp>Trigger</samp>
| |
− | | When to apply the trigger action. This must be one or more [[#Triggers|valid trigger types]] (space-delimited).
| |
− | |-
| |
− | | <samp>Actions</samp>
| |
− | | ''(Optional)'' The actions to perform, as a list of strings matching the [[#Actions|action format]].
| |
− | |-
| |
− | | <samp>Action</samp>
| |
− | | ''(Optional)'' A single action to perform, matching the [[#Actions|action format]].
| |
− | | |
− | This is just a shortcut for <samp>Actions</samp> with one action. Technically you can use both together, but usually you should just pick one property to set.
| |
− | |-
| |
− | | <samp>Location</samp>
| |
− | | ''(Optional)'' If set, the internal location name where this action should be applied. This is a shortcut for (and more efficient than) using a <samp>LOCATION_NAME</samp> game state query. Default none.
| |
− | |-
| |
− | | <samp>HostOnly</samp>
| |
− | | ''(Optional)'' Whether this trigger action can only run for the main player. If true, the action will be ignored for farmhands in [[multiplayer]].
| |
− | |-
| |
− | | <samp>Condition</samp>
| |
− | | ''(Optional)'' A [[Modding:Game state queries|game state query]] which indicates whether this action can be applied currently. Defaults to always true.
| |
− | |-
| |
− | | <samp>CustomFields</samp>
| |
− | | ''(Optional)'' The [[Modding:Migrate to Stardew Valley 1.6#Custom data fields|custom fields]] for this entry.
| |
− | |}
| |
− | | |
− | See [[#Overview|example under ''Overview'']].
| |
− | | |
− | ==Valid values==
| |
− | ===Triggers=== | |
− | The game has three built-in triggers which can be used in the <samp>Trigger</samp> field. (Other custom triggers may be [[#For C# mod authors|added by C# mods]].)
| |
− | | |
− | {| class="wikitable"
| |
− | |-
| |
− | ! trigger
| |
− | ! effect
| |
− | |-
| |
− | | <samp>DayStarted</samp>
| |
− | | Raised when the player starts a day, after either sleeping or loading.
| |
− | |-
| |
− | | <samp>DayEnding</samp>
| |
− | | Raised when the player is going to sleep. This happens immediately before the game changes the date, sets up the new day, and saves.
| |
− | |-
| |
− | | <samp>LocationChanged</samp>
| |
− | | Raised when the player arrives in a location.
| |
− | |}
| |
− | | |
− | ===Actions===
| |
− | These are the built-in actions which can be used in the <samp>Actions</samp> field. (Other custom actions may be [[#For C# mod authors|added by C# mods]].)
| |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 194: |
Line 110: |
| | Apply to the main player. | | | Apply to the main player. |
| |} | | |} |
| + | |
| + | ==Triggers== |
| + | ===<samp>Data/TriggerActions</samp>=== |
| + | <samp>Data/TriggerActions</samp> is a data asset which lets you dynamically perform actions when the conditions are met. |
| + | |
| + | For example, consider this [[Modding:Content Patcher|Content Patcher]] patch: |
| + | {{#tag:syntaxhighlight|<nowiki> |
| + | { |
| + | "Format": "</nowiki>{{Content Patcher version}}<nowiki>", |
| + | "Changes": [ |
| + | { |
| + | "Action": "EditData", |
| + | "Target": "Data/TriggerActions", |
| + | "Entries": { |
| + | "{{ModId}}_OnLeoMoved": { |
| + | "Id": "{{ModId}}_OnLeoMoved", |
| + | "Trigger": "DayEnding", |
| + | "Condition": "PLAYER_HAS_MAIL Host leoMoved", |
| + | "Actions": [ |
| + | "AddMail Current {{ModId}}_Abigail_LeoMoved", |
| + | "AddConversationTopic {{ModId}}_LeoMoved 5" |
| + | ] |
| + | } |
| + | } |
| + | } |
| + | ] |
| + | } |
| + | </nowiki>|lang=js}} |
| + | |
| + | You can read that like: "''When the player is going to sleep, if Leo has moved to the valley, then [[Modding:Mail data|send a letter]] and start [[Modding:Dialogue#Conversation topics|a conversation topic]]''". |
| + | |
| + | Each entry in <samp>Data/TriggerActions</samp> only runs once by default, though you can use the <samp>MarkActionApplied</samp> action to re-enable one. |
| + | |
| + | <samp>Data/TriggerActions</samp> consists of a list of models with these fields: |
| + | |
| + | {| class="wikitable" |
| + | |- |
| + | ! field |
| + | ! effect |
| + | |- |
| + | | <samp>Id</samp> |
| + | | The [[Modding:Modder Guide/Game Fundamentals#Unique string IDs|unique string ID]] for this trigger action. |
| + | |- |
| + | | <samp>Trigger</samp> |
| + | | When to apply the trigger action. This must be one or more of these values (space-delimited): |
| + | |
| + | {| class="wikitable" |
| + | |- |
| + | ! trigger |
| + | ! effect |
| + | |- |
| + | | <samp>DayStarted</samp> |
| + | | Raised when the player starts a day, after either sleeping or loading. |
| + | |- |
| + | | <samp>DayEnding</samp> |
| + | | Raised when the player is going to sleep. This happens immediately before the game changes the date, sets up the new day, and saves. |
| + | |- |
| + | | <samp>LocationChanged</samp> |
| + | | Raised when the player arrives in a location. |
| + | |- |
| + | | ''other'' |
| + | | Other custom triggers may be [[#For C# mod authors|added by C# mods]]. |
| + | |} |
| + | |- |
| + | | <samp>Actions</samp> |
| + | | ''(Optional)'' The actions to perform, as a list of strings matching the [[#Actions|action format]]. |
| + | |- |
| + | | <samp>Action</samp> |
| + | | ''(Optional)'' A single action to perform, matching the [[#Actions|action format]]. |
| + | |
| + | This is just a shortcut for <samp>Actions</samp> with one action. Technically you can use both together, but usually you should just pick one property to set. |
| + | |- |
| + | | <samp>Location</samp> |
| + | | ''(Optional)'' If set, the internal location name where this action should be applied. This is a shortcut for (and more efficient than) using a <samp>LOCATION_NAME</samp> game state query. Default none. |
| + | |- |
| + | | <samp>HostOnly</samp> |
| + | | ''(Optional)'' Whether this trigger action can only run for the main player. If true, the action will be ignored for farmhands in [[multiplayer]]. |
| + | |- |
| + | | <samp>Condition</samp> |
| + | | ''(Optional)'' A [[Modding:Game state queries|game state query]] which indicates whether this action can be applied currently. Defaults to always true. |
| + | |- |
| + | | <samp>CustomFields</samp> |
| + | | ''(Optional)'' The [[Modding:Migrate to Stardew Valley 1.6#Custom data fields|custom fields]] for this entry. |
| + | |} |
| + | |
| + | See [[#Overview|example under ''Overview'']]. |
| + | |
| + | ===Elsewhere=== |
| + | You can also run an action directly from... |
| + | |
| + | <ul> |
| + | <li>A [[Modding:Dialogue|dialogue string]] using the <samp>$action</samp> command. For example: |
| + | <syntaxhighlight lang="js"> |
| + | "Mon": "Hi there! Here's 10g, don't spend it all once.#$action AddMoney 10" |
| + | </syntaxhighlight></li> |
| + | |
| + | <li>An [[Modding:Event data|event script]] using the <samp>action</samp> command. For example: |
| + | <syntaxhighlight lang="js"> |
| + | "{{ModId}}_Event": "continue/64 15/farmer 64 16 2 Abigail 64 18 0/pause 1500/speak Abigail \"Hi. Here's 10g.\"/action AddMoney 10/pause 500/end" |
| + | </syntaxhighlight></li> |
| + | |
| + | <li>A [[Modding:Mail data|mail letter]] using the <samp>%action</samp> command. For example: |
| + | <syntaxhighlight lang="js"> |
| + | "{{ModId}}_Letter": "Hey there!^Here's 10g. Take care!^ -Abigail%action AddMoney 10%%[#]A gift from Abigail" |
| + | </syntaxhighlight></li> |
| + | |
| + | <li>The [[Modding:Console commands|SMAPI console window]] using the <samp>debug action</samp> console command. For example: |
| + | <pre>> debug action AddMoney 10 |
| + | |
| + | Applied action 'AddMoney 10'.</pre></li> |
| + | </ul> |
| | | |
| ==For C# mod authors== | | ==For C# mod authors== |