I’ve decided to start an FE8 eventing tutorial series based on prompts given. I will carefully go over each line of event code written to (hopefully) help you understand what exactly is happening within the event. For the first prompt, say we have a spooky dark mage bro and we want his death to trigger the deaths of all his monster minion buddies.
First, we define a handy macro that allows us to manually kill a unit by their ID.
#define Kill(unitid) "SET_SOMETHING unitid; DISA_IF unitid"
When we use this, it will kill the unit with the given id.
We want to make sure the dark mage guy and his minions have their own IDs. The minions can all share an ID, or use multiple IDs, as long as they aren’t used by anyone else. I will use the same ID for all the minions here.
We know we want something to occur after a specific unit dies. To do this, we need to set up an eID in their death quote for the chapter. This way, the eID is set to True when they die. For our example, I’ll use the eID 0x10 for their death quote. You can set this in the Death Quotes Table.
Now, we know the eID 0x10 will be true once our dark mage bro dies. But how can we use this to cause an event to occur? This is where AFEV, or after event, comes in. AFEVs will trigger immediately after their associated eID is set to true. We put them under MiscBasedEvents. The format is:
AFEV eID EventLabel eID2
Where the first eID is set to true after it’s completion, and the second eID is the one being “watched”.
Since we are using eID 0x10 for our dark mage’s death, we write it as
AFEV 0x11 KillMinions 0x10
And now we just have to define what KillMinions will do. We want to kill all of the minions, so this is where having them all be the same ID comes into play. When we use our Kill(unitid) macro, it will kill the first unit with that ID. However, we can actually take advantage of this by looping the event to keep killing units of that id until none are left.
KillMinions: LABEL 1 CHECK_EXISTS Minion BEQ 0x2 0xC 0x0 Kill(Minion) GOTO 1 LABEL 2 NoFade ENDA
So what’s going on here? Well, first, we should comment the code to make it more readable.
KillMinions: LABEL 1 CHECK_EXISTS Minion // 0xC = minion exist state (1 if exists, 0 otherwise) BEQ 0x2 0xC 0x0 // if 0xC = 0x0 (if minion does not exist) branch to label 2 // else (if minion exists) Kill(Minion) GOTO 1 //loop event LABEL 2 // if minion does not exist NoFade ENDA
This should help us understand a bit better. First, we have LABEL 1. Why? Well, we want the event to loop until all the minions are dead, so we need a LABEL at the start to be able to loop. Next, we check if any minion exists. If they do, SVAL 0xC will be 0x1. If not, it’ll be 0x0. As per programming customs, we can think of 1 as being true and 0 as being false. But why SVAL 0xC? 0xC is a special case, since all CHECK statements write their results here. Think of it like the C is for CHECK. Next is our branch - these can seem tricky, but they’re simple if you know what’s happeneing! Here, we compare 0xC and 0x0 with an equals statement. SVAL 0x0 is a special case that is always equal to 0, so we can think of this as checking if 0xC = 0. As we stated above, 0 is false, so we are checking to see if no minions exist, since 0xC is currently equal to the existance state of the minions. When a branch statement is true, we branch to the associated LABEL - in this case, 2. We can see LABEL 2 is at the end of the event, so what exactly is happening? What is happeneing is that if no minions are left, we branch to the end of the event. If there are no minions left to kill, then the event has completed - makes sense? The part between a branch and it’s associated LABEL only occurs if the condition is not met. In this case, this bit will only occur if there are minions existing. We indent this bit so it’s more legible. The code here is fairly simple - we kill a minion using our handy macro, since that’s what we want to do. Next we GOTO LABEL 1. Why? As we stated before, the event needs to loop, so this is where the loop comes into play. After we kill a minion, we move back up to LABEL 1, to check if any more minions exist! Only once CHECK_EXISTS Minion returns 0 will the event be able to end. In other words, it will only end once we’ve killed all the minions.
Earlier, I stated that the minions can have seperate ids as well. How does this work? Well, to put it simply, we can just repeat the same event as above! Rather than having the event end after LABEL 2, we would instead repeat the event, but check for the next minion’s ID. I’ll leave it to you to sort out what that might look like.
Feel free to ask any questions about this prompt, or to suggest the next one. Thanks for reading and happy eventing!