• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best places on the 'net to talk Pokémon and more! Community members will not see the bottom screen advertisements.
  • Want to share your adventures playing Pokémon?
    Check out our new Travel Journals forum for sharing playthroughs of ROM Hacks, Fan Games, and other Pokémon content!
  • IMPORTANT: Following a takedown request, the following hacks have been delisted from PokéCommunity:

    • Pokémon Glazed
    • Pokémon: Giratina Strikes Back
    • Pokémon Flora Sky
    • Pokémon Stranded
    The downloads and discussion threads for these hacks will no longer be accessible, and staff will be unable to return questions regarding accessing this content.

Development: Getting the min/max level of your Pokémon party

HackMew

Mewtwo Strikes Back
1,314
Posts
17
Years
  • Seen Oct 26, 2011

Brief Intro

Here I've got a couple of routines for you. They are designed to get the minimum and maximum levels respectively.

Description

As you can see, the routines are pretty short and simple so I did not comment them on purpose.
Either way, here's a brief description of what happens:

  1. Get the Pokémon party level address into r1.
  2. Load the first value into r0, and assume it's the minimum (or maximum) value yet.
  3. Loop 5 times, and update the mininum (or maximum) value if needed.
  4. Get the LASTRESULT var address into r1 and store the minimum (or maximum) level.
The minimum routine, however, is slighty different because a zero-level is not an acceptable value so there's an extra check to take that into account (otherwhise as long as your team is not full, the minimum level would always be zero, which is no good obviously). That also means the routine will loop up to 5 times rather than always 5 as it happens in the maximum routine.

The Code


GetMinPartyLevel


  • FireRed/LeafGreen

    Code:
    [div="font-family:consolas,courier new,monospace"].text
    .align 2
    .thumb
    .thumb_func
    .global GetMinPartyLevel
    
    main:
    	push {r0-r3, lr}
    	ldr r1, .PARTY_LVL
    	ldrb r0, [r1]
    	mov r3, #0x5
    
    loop:
    	add r1, #0x64
    	ldrb r2, [r1]
    	cmp r2, #0x0
    	beq return
    	cmp r2, r0
    	bge next
    	add r0, r2, #0x0
    
    next:
    	sub r3, #0x1
    	cmp r3, #0x0
    	bne loop
    
    return:
    	ldr r1, .VAR
    	strh r0, [r1]
    	pop {r0-r3, pc}
    
    .align 2
    .PARTY_LVL:
    	.word 0x02024284 + 0x54
    .VAR:
    	.word 0x020270B6 + (0x800D * 2)[/div]
  • Ruby/Sapphire

    Note: The routine is the same as the FR/LG one; just replace the bottom part with the following:

    Code:
    [div="font-family:consolas,courier new,monospace"].align 2
    .PARTY_LVL:
    	.word 0x03004360 + 0x54
    .VAR:
    	.word 0x0201E8C2 + (0x800D * 2)[/div]
  • Emerald

    Note: The routine is the same as the FR/LG one; just replace the bottom part with the following:

    Code:
    [div="font-family:consolas,courier new,monospace"].align 2
    .PARTY_LVL:
    	.word 0x020244EC + 0x54
    .VAR:
    	.word 0x020275D6 + (0x800D * 2)[/div]

GetMaxPartyLevel


  • FireRed/LeafGreen

    Code:
    [div="font-family:consolas,courier new,monospace"].text
    .align 2
    .thumb
    .thumb_func
    .global GetMaxPartyLevel
    
    main:
    	push {r0-r3, lr}
    	ldr r1, .PARTY_LVL
    	ldrb r0, [r1]
    	mov r3, #0x5
    
    loop:
    	add r1, #0x64
    	ldrb r2, [r1]
    	cmp r2, r0
    	ble next
    	add r0, r2, #0x0
    
    next:
    	sub r3, #0x1
    	cmp r3, #0x0
    	bne loop
    
    return:
    	ldr r1, .VAR
    	strh r0, [r1]
    	pop {r0-r3, pc}
    
    .align 2
    .PARTY_LVL:
    	.word 0x02024284 + 0x54
    .VAR:
    	.word 0x020270B6 + (0x800D * 2)
    [/div]
  • Ruby/Sapphire

    Note: The routine is the same as the FR/LG one; just replace the bottom part with the following:

    Code:
    [div="font-family:consolas,courier new,monospace"].align 2
    .PARTY_LVL:
    	.word 0x03004360 + 0x54
    .VAR:
    	.word 0x0201E8C2 + (0x800D * 2)[/div]
  • Emerald

    Note: The routine is the same as the FR/LG one; just replace the bottom part with the following:

    Code:
    [div="font-family:consolas,courier new,monospace"].align 2
    .PARTY_LVL:
    	.word 0x020244EC + 0x54
    .VAR:
    	.word 0x020275D6 + (0x800D * 2)[/div]


This research document is Copyright © 2010 by HackMew.
You are not allowed to copy, modify or distribute it without permission.
 
Last edited:
5,256
Posts
16
Years
Wow, this routine unlocks some pretty cool stuff, such as a FR/LG Battle Frontier-style thing (the opponents' Pokémon are the same level as your max Pokémon, for example). It's real cool. Nice one, HackMew!
 

HackMew

Mewtwo Strikes Back
1,314
Posts
17
Years
  • Seen Oct 26, 2011
Wow, this routine unlocks some pretty cool stuff, such as a FR/LG Battle Frontier-style thing (the opponents' Pokémon are the same level as your max Pokémon, for example). It's real cool. Nice one, HackMew!

You're welcome :)


don't mean to put ya down, but couldn't this be done with a script as well?

As far as I know, there's no special that can do that. Feel free to prove me wrong.
 

0m3GA ARS3NAL

Im comin' home...
1,816
Posts
16
Years
No specials really it would just be a long script I suppose... Probably much more space-efficient to use your routine... (A script version would require tons of copybyte's and comparefarbytes' as well as knowing RAM locations of variables, it's better to just use your routine and call it with callasm...)
 

HackMew

Mewtwo Strikes Back
1,314
Posts
17
Years
  • Seen Oct 26, 2011
No specials really it would just be a long script I suppose... Probably much more space-efficient to use your routine... (A script version would require tons of copybyte's and comparefarbytes' as well as knowing RAM locations of variables, it's better to just use your routine and call it with callasm...)

Yeah, indeed. Those routines are definitely more space- and time-efficient then any scripting equivalents.
 
Back
Top