The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Fan Games > Binary ROM Hacking
Reload this Page Script Get Selected Pokemon's Level

Notices
For all updates, view the main page.

Binary ROM Hacking Need a helping hand or just want to talk about binary ROM hacks? Get comments and answers to any ROM Hacking-related problems, questions or thoughts you have here.

Ad Content
Reply
 
Thread Tools
  #1   Link to this post, but load the entire thread.  
Old September 1st, 2019 (10:29 PM).
Dragonite2963 Dragonite2963 is offline
 
Join Date: Mar 2019
Posts: 36
I'm using Lunos' wonder trade script and it all works well. However, right now the Pokemon you receive is at level five no matter what, as seen here:
givepokemon 0x8000 0x5 0x0 0x0 0x0 0x0

Is there some way to store your chosen Pokemon's level in a variable, then give you a random Pokemon at that same level? I have JPAN's hacked engine applied, if that helps.


Here's the script I'm using:
Code:
'---------------
#org 0x834DAB
faceplayer
lockall
msgbox 0x88BBDDE MSG_YESNO '"Wanna wonder trade?"
compare LASTRESULT 0x1
if 0x1 goto 0x88F83F4
msgbox 0x88EEFED MSG_NORMAL '"Come back anytime."
releaseall
end

'---------------
#org 0x8F83F4
countpokemon
compare LASTRESULT 0x1
if 0x1 goto 0x88F3419
msgbox 0x88FEF7D MSG_NORMAL '"Select the Pokémon you wanna trade..."
special 0x9F
waitstate
special2 0x8003 0x147
compare 0x8003 0x19C
if 0x1 goto 0x88BA2AA
compare 0x8004 0x6
if 0x4 goto 0x88BEEE1
goto 0x88EDAB2

'---------------
#org 0x8F3419
msgbox 0x8866BC4 MSG_NORMAL '"Sorry, you need two Pokémon\nto us..."
releaseall
end

'---------------
#org 0x8BA2AA
msgbox 0x8812385 MSG_NORMAL '"I'm sorry, you cannot trade\na Pok..."
releaseall
end

'---------------
#org 0x8BEEE1
msgbox 0x88EEFED MSG_NORMAL '"Come back anytime."
releaseall
end

'---------------
#org 0x8EDAB2
random 0x19C
compare LASTRESULT 0x0
if 0x1 goto 0x88EDAB2
compare LASTRESULT 0xFB
if 0x3 goto 0x88BB32D
compare LASTRESULT 0x115
if 0x4 goto 0x88BB32D
goto 0x88EDAB2

'---------------
#org 0x8BB32D
copyvar 0x8000 LASTRESULT
bufferpokemon 0x0 0x8000
showpokepic 0x8000 0xA 0x3
waitcry
callasm 0x871E751
givepokemon 0x8000 0x5 0x0 0x0 0x0 0x0
pause 0x13
fanfare 0x13E
msgbox 0x88BFC33 MSG_KEEPOPEN '"[player] got a [buffer1]!"
waitfanfare
closeonkeypress
hidepokepic
msgbox 0x88D4343 MSG_YESNO '"Wanna give it a nickname?"
compare LASTRESULT 0x1
if 0x1 call 0x8844FED
msgbox 0x88EEFED MSG_NORMAL '"Come back anytime."
releaseall
end

'---------------
#org 0x844FED
countpokemon
subvar LASTRESULT 0x1
copyvar 0x8004 LASTRESULT
fadescreen 0x1
special 0x9E
waitstate
return


'---------
' Strings
'---------
#org 0x8BBDDE
= Wanna wonder trade?

#org 0x8EEFED
= Come back anytime.

#org 0x8FEF7D
= Select the Pokémon you wanna trade.

#org 0x866BC4
= Sorry, you need two Pokémon\nto use the Wonder Trade.\pCome back anytime.

#org 0x812385
= I'm sorry, you cannot trade\na Pokémon Egg using the\lWonder Trade System.\pCome back anytime.

#org 0x8BFC33
= [player] got a [buffer1]!

#org 0x8D4343
= Wanna give it a nickname?
It's probably a simple question, but I'm just having trouble figuring it out. Thanks!
Reply With Quote
  #2   Link to this post, but load the entire thread.  
Old September 16th, 2019 (2:02 PM).
Burtle's Avatar
Burtle Burtle is offline
Discord: Burtle#6904
 
Join Date: Sep 2019
Posts: 30
https://www.pokecommunity.com/showthread.php?t=204808
Reply With Quote
  #3   Link to this post, but load the entire thread.  
Old December 5th, 2019 (8:08 AM). Edited December 5th, 2019 by Dr. POP.
Dr. POP's Avatar
Dr. POP Dr. POP is offline
 
Join Date: Sep 2009
Location: Mt. Silver
Gender: Male
Posts: 119
Dragonite2963, this Reddit post seems to have exactly what you need. I was looking for this type of script myself, and I've tried out this ASM routine and it works as intended.

I am copying it here for reference/archival purposes, but all credit goes to the OP, /u/IncompleteThought:

Spoiler:
Quote:
Originally Posted by IncompleteThought
Found a workaround. Compiled code: Write at freespace offset:
Code:
.text
.align 2
.thumb
.thumb_func
main:
ldrb r1, [r0, #0x0] @loads level of Pokémon to be given into
 r1
cmp r1, #0xFF
BNE end @jumps to end if Pokémon's level is not 255
push {r0}
ldr r0, =(0x020370BA) @var 0x8001; contains level of Pkm1
ldrb r0, [r0]
mov r1, r0 @stores byte loaded from variable into r1
pop {r0}

end: 
@original instructions from givepokemon removed for hook:
mov r9, r1
add r0, #0x1
str r0, [r4, #0x8]
add r0, r4, #0x0
ldr r1, =(0x0806BFFB)
bx r1
.align 2
And then at 0x06BFF0 for the hook:
Code:
.text
.align 2
.thumb
.thumb_func
main:
ldr r2, =(0x0883F0A9) @pointer to free space 83F0A8
@hook @0x0806BFF0:
bx r2                 @hook to the spot.

.align 2
This makes this work:
Code:
setvar 0x8001 0x[lvlofpkmn]
givepokemon 0x[species] 0xFF 0x0 0x0 0x0

This a fairly simple case of inserting an ASM routine, so I'm not adding extensive step-by-step instructions here. If you are not familiar with ASM yet, you should be fine by simply following FBI's instructions. I am absolutely not versed in ASM but could somehow make it work.

Avoid the rookie mistakes I made:
  • Don't forget to open the .bin file in the Hex editor (and not the .asm file). As clearly stated in FBI's tutorial.
  • Don't forget to insert your own offset in the second piece of code. There where it says "ldr r2, =(0x.....".
  • Don't forget that pointers in ASM always add +1 to the actual offset. As you can see from the sample, the offset for the new script was 0x83F0A8 but the second piece of code is ldr r2, =(0x0883F0A9). This is stated in FBI's tutorial as well, so I don't have much to add. This is simply meant as a reminder.
  • Finally, don't forget to insert a regular XSE script in which the level is stored in variable 0x8001.
Let me know if this works for you or not.
Reply With Quote
Reply

Quick Reply

Join the conversation!

Create an account to post a reply in this thread, participate in other discussions, and more!

Create a PokéCommunity Account
Ad Content

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 9:15 AM.