Change AI of the Enemy that Triggered An Area Event

This should be fairly simple, but I’m having trouble getting it to work.
I tried this:

CHECK_COORDS 0xFFFF // Get the coordinate of the enemy that triggered event and store to 0xC
SADD 0xCB // Transfer value from 0xC to 0xB
SVAL 0x1 0x00000000 // Set AI to Slot 0x1 (I’ve tried with Slot 0x2 as well)
CHAI2 // Change AI

Which had no effect.

I even tried with a regular CHAI and give it the correct coordinate that the enemy moved on to.

SVAL 0x1 0x00000000
CHAI [11,8]

Still the enemy’s behaviour did not change.

Has anyone been able to get this to work?

#AI changing - the AI to change to is read from Memory Slot 0x2
#Format is SETVAL 0x2 0x2211 for AI Bytes 2 and 1. Bytes 3-4 can't be changed.

put the ai in slot 2, not slot 1
wait you tried that

Well, this is how the game does it anyway

SETVAL 0xD 0x0
SETVAL 0x1 0xYY00XX (coordinates 1)
SETVAL 0x1 0xYY00XX (coordinates 2)
SETVAL 0x2 0xXXYY (ai setting)
CALL $9EE67C (chai for all units at queued coordinates)

If I remember correctly, most of the CHAI events in the game are triggered by players, which does work correctly as far as I can tell.
However, if I want an enemy to trigger the CHAI events, it appears that I can’t change the AI of which ever enemy that triggered the event.

I tried the following:


SVAL 0x1 0x00000000
CHAI [15,6]
SVAL 0x1 0x00000000
CHAI [13,4]
SVAL 0x1 0x00000000
CHAI [11,8]

AREA 0xA Test [11,8] [11,8]

All the other enemies affected by the CHAI started pursuing me, except for the guy who triggered the event by walking on to the tile [11,8]. I waited for a few turns, and all he did was just stand there until I moved within his range. This is very strange…

It looks like there is no easy way to change the AI of the trigger enemy. Darn.

Ah, because the enemy is the active unit at the time of the ai change, I suppose. You could make it so the ai changes the turn after the enemy steps on the tile, using the turn event trick used in prologue and chapter 1 among others

Thanks. I’ll probably try that, unless someone has a better way. It’s convoluted, but I suppose the game probably only expected CHAI events to happen during PlayerPhase as opposed to EP.