This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
ff3:ff3us:tutorial:events:branch [2017/12/28 22:11] lockirby2 created |
ff3:ff3us:tutorial:events:branch [2019/02/12 12:44] (current) |
||
---|---|---|---|
Line 3: | Line 3: | ||
This section contains the most technical aspects of event hacking. | This section contains the most technical aspects of event hacking. | ||
- | * To reuse a part of the event script several times. | + | * To reuse an event script several times. |
* To skip over part of an event. | * To skip over part of an event. | ||
* To use extra space. | * To use extra space. | ||
* To repeat part of an event many times (perhaps an infinite number of times). | * To repeat part of an event many times (perhaps an infinite number of times). | ||
+ | |||
+ | ==== Jumping to a Subroutine ==== | ||
+ | |||
+ | The simplest way to jump to another address is to use the B2 command. | ||
+ | |||
+ | When the game jumps to CA/4020, it will execute the event script found there and then return when it reaches an $FE command. | ||
+ | |||
+ | By itself, this command allows us to reuse parts of the event script, as in the innkeeper example above. | ||
+ | |||
+ | ==== Event Bits ==== | ||
+ | |||
+ | A way to branch based on certain conditions would also be very helpful. | ||
+ | |||
+ | Every time you step on that tile, the game will check to see if that particular event bit is 1 or 0. If it is 0, the game knows that the player has not fought the guards yet. If it is 1, the player must have fought the guards already. | ||
+ | |||
+ | If we use event bits correctly, the game can answer questions like "Has the party met Shadow yet?" or "Has the party defeated my optional superboss?" | ||
+ | |||
+ | ==== Example ==== | ||
+ | |||
+ | Right now, players can trigger our new Narshe guard cutscene infinitely many times, summoning as many guards as they please. | ||
+ | |||
+ | First, we should look through the Event Bits Document to find a bit that is unused by the vanilla game. Arbitrarily, | ||
+ | |||
+ | Now we need to revisit the beginning of the cutscene to add the command that branches based on our event bit. Looking in the Event Commands Document, we can see that the $C0 command allows us to do this. We need to specify five parameters for this command, so we will need to copy the existing cutscene and paste it six bytes ahead. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | The first two parameters of the $C0 command allow us to choose which bit to branch on. We want to branch if bit $149 is set, so we invert 01 49 and add $80 to the second parameter. | ||
+ | |||
+ | We can use the last three parameters to specify the address to branch to. In this case, we want to branch to the address just after our original cutscene. | ||
+ | |||
+ | Finally, we need to write an alternate cutscene that is shown if the guards have been defeated. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Conveniently, | ||
+ | |||
+ | ==== Reading the Event Script Dump ==== | ||
+ | Event bits are represented in different ways depending on which document or tool you are using to view them. In the Event Bits Document, each Event Bit is represented by a number between $000 and $2FF, as you have seen. However, if you look in the Event Script Dump, you may see a line like the following (emphasis mine): | ||
+ | |||
+ | '' | ||
+ | |||
+ | This line only refers to a single event bit ($1CC), which I have bolded and underlined. | ||
+ | |||
+ | ==== Event Bits Higher Than $2FF ==== | ||
+ | You may have noticed that event bits higher than $2FF are not listed in the Event Bits Document, yet they are often set or cleared in the Event Script Dump. These event bits are used to determine whether NPCs are immediately shown when you load a map. For example, bit $31C controls whether Vargas appears on Mt. Kolts. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | You can cross reference this with the event dump by looking at the following part of lines like this: | ||
+ | |||
+ | '' | ||
+ | |||
+ | In this way, you can tell that " |