QUADRA-POST
I've been looking into how H0512 and H0512-opt 'work', hoping for code that can tell me how to make one creature support a specific peer, but not itself.
Here's how it does it:
1. In H0512's Pre-Battle script, there is a set of opcodes:
12 0020
02 2050
02 4120
80
60 41
40
90
73
This pushes the address of localvar20 to the stack. Then, it uses a mask to create a list of players who are both active, and have enemy ID (address 4120) $41 (65 - that's H0512-opt's ID), and stores it at 0020.
2. Now, one way it can interact with its peers is to directly change the statuses of them in a script. One example appears in the Death script, where H0512-opt is made un-targetable:
12 0020
10 4023
80
60 00
90
This uses the mask, taking the list of active players with ID 65, then specifying the target-able flag. Basically, you use 12 0020 as you would use 12 2060 if you wanted to change the stats of the script owner, or 12 20A0 if you wanted to change the stats of all opponents.
3. What if you want to, say, target a peer with a particular ID? Well, you can probably guess from above that you might substitute 02 0020 for a 'all opponent mask', 'all allies mask' etc. etc. You're right. H0512's code for targeting H0512-opt is:
12 2070
02 0020
90
You can also mask the list provided by 0020. H0512 masks the list, targetting Opt-units which are dead:
12 2070
02 0020
00 4000
80
60 01
40
90
Address 4000 is 'dead'. A list of Opt-units and their death-statuses is created, then the opcode 40 compares the value of each entry with the 'True' condition. You could add an 82 before the 'store' opcode (90) of that if you wanted to pick a random dead H0512-opt unit.
You could easily adapt this code to have a monster buff another monster in certain conditions. I think, though, that you'd have to change the way that LocalVar0020 is set, instead setting it at the start of the script and having it choose from *alive* units, or else I think you might get your monster trying to cast haste on something that's dead. Of course, you could just set a condition saying that the ability is only used when monster X is both unbuffed and alive, and only target those living, but I think changing the way LocalVar0020 is set would be easier.
Also, I was wondering if one of our veterans could tell me: what if I wanted to use multiple conditions in targeting? What if I wanted to choose targets who were both asleep and slowed?
Edit: Found it. I looked at how Helletic Hojo locates targets for Pile Banger:
12 2070 [pushes address of 'target mask']
02 20A0 [all opps]
00 4006 [confu]
80 [mask - all opponents and their confu statuses]
60 00
40 [compare - creates list of opponents without confu]
90 [store this to target mask]
12 2070
02 2070 [loads the list of enemies from the target mask]
00 4002 [sleep]
80
60 00
40
90 [so, takes the list from the target mask, then sees the sleep status of these targets, and returns to the target mask only party members in neither confu nor sleep]
12 2070
02 2070 [again]
82
90 [and a random target from that list]
Ta-da!