So I'm not sure if there is a way to do this by scripting in these games, and I saw that trading-style thing post just a few above, but I wrote up a quick bit of ASM code to count the number of a specific species of Pokémon in the party, as a bit of practice for myself, and I thought I would share it.
The reason I wrote is so that it could be mainly used as a checkpartypokemon-like command in a script.
It works for FireRed and LeafGreen with no changes, works for Emerald by performing the changes given, and will probably work with any game as long as you find the matching offsets.
Anyway, here's the ASM for FR/LG:
Code:
.text
.align 2
.thumb
.thumb_func
.global CountPartyPokemonSpecies
main:
push {r0-r7, lr}
mov r5, #0x0 @ This means fail
ldr r6, var
ldr r7, party_amount
ldrb r4, [r7] @ Get Pokemon count from r7
cmp r4, #0x0
beq exit
ldrh r3, [r6] @ Get the species to check
cmp r3, #0x0
beq exit @ Don't allow Missingno. This doesn't limit the species from going up, though.
mov r7, #0x0
loop:
ldr r0, first_pokemon @ Offset of first Pokemon
mov r1, #0x64 @ Length of Pokemon RAM data
mul r1, r1, r7 @ r7 holds current index
add r0, r0, r1
bl decrypt_poke_species @ Get this specific species.
mov r9, r0
pop {r0-r7}
cmp r9, r3
bne next
add r5, r5, #0x1 @ Increase the counter
next:
add r7, r7, #0x1 @ Increase party index
cmp r7, r4 @ And compare against the number in the party
blo loop @ I could use a bls here?
exit:
str r5, [r6, #0x10] @ Store the result (r5) in r6 (the var -- 0x800D)
pop {r0-r7, pc} @ Return
decrypt_poke_species:
push {r0-r7}
mov r1, #0xB @ This is the index for the Pokemon species.
ldr r2, decrypt_poke @ Call the Pokemon decryption code
bx r2
.align 2
party_amount:
.word 0x02024029
first_pokemon:
.word 0x02024284
var: @ Got this beauty from HackMew.
.word 0x020270B8 + (0x8004 * 2)
decrypt_poke:
.word 0x0803FBE9
And to work for Emerald, you need only change the end stuff:
Code:
.align 2
party_amount:
.word 0x020244E9
first_pokemon:
.word 0x020244EC
var: @ Got this beauty from HackMew.
.word 0x020275D8 + (0x8004 * 2)
decrypt_poke:
.word 0x0806A519
Some of it is based off some stuff from HackMew's Pokemon take away code, so yeah.
And of course, here's a sample script explaining how to use it:
Code:
#dynamic 0x800000
#include stdpoke.rbh
#org @start
lock
faceplayer
bufferpokemon 0x0 PKMN_MAGIKARP
setvar 0x8004 PKMN_MAGIKARP // Change this to the species you want
callasm 0x08XXXXXX // This is the offset of the routine + 1
compare LASTRESULT 0x1 // The count is stored in 0x800D
if B_>= goto @some // It will be 0 if there is none, or 1-6 for the count
msgbox @m1 MSG_KEEPOPEN // It also counts eggs, so yeah...
release
end
#org @some
buffernumber 0x1 LASTRESULT
msgbox @m2 MSG_KEEPOPEN
release
end
#org @m1
= You don't have any [buffer1]!
#org @m2
= Wow! You have [buffer2] [buffer1]!
I hope someone finds this useful, even if for just an example for beginners to learn from.
Enjoy~!
EDIT: I added Emerald, although I didn't test it.
EDIT 2: I tested the Emerald code, and it works.