Here is a trade script that was taken from in-game and explained in great detail by HackMew - You can see the original explanation by opening XSE's Guide (F2) and going inside the 'Practical Classroom' folder.
Code:
#org 0x16A9B1
lock // locks the sprite movement
faceplayer // sprite faces the player
setvar 0x8008 0x1 // sets value of variable 0x8008 to 0x1
call 0x81A8CAD // calls a branch before returning at 0x1A8CAD
checkflag 0x24A // the script returns and checks flag 0x24A
if 0x1 goto 0x816AA23 // if the flag is enabled goto 0x16AA23
msgbox 0x81A59FE MSG_YESNO '"Hello, there! Do you happen to\nha..." // asks a question - Yes/No
compare LASTRESULT 0x0 // compares LASTRESULT if its value is 0x0 - for No
if 0x1 goto 0x816AA0B // if LASTRESULT is 0x0 - No, the script jumps to 0x16AA0B if Yes then continues
call 0x81A8CBD // the result is Yes and again it jumps to another offset 0x1A8CBD
compare 0x8004 0x6 // compares 0x8004 if its equal to 0x6
if 0x4 goto 0x816AA0B // if the value of 0x8004 is smaller than equal to the script jumps to 0x16AA0B
call 0x81A8CC9 // calls another offset 0x1A8CC9
comparevars2 LASTRESULT 0x8009 // compares if the value LASTRESULT is equal to the value of 0x8009
if 0x5 goto 0x816AA15 // if LASTRESULT's value is not equal to value at 0x8009 script jumps to 0x16AA15
call 0x81A8CD9 // calls another branch of the script at 0x1A8CD9
msgbox 0x81A5A9D MSG_KEEPOPEN '"Thanks!" // displays a Keep Open msg at 0x1A5A9D
setflag 0x24A // sets flag 0x24A
release // sprite resumes movement and the textbox can be closed
end // ends script execution
'---------------
#org 0x1A8CAD
copyvar 0x8004 0x8008 // copies value of 0x8004 to 0x8008
special2 LASTRESULT 0xFC // script uses special2 0xfc to retain a returned value to LASTRESULT
copyvar 0x8009 LASTRESULT // copies value at 0x8009 to LASTRESULT
return // script returns where it was last called
'---------------
#org 0x16AA23
msgbox 0x81A5AA5 MSG_KEEPOPEN '"The [buffer2] that I traded you,\n..." // displays msg at 0x1A5AA5
release // sprite resumes movement and the textbox can be closed
end // ends script execution
'---------------
#org 0x16AA0B
msgbox 0x81A5A4E MSG_KEEPOPEN '"Well, if you don't want to[.]" // displays msg at 0x1A5A4E
release // sprite resumes movement and the textbox can be closed
end // ends script execution
'---------------
#org 0x1A8CBD
special 0x9F // script uses special 0x9f which chooses a pokemon in the party
waitstate // script is in waitstate waiting for the special
lock // locks the sprites movement
faceplayer // sprite faces the player
copyvar 0x800A 0x8004 // copies value at 0x800A to 0x8004
return // script returns where it was last called
'---------------
#org 0x1A8CC9
copyvar 0x8005 0x800A // copies value at 0x8005 to 0x800A
special2 LASTRESULT 0xFF // uses special 0xFF and stores returned value at LASTRESULT
copyvar 0x800B LASTRESULT // copies value at 0x800B to LASTRESULT
return // script returns where it was last called
'---------------
#org 0x16AA15
bufferpokemon 0x0 0x8009 // stores the pokemon name value in 0x8009 to [buffer1]
msgbox 0x81A5A6A MSG_KEEPOPEN '"Hmmm?\nThis isn't a [buffer1].\pTh..." // displays msg at 0x1A5A6A
release // sprite resumes movement and the textbox can be closed
end // ends script execution
'---------------
#org 0x1A8CD9
copyvar 0x8004 0x8008 // copies value at 0x8004 to 0x8008
copyvar 0x8005 0x800A // copies value at 0x8005 to 0x800A
special 0xFD // special 0xFD is used
special 0xFE // special 0xFE is also used
waitstate // script is in waiting state waiting for the specials
lock // locks the sprite
faceplayer // sprite faces the player
return // script returns where it was last called
'---------
' Strings
'---------
#org 0x1A59FE
= Hello, there! Do you happen to\nhave a [buffer1]?\pWould you agree to a trade for\nmy [buffer2]?
#org 0x1A5A9D
= Thanks!
#org 0x1A5AA5
= The [buffer2] that I traded you,\nhas it grown stronger?
#org 0x1A5A4E
= Well, if you don't want to[.]
#org 0x1A5A6A
= Hmmm?\nThis isn't a [buffer1].\pThink of me if you get one.
Its quite complicated, but you can use it a skeleton and just change the flags/ text each time, along with the value in the line 'setvar 0x8008 0x1' as it determines which trade you will be initiating. You can also view and change the Pokemon that are involved with the trade by using
ZodiacDaGreat's Trader Advanced.
If you want to take away a Pokemon then you can use HackMew's
ASM code or
metapod23's script.