Spell05 Card Triggers - Monster-Train-2-Modding-Group/Trainworks-Reloaded GitHub Wiki
← Part 4: Dynamic Scaling Spells | Next: Part 6: Conditionals & Card Pools →
So far, all of our spell cards have executed effects when cast by the player. In this lesson, we explore Card Triggers—effects that trigger automatically when specific conditions occur.
We will create Pyre Sharpener, an unplayable card featuring a Reserve trigger. At the end of each turn, if this card is in your hand, it automatically grants your Pyre +3 Attack. You will learn how to make cards unplayable, adding triggers to a card, and how to target the Pyre.
Download the custom card art:
-
Download Art: Save your card art texture as
PyreSharpener.png. -
Save Location: Save it to your mod project under
textures/PyreSharpener.png.
In Plugin.cs, add "json/spells/PyreSharpener.json" to your AddMergedJsonFile call. Then create json/spells/PyreSharpener.json and add:
{
"$schema": "https://github.com/Monster-Train-2-Modding-Group/Trainworks-Reloaded/releases/latest/download/schema.json",
"cards": [
{
"id": "PyreSharpener",
"cost": 0,
"cost_type": "unplayable",
"names": {
"english": "Pyre Sharpener"
},
"rarity": "common",
"targets_room": false,
"targetless": false,
"class": "ClassBanished",
"card_art": "@PyreSharpenerCardArt",
"traits": [
"@PyreSharpenerUnplayable"
],
"triggers": [
"@BuffThePyreOnUnplayed"
],
"pools": [
"MegaPool"
]
}
],
"traits": [
{
"id": "PyreSharpenerUnplayable",
"name": "CardTraitUnplayable"
}
],
"effects": [
{
"id": "BuffThePyre",
"name": "CardEffectBuffDamage",
"target_mode": "pyre",
"param_int": 3
}
],
"card_triggers": [
{
"id": "BuffThePyreOnUnplayed",
"trigger": "on_unplayed_positive",
"descriptions": {
"english": "Apply +[effect0.power][attack] to your Pyre."
},
"effects": [
"@BuffThePyre"
]
}
],
"game_objects": [
{
"id": "PyreSharpenerCardArt",
"type": "card_art",
"extensions": {
"card_art": {
"sprite": "@PyreSharpenerSprite"
}
}
}
],
"sprites": [
{
"id": "PyreSharpenerSprite",
"path": "textures/PyreSharpener.png"
}
]
}Notice two distinct properties work together to handle unplayability:
-
"cost_type": "unplayable": Hides the Ember cost circle on the card frame. This is visual only and does not mechanically prevent card play. -
"name": "CardTraitUnplayable": The functional trait that forbids the player from playing the card.
Card Triggers exist in their own top-level array alongside traits and effects:
"card_triggers": [
{
"id": "BuffThePyreOnUnplayed",
"trigger": "on_unplayed_positive",
"descriptions": {
"english": "Apply +[effect0.power][attack] to your Pyre."
},
"effects": [
"@BuffThePyre"
]
}
]-
trigger: Defines the card trigger to useReserveactually has two distinct trigger types:-
"on_unplayed_positive": Fires at end of turn; styles the card with positive (green) FX around the card. -
"on_unplayed_negative": Fires at end of turn; styles the card with negative/blight (red) FX around the card.
-
-
descriptions: Card triggers automatically add themselves into the card's description. Because of this, the card does not need adescriptionsfield.-
[effect0.power]: Resolves to theparam_int(3) of the trigger's first effect (effect0->@BuffThePyre). -
[attack]: Replaced with the Attack icon.
-
-
effects: The list of effect IDs that fire when the trigger executes.
"effects": [
{
"id": "BuffThePyre",
"name": "CardEffectBuffDamage",
"target_mode": "pyre",
"param_int": 3
}
]-
name:CardEffectBuffDamageapplies temporary attack buff directly to enemy units or the Pyre. Never use this effect for friendly units as the attack gained will fall off when the monster is defeated use aCardUpgradew/CardEffectAddUpgradeToUnitsinstead. -
target_mode: "pyre": This target mode, targets the pyre itself. You don't need to specifytarget_teamwith this target mode as there is no enemy pyre.
- Build your mod solution and ensure files are copied to
BepInEx/plugins/<YourMod>/. - Launch Monster Train 2 and check the BepInEx console log for clean loading.
- Start a battle with Pyre Sharpener in your deck:
- Confirm the card lacks an Ember cost badge and displays a green Reserve trigger header reading: "Apply +3 Attack to your Pyre."
- Attempt to drag and cast the card: verify that
CardTraitUnplayableprevents it from being played. - End your turn while keeping the card in hand: observe the Reserve trigger fire and confirm your Pyre's attack increases by +3.
Now that you know how to build cards with card triggers, head to the final lesson: Part 6: Conditionals & Card Pools (Hymnist Recruit).