- 192
- Posts
- 17
- Years
- Seen Oct 28, 2020
Hello.
I found what seems to be the scrips that determine how trainers act during battles. It's a different bytecode than that used for NPCs, or moves, or moveanimations, or overworld effects, etc.
It runs a series of 32 scripts for each move in the moveset, the scripts can add or subtract to a score for this move depending on the circumstances and then quit.
Unlike the npc scripts there aren't serveral variables that you can access by number but only one that you can use freely, and another one that contains the id of the move being considered right now.
In case a command can use either variable as input, there are two variants of it with separate codes.
(In my notes __8 is the free variable and _2 is the move being considered, I'm renaming these however wherever I encounter them in my notes. _8, _16 and _32 refer to the lengths one byte, two bytes, four bytes)
Many of these commands are followed by one byte that specifies if it refers to the attacking pokemon (1) or defending pokemon (0).
The dispatch table is at 083F55A4. Meanings as far as I have figured them out so far are:
Reminder regarding status1 and status2. The Pokemon Information relevant for a battle is copied from their own data structures into four structures at 02023BE4 (two for player side, two for opponent side). JPAN documented this in this post: https://www.pokecommunity.com/posts/7156541/ (in the RAM-structures spoiler) and status1 and status2 are part of that structure.
The array of 32 pointers to such scripts is at 081D9BF4.
It's worth noting that the entry "081DBCED", that appears multiple times here, doesn't do anything and can be replaced by custom move-rating-scripts.
Here are some lightly documented examples:
More information can be found in my IDA database.
At this point I need to thank JPAN. Never before have I relied on JPANs research this much.
I found what seems to be the scrips that determine how trainers act during battles. It's a different bytecode than that used for NPCs, or moves, or moveanimations, or overworld effects, etc.
It runs a series of 32 scripts for each move in the moveset, the scripts can add or subtract to a score for this move depending on the circumstances and then quit.
Unlike the npc scripts there aren't serveral variables that you can access by number but only one that you can use freely, and another one that contains the id of the move being considered right now.
In case a command can use either variable as input, there are two variants of it with separate codes.
(In my notes __8 is the free variable and _2 is the move being considered, I'm renaming these however wherever I encounter them in my notes. _8, _16 and _32 refer to the lengths one byte, two bytes, four bytes)
Many of these commands are followed by one byte that specifies if it refers to the attacking pokemon (1) or defending pokemon (0).
The dispatch table is at 083F55A4. Meanings as far as I have figured them out so far are:
Spoiler:
Code:
00 random_goto__high_param_likely
01 random_goto__low_param_likely
02 random_goto__1_in_256_chance
03 random_goto__255_in_256_chance
04 viability_score (followed by the value that should be added FF=-1 FE=-2 …)
05 jump_if_health_percentage_lt
06 jump_if_health_percentage_ge
07 jump_if_health_percentage_eq
08 jump_if_health_percentage_ne
09 jump_if_any_status1_bit
0A jump_if_no_status1_bit
0B jump_if_any_status2_bit
0C jump_if_no_status2_bit
0D jump_if_any_status3_bit
0E jump_if_no_status3_bit
0F jump_if_any_status4_bit
10 jump_if_no_status4_bit
11 jump_if__8_lt_8
12 jump_if__8_gt_8
13 jump_if__8_eq_8
14 jump_if__8_ne_8
15 jump_if__8_lt_32
16 jump_if__8_gt_32
17 jump_if__8_eq_32
18 jump_if__8_ne_32
19 jump_if_move_id_eq_16
1A jump_if_move_id_ne_16
1B jump_if__8_in_list_8
1C jump_if__8_not_in_list_8
1D jump_if__8_in_list_16
1E jump_if__8_not_in_list_16
1F jump_if_attacker_has_any_damaging_moves
20 jump_if_attacker_has_no_damaging_moves
21 get_battle_turn_counter__8
22 get_some_type
23 move_get_power__2_8
24 is_most_powerful_move__8
25 get_move_to_execute_B
26 jump_if__8_ne_2
27 jump_if__8_eq_2
28 jump_if_move_would_hit_first
29 jump_if_move_would_hit_second
2A —
2B —
2C count_alive_pokemon_on_team
2D get_move_id__8
2E move_get_move_script_id
2F get_ability
30 simulate_damage_muliplier_four_times
31 simulate_damage_bonus_jump_if_eq
32 —
33 —
34 jump_if_any_party_member_has_status_ailment_32
35 jump_if_no_party_member_has_status_ailment_32_BUGGED
36 get_weather__8
37 jump_if_move_id_eq_8
38 jump_if_move_id_ne_8
39 jump_if_stat_buff_lt
3A jump_if_stat_buff_gt
3B jump_if_stat_buff_eq
3C jump_if_stat_buff_ne
3D determine_move_damage_jump_if_fatal
3E determine_move_damage_jump_if_not_fatal
3F jump_if_has_move
40 jump_if_hasnt_move
41 jump_if_move_with_same_movescript_in_either_0_2_history_or_1_3_moveset
42 jump_if_move_with_same_movescript_in_neither_0_2_history_nor_1_3_moveset
43 is_moveset_restricted
44 jump_if_or_if_not_current_move_in_encore
45 f10_or_b1011
46 jump_random_unknown
47 f10_or_b1101
48 get_held_item_x12__8
49 pokemon_species_get_gender_info
4A enter_battle_countdown_get_state
4B stockpile_get_num_uses
4C is_double_battle
4D get_dp08_item__8
4E move_get_type__8
4F move_get_power__8_8
50 move_get_move_script_id__8
51 get_protect_endure_activity
52 —
53 —
54 —
55 —
56 —
57 —
58 call
59 jump
5A return_and_eventually_f10_or_b0001
5B compare_attacker_defender_levels
5C jump_if_taunt_turns_ne_0
5D jump_if_taunt_turns_eq_0
Reminder regarding status1 and status2. The Pokemon Information relevant for a battle is copied from their own data structures into four structures at 02023BE4 (two for player side, two for opponent side). JPAN documented this in this post: https://www.pokecommunity.com/posts/7156541/ (in the RAM-structures spoiler) and status1 and status2 are part of that structure.
The array of 32 pointers to such scripts is at 081D9BF4.
Code:
081D9BF4: 081D9C74 081DA445 081DBA6F 081DBA8D
081D9C04: 081DBAEF 081DBADF 081DBB16 081DBB3B
081D9C14: 081DBB3C 081DBC91 081DBCED 081DBCED
081D9C24: 081DBCED 081DBCED 081DBCED 081DBCED
081D9C34: 081DBCED 081DBCED 081DBCED 081DBCED
081D9C44: 081DBCED 081DBCED 081DBCED 081DBCED
081D9C54: 081DBCED 081DBCED 081DBCED 081DBCED
081D9C64: 081DBCED 081DBCA8 081DBCD6 081DBCDD
It's worth noting that the entry "081DBCED", that appears multiple times here, doesn't do anything and can be replaced by custom move-rating-scripts.
Here are some lightly documented examples:
Spoiler:
Code:
// don't use moves that are negated by "soundproof"
081D9CE0 2F @ get ability of
081D9CE1 00 @ defender
081D9CE2 14 @ jump if not equal to
081D9CE3 soundproof
081D9CE4 081D9D27
081D9CE8 19 (jump_if_move_id_equals_16)
081D9CE9 mve_growl
081D9CEB 081DA433 (lower viability of move by 10)
081D9CEF 19 (jump_if_move_id_equals_16)
081D9CF0 mve_roar
081D9CF2 081DA433 (lower viability of move by 10)
081D9CF6 19 (jump_if_move_id_equals_16)
081D9CF7 mve_sing
081D9CF9 081DA433 (lower viability of move by 10)
081D9CFD 19 (jump_if_move_id_equals_16)
081D9CFE mve_supersonic
081D9D00 081DA433 (lower viability of move by 10)
081D9D04 19 (jump_if_move_id_equals_16)
081D9D05 mve_screech
081D9D07 081DA433 (lower viability of move by 10)
081D9D0B 19 (jump_if_move_id_equals_16)
081D9D0C mve_snore
081D9D0E 081DA433 (lower viability of move by 10)
081D9D12 19 (jump_if_move_id_equals_16)
081D9D13 mve_uproar
081D9D15 081DA433 (lower viability of move by 10)
081D9D19 19 (jump_if_move_id_equals_16)
081D9D1A mve_metal_sound
081D9D1C 081DA433 (lower viability of move by 10)
081D9D20 19 (jump_if_move_id_equals_16)
081D9D21 mve_grasswhistle
081D9D23 081DA433 (lower viability of move by 10)
081DA433 04 (add to viability)
081DA434 F6 (minus 10)
081DA435 5A (end)
081DAB77 5 @ jump if health of
081DAB78 1 @ attacker
081DAB79 70 @ less than 70%
081DAB7A 081DAB86 @ target
081DAB7E 0x3A @ jump if
081DAB7F 0 @ defender
081DAB80 5 @ spdef
081DAB81 3 @ ?
081DAB82 081DAB8E @ target
081DAB86 0
081DAB87 0x32
081DAB88 081DAB8E
081DAB8C 4 @ move not so viable
081DAB8D -2 @ minus 2 points
081DAB8E 6 @ jump if health of
081DAB8F 0 @ defender
081DAB90 70 @ greater than 70%
081DAB91 081DAB97 @ target
081DAB95 4 @ move not so viable
081DAB96 -2 @ minus 2 points
081DAB97 0x5A @ end
More information can be found in my IDA database.
At this point I need to thank JPAN. Never before have I relied on JPANs research this much.
Last edited: