Many Trainer AI Fixes - haven1433/HexManiacAdvance GitHub Wiki
All of these tutorials are made by MeKomoATuPrima, and they were made using pret/pokeemerald's bug-fix code segments.
Trainer AI checks if its Pokémon is Ghost type or if it has high evasion, but it should check the opposing Pokémon, not itself.
- Go to scripts.battle.ai.trainer and the CheckViability.
Search the address 2DD75D [EM] or 1DB3A3 [FR].
- You should see this code:
[EM]
get_type 1
if_equal 7 <2DD77C>
get_type 3
if_equal 7 <2DD77C>
if_stat_level_more_than user evasion positive_2 <2DD782>
score -2
goto <2DD78A>
[FR]
get_type 1
if_equal 7 <1DB3C2>
get_type 3
if_equal 7 <1DB3C2>
if_stat_level_more_than user evasion positive_2 <1DB3C8>
score -2
goto <1DB3D0>
Change it to: [EM]
get_type 0
if_equal 7 <2DD77C>
get_type 2
if_equal 7 <2DD77C>
if_stat_level_more_than target evasion positive_2 <2DD782>
score -2
goto <2DD78A>`
[FR]
get_type 0
if_equal 7 <1DB3C2>
get_type 2
if_equal 7 <1DB3C2>
if_stat_level_more_than target evasion positive_2 <1DB3C8>
score -2
goto <1DB3D0>
If you have edited Ghost to be special and Dark to be physical, their IDs are swapped, so change it to this instead:
[EM]
get_type 0
if_equal 17 <2DD77C>
get_type 2
if_equal 17 <2DD77C>
if_stat_level_more_than target evasion positive_2 <2DD782>
score -2
goto <2DD78A>
[FR]
get_type 0
if_equal 17 <1DB3C2>
get_type 2
if_equal 17 <1DB3C2>
if_stat_level_more_than target evasion positive_2 <1DB3C8>
score -2
goto <1DB3D0>
The Pursuit (2DD845 in Emerald or 1DB48B in Fire Red) and Curse (2DD645 in Emerald or 1DB293 in Fire Red) scripts should also be modified in case you have edited Ghost to be special and Dark to be physical: just change every if_equal 7 to if_equal 11. In case HMA doesn't let you edit Curse, just change 2DD648 and 2DD650 (Both in Emerald) or 1DB296 and 1DB29E (Both in Fire Red) from 07 to 11.
From the pokeemerald repo: "The scripts for checking type-resistance to weather for semi-invulnerable moves are swapped. The result is that the AI is encouraged to stall while taking damage from weather."
The way to fix this is going to address 2DDA3D [EM] or 1DB677 [FR]. You will see:
[EM]
if_status target 128 <2DDAAC>
if_status2 target 0x10000000 <2DDAAC>
if_status3 target 4 <2DDAAC>
get_weather
if_equal 3 <2DDA6D>
if_equal 2 <2DDA88>
goto <2DDA98>
[FR]
if_status target 128 <1DB6E6>
if_status2 target 0x10000000 <1DB6E6>
if_status3 target 4 <1DB6E6>
get_weather
if_equal 3 <1DB6A7>
if_equal 2 <1DB6C2>
goto <1DB6D2>
Just swap the addresses in the if_equals:
[EM]
if_status target 128 <2DDAAC>
if_status2 target 0x10000000 <2DDAAC>
if_status3 target 4 <2DDAAC>
get_weather
if_equal 3 <2DDA88>
if_equal 2 <2DDA6D>
goto <2DDA98>
[FR]
if_status target 128 <1DB6E6>
if_status2 target 0x10000000 <1DB6E6>
if_status3 target 4 <1DB6E6>
get_weather
if_equal 3 <1DB6C2>
if_equal 2 <1DB6A7>
goto <1DB6D2>
Normally, trainer AI checks if the target is statused to use Façade, but it should check if the user is statused.
Go to address 2DDAF7 [EM] or 1DB731 [FR], and change 00 to 01.
The script goes from
[EM and FR]
if_not_status target 216 <section0>
score 1
end
To
[EM and FR]
if_not_status user 216 <section0>
score 1
end
I think this is the most important fix.
If you have played Gen 3, you may have noticed how frequently the AI uses Protect. (It almost always uses it on the first turn if there is no weather move.) This is due to a programming error: the AI checks if your last move HASN'T been Lock-On or MInd Reader (meaning, almost always); if it is the case, the AI prioritizes Protect. In order to fix this, we have to modify the code so the AI prioritizes protect if your last move HAS been Lock-On or MInd Reader.
-
Go to scripts.battle.ai.trainer and the CheckViability. Search for the address 2DD694.
-
You should see this code:
get_protect_count user
if_more_than 1 <2DD75A>
if_status user 128 <2DD751>
if_status2 user 0x10000000 <2DD751>
if_status3 user 32 <2DD751>
if_status2 user 0x000F0000 <2DD751>
if_status3 user 4 <2DD751>
if_status3 user 6144 <2DD751>
if_has_move_with_effect target HealHalfSelf <2DD751>
if_has_move_with_effect target RaiseDefenseAndImproveRollingMoves <2DD751>
if_status target 128 <2DD730>
if_status2 target 0x10000000 <2DD730>
if_status3 target 32 <2DD730>
if_status2 target 0x000F0000 <2DD730>
if_status3 target 4 <2DD730>
if_status3 target 6144 <2DD730>
get_last_used_move target
get_move_effect_from_result
if_not_equal 94 <2DD730>
goto <2DD732>
Just change:
if_not_equal 94 <2DD730> to if_equal 94 <2DD730>.
That's it.
(It's the same situation as in Emerald, but the addresses are different.)
-
Go to scripts.battle.ai.trainer and the CheckViability. Search for the address 1DB2E2.
-
You should see this code:
get_protect_count user
if_more_than 1 <1DB3A0>
if_status user 128 <1DB397>
if_status2 user 0x10000000 <1DB397>
if_status3 user 32 <1DB397>
if_status2 user 0x000F0000 <1DB397>
if_status3 user 4 <1DB397>
if_status3 user 6144 <1DB397>
if_has_move_with_effect target HealHalfSelf <1DB397>
if_has_move_with_effect target RaiseDefenseAndImproveRollingMoves <1DB397>
if_status target 128 <1DB37E>
if_status2 target 0x10000000 <1DB37E>
if_status3 target 32 <1DB37E>
if_status2 target 0x000F0000 <1DB37E>
if_status3 target 4 <1DB37E>
if_status3 target 6144 <1DB37E>
get_last_used_move target
get_move_effect_from_result
if_not_equal 94 <1DB37E>
goto <1DB380>
Just change if_not_equal 94 <1DB37E> to if_equal 94 <1DB37E>.
That's it.