View Tags

May 27, 2015

Tutorial: Making a Telepath Tactics Campaign, Part 19

<< Continued from Part 18

A. Intro to destructible object script triggers

Now it’s time to learn about script triggers you can stick on destructible objects! These triggers are a way for you to turn normal destructible objects into traps, buttons, switches, etc. The way we do this is by attaching a trigger to an object and instructing the trigger to run a script.

The types of triggers are as follows:

  • Pressure – this triggers a script when a character moves onto the object’s space. Needless to say, this is used with traps and pressure plates. Most objects that use this trigger will have a passability of all.
  • Use Once – this presents the player with the Use option when a character is adjacent to the object. If the player presses the Use button, it runs a script. The trigger is then removed so the player can’t use the object over and over again. Good for one-use buttons and lootable objects (like book cases or weapon racks).
  • Use – the same as Use Once, except that there is no limit to how many times the player can use the object. The main candidate for the Use trigger are levers and switches. Because objects with Use triggers can be triggered repeatedly, you’ll need to account for this in the script, most likely by saving a VAL to keep track of its trigger state and using IfValRun to have it run one of two scripts based on whether the switch is “on” or “off.”

There are two ways to attach a trigger to an object; one is to place triggers on particular objects on a map-by-map basis, and the other is to tag an entire class of object so they each get the same trigger automatically.

B. Adding a trigger to a destructible object in a map

We’ll start with attaching a trigger directly to a particular instance of an object within a map. These are placed within the <Unit> XML tag, and follow the format:

<Unit trigger=”Trigger Type,Script Name”>…</Unit>

This, for instance, attaches a Use Once trigger with the Grab Sword script to a weapons rack on the space 7 , 6 within the map:

<Unit trigger=”Use Once,Grab Sword”>0,99,RackSparse,7,6,None,None</Unit>

This trigger will run the Grab Sword script as soon as the player uses the weapons rack. The Grab Sword script, in turn, plays a sound effect, gives the character that used it an Iron Sword, then replaces the weapons rack with a different, visibly empty weapons rack:

<Script>
Grab Sword
<Action>PlaySound/Swoosh Sword2</Action>
<Action>GiveItem/-FNAME-,Iron Sword</Action>
<Action>SpawnFloatingText/Got Iron Sword!,-FNAME-,0xFFFF00,0</Action>
<Action>RemoveCharAt/7,6</Action>
<Action>SpawnChar/99,RackEmpty,7,6,None</Action>
<Action>RemoveTextOverlay</Action>
</Script>

In case you don’t remember, -FNAME- is a special thing we can put in dialogue and script actions; the game substitutes -FNAME- with the full name of whatever character triggered the script. Needless to say, it’s pretty important to make use of this when dealing with triggered scripts! This allows you to have the script attached to a Use trigger that affects different characters based on who used the object.

C. Adding a trigger to every instance of a destructible object

For some objects (like traps), you’ll want to attach a trigger to every instance of that object that spawns throughout the campaign. To do that, we use the Trigger character tag.

The Trigger tag takes the trigger type and script name, delimited with a colon, as its parameter. Here, for instance, is how I tagged the Iron Jaw object in ObjClasses.xml:

<Obj charname=”none” spritetype=”IronJaw” portrait=”” race=”None” sex=”None” classname=”Iron Jaw” move=”all” … pushable=”false” tags=”Trigger,Pressure:Iron Jaw Trap”></Obj>

On all Iron Jaws that spawn, this tag automatically adds a Pressure trigger that then runs the script Iron Jaw Trap whenever a character wanders onto it. Here, in turn, is the script it triggers:

<Script>Iron Jaw Trap
<Action>AddStatusAt/-Y-,-X-,Stunned,AutoAdd</Action>
<Action>AddStatusAt/-Y-,-X-,Slowed,AutoAdd</Action>
<Action>RemoveTriggerObj/-Y-,-X-</Action>
<Action>SpawnParticlesAt/Sparks,-Y-,-X-</Action>
<Action>PlaySound/Swoosh Spear</Action>
<Action>DamageCharAt/-Y-,-X-,10,Pierce</Action>
<Action>SpawnFloatingTextAt/Iron Jaw Trap!,-Y-,-X-,0xFFFF00</Action>
<Action>SpawnFloatingTextAt/Slowed!,-Y-,-X-,0xFFFF00,45</Action>
</Script>

This adds Stunned and Slowed status to the victim; removes the trap (the “TriggerObj”) from the battlefield; spawns spark particles; plays a sound effect; damages the victim; and spawns some floating text to let the player know what just happened.

“But Craig,” you might ask, “what are all those -Y-s and -X-s?” Simple! Just as -FNAME- is a special character that stands in for name of the character that triggers the script, -Y- and -X- stand in for the character’s y and x coordinates. Here, we use this to damage and add status effects to whoever triggers the trap. (Because enemies can set off Pressure triggers, it’s best to accomplish these things without resort to character name, since generic enemies often share the same name.)

One last thing to note: because Iron Jaws can spawn on any map, we have to put the Iron Jaw Trap script in PersistentDialogue.xml. That way, the script will always be accessible when the trap is triggered, no matter which scene it happens in.

 

That’s about all, tactics fans! You now know how to create traps and useable objects by placing triggers. In our next tutorial, we’ll learn how to create new attacks. See you next time!


Continued in Part 20 >>