Users browsing this thread: 1 Guest(s)
Antinomia: FF6
01-27-2023, 08:59 PM
Still working on part 3 (which ended up being part 3.1 and 3.2, with 3.1 now being done) of the Leo re-recruitment, but I wanted to share the code for the two custom event commands I ended up needing to write for this.
The first is a re-write of event $81, which is never actually used by the game at all. This is the "take item X from inventory" event. The problem is that all it did was scan your inventory for the specified item, and if it found it, decremented its quantity by 1. Unlike the "take X GP from party" event, it did NOT flag that the specified item was not found. So if you wanted to do an event where a character was, like, "Give me a potion", there was no way to determine whether you could actually give him a potion or not. This new version uses the unused event flag $1BD to flag that the item in question is not in your inventory so you can use it to branch. This code is longer than the original $81 code so I had to relocate it. The usage would be 81 XX where XX is the item ID, and then check the $1BD flag, and if it's clear, you can branch to a "thanks for the item!" dialog, and if it's set you can branch to a "you don't have that item" dialog or something.
The other function that I made was more home-brewed, and involves being able to permanently increase a given character's base stats through an event. I assigned it to $76, but it can be any of the dozen or so unused event codes. This takes two parameters: Character ID $00-$0F, and stat ID $00-$03, where the stat IDs are:
$00 = Vigor
$01 = Speed
$02 = Stamina
$03 = Magic Power
The command increases the given base stat for the given character by 1. So, using my assigned event code as an example, 76 06 03 would increase Celes's Magic Power by 1 inside of an event. The intent is to call it in a $B0 loop if you want to increase it by more than 1, so B0 05 76 06 03 B1 would increase Celes's Magic Power by 5. This only takes absolute character IDs, not the $31-$34 party character IDs. It limits the stats to 127 because some calculations use stat*2 which makes the stat overflow and become terrible above that value. This code does not otherwise error-check that you gave it a valid character ID or stat ID, so use wisely.
The first is a re-write of event $81, which is never actually used by the game at all. This is the "take item X from inventory" event. The problem is that all it did was scan your inventory for the specified item, and if it found it, decremented its quantity by 1. Unlike the "take X GP from party" event, it did NOT flag that the specified item was not found. So if you wanted to do an event where a character was, like, "Give me a potion", there was no way to determine whether you could actually give him a potion or not. This new version uses the unused event flag $1BD to flag that the item in question is not in your inventory so you can use it to branch. This code is longer than the original $81 code so I had to relocate it. The usage would be 81 XX where XX is the item ID, and then check the $1BD flag, and if it's clear, you can branch to a "thanks for the item!" dialog, and if it's set you can branch to a "you don't have that item" dialog or something.
Code:
AD B7 1E LDA $1EB7 (Load event byte $1EB7 into A)
29 DF AND #$DF (Mask with 1101 1111 to clear bit 5. $1EB7:5 = $1BD)
8D B7 1E STA $1EB7 (Store the new value)
A6 00 LDX $00 (Zero out X)
BD 69 18 LDA $1869,X (Load item at offset X from inventory list starting at $1869)
C5 EB CMP $EB (Compare that item ID with the item ID given as parameter 1 in $EB)
F0 10 BEQ #$10 (If it's the same, item is in inventory, skip to the decrement function below)
E8 INX (Otherwise, increment X by 1)
E0 00 01 CPX $#0100 (Is X > 255? If so, we've reached the end of the inventory list)
D0 F3 BNE $#F3 (If it's not, jump back to the load item X and try again)
AD B7 1E LDA $1EB7 (If we have reached the end of the list without finding our item, load $1EB7 again)
09 20 ORA #$20 (Mask it with 0010 0000 to set bit 5, i.e. set $1BD)
8D B7 1E STA $1EB7 (And store it)
80 0D BRA $#0D (Jump to the end of the function)
DE 69 19 DEC $1969,X (Decrement the quantity of the item at index X)
BD 69 19 LDA $1969,X (Load the new quantity of this item)
D0 05 BNE #$05 (If it's not zero, jump to the end of the function)
A9 FF LDA $#FF (Otherwise create an "empty" item)
9D 69 18 STA $1869,X (And store it at that index in the item list)
A9 02 LDA $#02 (This function used up 2 event queue bytes)
4C 5C 9B JMP $9B5C (Return to event queue)
The other function that I made was more home-brewed, and involves being able to permanently increase a given character's base stats through an event. I assigned it to $76, but it can be any of the dozen or so unused event codes. This takes two parameters: Character ID $00-$0F, and stat ID $00-$03, where the stat IDs are:
$00 = Vigor
$01 = Speed
$02 = Stamina
$03 = Magic Power
The command increases the given base stat for the given character by 1. So, using my assigned event code as an example, 76 06 03 would increase Celes's Magic Power by 1 inside of an event. The intent is to call it in a $B0 loop if you want to increase it by more than 1, so B0 05 76 06 03 B1 would increase Celes's Magic Power by 5. This only takes absolute character IDs, not the $31-$34 party character IDs. It limits the stats to 127 because some calculations use stat*2 which makes the stat overflow and become terrible above that value. This code does not otherwise error-check that you gave it a valid character ID or stat ID, so use wisely.
Code:
A5EB LDA $EB (load parameter, character ID)
8D0242 STA $4202 (store as multiplier)
A925 LDA #$25 (set to 37 bytes of char data each)
8D0342 STA $4203 (store as multiplier)
A5EC LDA $EC (load parameter, stat offset)
C221 REP #$21 (set A to 16 bits, clear carry)
EA NOP (2-cycle NOP to allow multiplication to complete)
6D1642 ADC $4216 (add 37*ID + $EC offset)
AA TAX (put this value in X)
7B TDC (clear A)
E220 SEP #20 (set A to 8 bits)
BD1A16 LDA $161A,X (load current stat, offset by X)
C97F CMP #$7F (check if already 127)
F004 BEQ #$04 (skip next two commands if it is)
1A INC (increment the value by 1)
9D1A16 STA $161A,X (store new stat value
A903 LDA #$03 (This command was 3 bytes)
4C5C9B JMP $9B5C (Return to event queue)
« Next Oldest | Next Newest »
|
||||
Users browsing this thread: 1 Guest(s)