The PokéCommunity Forums

The PokéCommunity Forums (https://www.pokecommunity.com/index.php)
-   Binary ROM Hacking (https://www.pokecommunity.com/forumdisplay.php?f=284)
-   -   Script Script for NPC pokemon trade? (https://www.pokecommunity.com/showthread.php?t=382951)

Scarlet D. November 11th, 2016 6:37 AM

Script for NPC pokemon trade?
 
Hey guys

As the title says, I need a script that will make NPC trade certain pokemon in Fire Red Rom. I tried to read the compiled script on fire red and leaf green roms but i didn't find any sense there XD

Thanks

DizzyEgg November 11th, 2016 6:47 AM

Quote:

Originally Posted by Aenaos (Post 9483308)
Hey guys

As the title says, I need a script that will make NPC trade certain pokemon in Fire Red Rom. I tried to read the compiled script on fire red and leaf green roms but i didn't find any sense there XD

Thanks

Show me the decompiled script and tell me which part you don't understand.

Scarlet D. November 11th, 2016 7:26 AM

Quote:

Originally Posted by DizzyEgg (Post 9483318)
Show me the decompiled script and tell me which part you don't understand.

ok here is the script

Code:

'---------------
#org 0x16F602
lock
faceplayer
setvar 0x8008 0x0
call 0x81A8CAD
checkflag 0x248
if 0x1 goto 0x816F674
msgbox 0x81A597B MSG_YESNO '"I'm looking for the POKéMON\n[buff..."
compare LASTRESULT 0x0
if 0x1 goto 0x816F65C
call 0x81A8CBD
compare 0x8004 0x6
if 0x4 goto 0x816F65C
call 0x81A8CC9
comparevars LASTRESULT 0x8009
if 0x5 goto 0x816F666
call 0x81A8CD9
msgbox 0x81A59DA MSG_KEEPOPEN '"Hey, thanks!"
setflag 0x248
release
end

'---------------
#org 0x1A8CAD
copyvar 0x8004 0x8008
special2 LASTRESULT 0xFC
copyvar 0x8009 LASTRESULT
return

'---------------
#org 0x16F674
msgbox 0x81A59E7 MSG_KEEPOPEN '"Isn't my old [buffer2] great?"
release
end

'---------------
#org 0x16F65C
msgbox 0x81A59B6 MSG_KEEPOPEN '"Awww!\nOh, well[.]"
release
end

'---------------
#org 0x1A8CBD
special 0x9F
waitstate
lock
faceplayer
copyvar 0x800A 0x8004
return

'---------------
#org 0x1A8CC9
copyvar 0x8005 0x800A
special2 LASTRESULT 0xFF
copyvar 0x800B LASTRESULT
return

'---------------
#org 0x16F666
bufferpokemon 0x0 0x8009
msgbox 0x81A59C6 MSG_KEEPOPEN '"What?\nThat's no [buffer1]!"
release
end

'---------------
#org 0x1A8CD9
copyvar 0x8004 0x8008
copyvar 0x8005 0x800A
special 0xFD
special 0xFE
waitstate
lock
faceplayer
return

'---------
' Strings
'---------
#org 0x1A597B
= I'm looking for the POKéMON\n[buffer1]!\pWanna trade one for my\n[buffer2]?

#org 0x1A59DA
= Hey, thanks!

#org 0x1A59E7
= Isn't my old [buffer2] great?

#org 0x1A59B6
= Awww!\nOh, well[.]

#org 0x1A59C6
= What?\nThat's no [buffer1]!


I can't see the part that i can choose which pokemon to give and which pokemon to receive, that's all

DizzyEgg November 11th, 2016 10:01 AM

Quote:

Originally Posted by Aenaos (Post 9483352)
ok here is the script

Code:

'---------------
#org 0x16F602
lock
faceplayer
setvar 0x8008 0x0
call 0x81A8CAD
checkflag 0x248
if 0x1 goto 0x816F674
msgbox 0x81A597B MSG_YESNO '"I'm looking for the POKéMON\n[buff..."
compare LASTRESULT 0x0
if 0x1 goto 0x816F65C
call 0x81A8CBD
compare 0x8004 0x6
if 0x4 goto 0x816F65C
call 0x81A8CC9
comparevars LASTRESULT 0x8009
if 0x5 goto 0x816F666
call 0x81A8CD9
msgbox 0x81A59DA MSG_KEEPOPEN '"Hey, thanks!"
setflag 0x248
release
end

'---------------
#org 0x1A8CAD
copyvar 0x8004 0x8008
special2 LASTRESULT 0xFC
copyvar 0x8009 LASTRESULT
return

'---------------
#org 0x16F674
msgbox 0x81A59E7 MSG_KEEPOPEN '"Isn't my old [buffer2] great?"
release
end

'---------------
#org 0x16F65C
msgbox 0x81A59B6 MSG_KEEPOPEN '"Awww!\nOh, well[.]"
release
end

'---------------
#org 0x1A8CBD
special 0x9F
waitstate
lock
faceplayer
copyvar 0x800A 0x8004
return

'---------------
#org 0x1A8CC9
copyvar 0x8005 0x800A
special2 LASTRESULT 0xFF
copyvar 0x800B LASTRESULT
return

'---------------
#org 0x16F666
bufferpokemon 0x0 0x8009
msgbox 0x81A59C6 MSG_KEEPOPEN '"What?\nThat's no [buffer1]!"
release
end

'---------------
#org 0x1A8CD9
copyvar 0x8004 0x8008
copyvar 0x8005 0x800A
special 0xFD
special 0xFE
waitstate
lock
faceplayer
return

'---------
' Strings
'---------
#org 0x1A597B
= I'm looking for the POKéMON\n[buffer1]!\pWanna trade one for my\n[buffer2]?

#org 0x1A59DA
= Hey, thanks!

#org 0x1A59E7
= Isn't my old [buffer2] great?

#org 0x1A59B6
= Awww!\nOh, well[.]

#org 0x1A59C6
= What?\nThat's no [buffer1]!


I can't see the part that i can choose which pokemon to give and which pokemon to receive, that's all

The specials are what you want.

Scarlet D. November 11th, 2016 10:40 AM

Quote:

Originally Posted by DizzyEgg (Post 9483502)
The specials are what you want.

Are you trying to tell me there is no actual way to choose the pokemon you want to trade with a npc a receive? for example: I want the NPC to require Mew for the trade and if i choose mew, he will give me a rattata, something like this.

DizzyEgg November 11th, 2016 11:03 AM

Quote:

Originally Posted by Aenaos (Post 9483539)
Are you trying to tell me there is no actual way to choose the pokemon you want to trade with a npc a receive? for example: I want the NPC to require Mew for the trade and if i choose mew, he will give me a rattata, something like this.

There is a trade table that has stuff like wanted and received pokemon, OT gender, OT name, etc. Sadly I don't have the offset of it(look at quick research forums, you may find it there).
Also, there's always a way.

Scarlet D. November 11th, 2016 12:34 PM

Quote:

Originally Posted by DizzyEgg (Post 9483561)
There is a trade table that has stuff like wanted and received pokemon, OT gender, OT name, etc. Sadly I don't have the offset of it(look at quick research forums, you may find it there).
Also, there's always a way.

There is always a way but my knowledge of ASM is low... I am trying to find the topic you are reffering at but I find nothing at all :(

DizzyEgg November 11th, 2016 12:43 PM

Quote:

Originally Posted by Aenaos (Post 9483632)
There is always a way but my knowledge of ASM is low... I am trying to find the topic you are reffering at but I find nothing at all :(

It's not too late to start learning ASM. Chances are you're gonna need it a lot of times.
I'll give you a link, but make sure you search thoroughly next time https://www.pokecommunity.com/showthread.php?p=8528011#post8528011

Scarlet D. November 11th, 2016 1:23 PM

Quote:

Originally Posted by DizzyEgg (Post 9483645)
It's not too late to start learning ASM. Chances are you're gonna need it a lot of times.
I'll give you a link, but make sure you search thoroughly next time https://www.pokecommunity.com/showthread.php?p=8528011#post8528011

wow dude chill, it was in 26 page of the quick research topic ( I am still new in the forum so i thought you were mentioning the whole "reasearch and developement" category, yet i couldn't find any keywords on the search.

well, you see, the project i am participating in is simple enough and I didn't need any ASM, only some simple XSE and now it is finally ending. Ye know, it's the kind of games that story and body movements have priority

ok I saw the post but i really can't understand shit :( , I can't find the 0x26CF8C or well, even when i find it in advancedmap it shows me a givegg command. 0_o

DizzyEgg November 11th, 2016 2:54 PM

Quote:

Originally Posted by Aenaos (Post 9483690)
wow dude chill, it was in 26 page of the quick research topic ( I am still new in the forum so i thought you were mentioning the whole "reasearch and developement" category, yet i couldn't find any keywords on the search.

well, you see, the project i am participating in is simple enough and I didn't need any ASM, only some simple XSE and now it is finally ending. Ye know, it's the kind of games that story and body movements have priority

ok I saw the post but i really can't understand **** :( , I can't find the 0x26CF8C or well, even when i find it in advancedmap it shows me a givegg command. 0_o

You need to open your rom in a hex editor(download HxD) and goto that address.

Scarlet D. November 11th, 2016 3:46 PM

Quote:

Originally Posted by DizzyEgg (Post 9483772)
You need to open your rom in a hex editor(download HxD) and goto that address.

great, i had it installed already but i don't know exactly how to use it. Seems like for some reason i can't find the offset 26CF8C ... how can i see the offsets between 26CF88 and 26CF90 :/

https://i37.servimg.com/u/f37/19/56/75/41/screen22.png

dammit... i feel such a noob when it comes for hex values

longlostsoldier November 11th, 2016 8:32 PM

I believe there is actually a trade editor tool out there. PGE can do it, for instance. It has a lot of tools and it's much quicker than hex. As a novice you'll probably find that easier. Heck, I can edit ASM a bit and /I/ still prefer tools most of the time when given the opportunity.

Blah November 12th, 2016 6:21 AM

Quote:

Originally Posted by Aenaos (Post 9483821)
great, i had it installed already but i don't know exactly how to use it. Seems like for some reason i can't find the offset 26CF8C ... how can i see the offsets between 26CF88 and 26CF90 :/

https://i37.servimg.com/u/f37/19/56/75/41/screen22.png

dammit... i feel such a noob when it comes for hex values

Right, so lets go through this step by step for you.

Initially, lets understand the script first:
Code:

'---------------
#org 0x16F602
lock
faceplayer
setvar 0x8008 0x0
call 0x81A8CAD
checkflag 0x248
if 0x1 goto 0x816F674
msgbox 0x81A597B MSG_YESNO '"I'm looking for the POKéMON\n[buff..."
....


I assume you are aware of what these scripting commands do. But I will explain to you how to edit this script in the way you wish.

At the start of the script, looking past the lock and faceplayer commands, var 0x8008 is set to 0 and we call another script. When you call a script, the initial location of the call is saved and the other script is executed with all the script variables and such intact. So basically it runs this other script at 0x1A8CAD to determine something and then checks a flag.

If this flag is set, then it does goto 0x816F674 - which is to the message "My old [buffer2] is great isn't it?". So the flag is most likely to indicate that you've already had a successful trade with the npc. But even more so, you'll notice that the NPC buffer's their former Pokemon's name! That means they must have retrieved the name prior. So far we know all of what has been executed doesn't deal with retrieving then name...except for that other script that was called at the start, 0x1A8CAD!

Code:

'---------------
#org 0x1A8CAD
copyvar 0x8004 0x8008
special2 LASTRESULT 0xFC
copyvar 0x8009 LASTRESULT
return


So you can see that it sets var 0x8004 to whatever var 0x8008 was, and then launched special2 with an arguement of the lastresult. I'll butt in here and say that special2 0xFC is hardcoded to use variable 0x8004, so the fact they've passed LASTRESULT means nothing, other than this should have been coded as just be a normal special rather than special2 :P
Anyways, I'm ranting, getting back to the point, 0x8004 is 0 and the special is called. The special's function is to load the Pokemon's name and species into special buffer. Buffer2 = name, Buffer3 = species. The value in 0x8004 determines which index of the table the Pokemon trade NPC is for. So since 0x8004 == 0, then it's clearly the first trade slot.

Cool, lets look at the table data doesnt documented again:
Quote:

In-game trades in FR are at 0x26CF8C. The scripts relating to them store very little information, and just index into this table. Each entry is 0x3C bytes, used as such:

0x0 - Nickname, limited to ten characters + 0xFF.
0xC - Half-word, ID of the NPC's pokemon.
0xE - IVs, stored in HP/Atk/Def/Speed/SAtk/SDef order. One byte each.
0x14 - An entire word dedicated to the ability bit.
0x18 - NPC's trainer ID. Only the low bits are visible on the status screen.
0x1C - Five bytes; four of them are 5 and one is 0x1E. Not sure what they do if anything.
0x24 - Personality value; influences nature, gender, etc; more info here: http://bulbapedia.bulbagarden.net/wiki/Personality_value
0x28 - Hold item.
0x2A - 0x00 if the mon carries mail (only ZYNX has mail in FR), 0xFF otherwise.
0x2B - Original trainer's name. Limited to seven characters + 0xFF.
0x36 - 0x00 if original trainer is male, 0x01 if original trainer is female. Only visible in RSE.
0x37 - Always 0xA. Not sure what it controls if anything.
0x38 - Half-word, ID of the species the NPC is looking for.
0x3A - Half-word, seems unused.
He mentions that each NPC's entry in the table is 0x3C bytes, that is to say the first NPC's data is in the first 0x3C bytes and the next NPC's data is in the 0x3C bytes after that and so on. So starting we do this operation to get the starting address of the Xth trade trainer Address = (0x26CF8C) + (0x3C * X). So in the case of the 0th entry (first entry) it's going to be 0x26CF8C + (0x3C *0) = 0x26CF8C.

On the very left column he has some numbers, these are the relative addresses for each entry. For example, the nickname is at 0x0 and NPC's Pokemon is that 0xC. So to get the Species ID of the Pokemon that trainer has, we do: (0x26CF8C + 0xC)

Doing that, we know var 0x8004 == 0, so this is the first trainer, their starting address is going to be at
address = (0x26CF8C) + (0x3C * 0)
address = 0x26CF8C

now we need to know what Pokemon they have with according to the post is the 0xCth value of that entry, so we add 0xC to the starting address to get the NPC's pokemon species.
npc's species = starting_address + 0xC
npc's species = 0x26CF8C + 0xC
npc's species = 0x26CF98

go to 0x26CF98, and you'll see the 2 bytes read 0x78 0x0. That means the species they have is 00 78 = 0x78 = MrMime. To edit the species this NPC gives away, you must edit the 0x78 0x0 then.

Do the same logical operation to edit what Pokemon the NC wants. "0x38 - Half-word, ID of the species the NPC is looking for."
--

Now let me show you something about the hex editor.

http://i.imgur.com/6d6MKgF.png
Clicking a byte or highlighting it will tell you what the offset of that value is. You see in the highlight it shows the byte I've highlighted is the 0x26CF80 byte. From 0x26CF80, fine 0x26CF8C by going through the subsequent bytes. Hint in your case, the amount of bytes you have to go through is just 0x26CF8C - 0x26CF88 = 0x4 :)

Scarlet D. November 12th, 2016 6:22 AM

Quote:

Originally Posted by longlostsoldier (Post 9484093)
I believe there is actually a trade editor tool out there. PGE can do it, for instance. It has a lot of tools and it's much quicker than hex. As a novice you'll probably find that easier. Heck, I can edit ASM a bit and /I/ still prefer tools most of the time when given the opportunity.

Some heroes don't wear capes bro! You just saved my life from an eternal hex headache XD

Quote:

Originally Posted by FBI (Post 9484418)
Right, so lets go through this step by step for you.

I am sorry for this FBI, PGE does the job when it comes to what you were saying. but, the guide you just wrote will make me clearly understand how the vars and hex editor values work so i will give it a try too ^^

thanks for you time!

Blah November 12th, 2016 6:34 AM

Quote:

Originally Posted by Aenaos (Post 9484421)
Some heroes don't wear capes bro! You just saved my life from an eternal hex headache XD

I am sorry for this FBI, PGE does the job when it comes to what you were saying. but, the guide you just wrote will make me clearly understand how the vars and hex editor values work so i will give it a try too ^^

thanks for you time!

np, you should still try to learn it this way incase you run into something there isn't a tool for :)


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


Like our Facebook Page Follow us on Twitter © 2002 - 2018 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2016 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.

Acknowledgements
Use of PokéCommunity Assets
vB Optimise by DragonByte Technologies Ltd © 2023.