Adding New Behaviour - Kizari/Flagrum GitHub Wiki

Introduction

This is the most exciting prospect of script editing, the ability to add your own behaviour to the game.

For this example, we'll use the same example from the old manual script editing guide, but do it 10x easier in Lucent. If you're not familiar with that guide, the example involved triggering the flying armiger mode from the Leviathan fight when the player is done interacting with a chocobo rental machine. We'll put a slight spin on it though, it'll only toggle if the player spends gil at the machine. If you still have Lucent open from the previous section, save the project and close Lucent. You can then relaunch Lucent and begin a new project.

Once you have created a new project, import the following script:

data/menu/chocobo_menu/script/menuswfentry_chocoborental.xml

You should get something like this. Note that I have double-clicked to open the tray this time instead of the sequence container. This is because the sequence container contains nothing except the tray and so isn't useful for adding logic to.

Chocobo Menu
 

Adding the Behaviour

As explained in the original guide, the method for activating the flying armiger mode was discovered by observing the node graph from the Leviathan fight. Fortunately, reading such graphs is much easier these days with Lucent—although it can still be beneficial to search for keywords using the method shown in the first guide in this series if you are unsure which entity package to import into Lucent to start studying.

The method involves setting Noctis' status to Knights of Eos, which is the codename for the flying armiger mode in the game's code. To do this, use the SequenceActionActorSetStatusInt node is used. You can search for this in the Toolbox panel on the right side of Lucent, and double-click it to add it to the node graph. It'll appear in the centre of the screen, so just drag it to where you want it. Since we know we want it to occur after the menu is closed, now would be a good time to drag it to the end and connect it. You'll notice that at the end of the graph there is an arrow exiting the Wait node's Finished pin into the CloseMenu pin on the Menu Logic node. Let's also drag another arrow off the Finished pin so that our new node is triggered at the same time. We also know that this control flow only activates if the player spends gil, because the only control flow that leads here comes from the Success pin of the SequenceActionActorUseGil node.

New Node

There are multiple ways to handle this now. Thinking back to the second guide, it may seem obvious to use am ActorObjectVariable node and connect it to the Actor pin of this new node. That would work just fine, but there's an easier way. Click the new node, and you can simply change the Target dropdown to TARGET_PLAYER_NOCTIS instead. When no pin is connected, the node will fallback onto this value, and so we simply leave it unconnected so it will always target Noctis. It's worth noting that this status won't work for any other character, so there's no benefit to setting it to a different character.

Next we need to choose which status to apply. As mentioned, we need to use Knights of Eos. Simply select STATUS_KNIGHTS_OF_EOS from the Kind dropdown in the inspector to do so.

Finally, we need to set the value. You could simply type 1 in the Value property in the inspector, but what if Knights of Eos is already active? Now you're stuck in this mode indefinitely! Perhaps it would be better to make this a toggle instead. This is where the power of nodes comes in to help script this behaviour. What we need to do is find out what this value already is (0 for off, 1 for on), and then change it to the opposite. Well that's simple enough, grab a SequenceActionActorGetStatusInt node from the toolbox and give it the same Target and Kind as the node we just created.

Get Status

We can use some very simple math here to toggle the value. Take the following formula:

x = 1 - x

If x is 1, our formula will give x = 1 - 1 or 0.
If x is 0, our formula will give x = 1 - 0 or 1.

We can represent this formula with nodes!

For this, we'll grab some more nodes from the toolbox. These are SequenceOperatorSubtract to handle the subtraction, and int constant to provide the value for 1.

Warning

Make sure to select the int constant node after adding it to the graph and change the Value in the inspector from 0 to 1.

Formula

It is important that you plug these two nodes into the correct pins on the subtract node. In2 will be subtracted from In1 as shown in the picture above. The result of the equation can be retrieved from the Out pin of the subtract node, so this will be connected to the Int pin of SequenceActionActorSetStatusInt to give it the toggled value. The Out pin from SequenceActionActorGetStatusInt is also connected to the In pin of SequenceActionActorSetStatusInt to complete the sequence. The control flow is executed in this order as we need to get the current value before we can can calculate the toggled value and set it. Here's how it looks when it's all put together.

Final
 

Conclusion

As with the previous guide, you can now export your mod and test it in game.

There are countless combinations of nodes, and very many different things you can achieve with this tool. Unfortunately, a lot of these things are yet to be discovered, so the best way to continue from here is to take this knowledge/process, and study the numerous scripts that shipped with the game to understand how Square Enix achieved the functionality that they did.

Congratulations on finishing this guide, and happy modding!
 


< Previous: Removing Existing Behaviour

⚠️ **GitHub.com Fallback** ⚠️