- 78
- Posts
- 16
- Years
- Texas, USA
- Seen Feb 27, 2022
I'm fairly average when it comes to my knowledge of scripting, and one thing that caused me some difficulty was successfully writing a script that allowed me to nickname a Pokemon that an NPC had given me after I already had Pokemon in my party. Time and time again I found myself staring at the "????????" on the nickname screen or nicknaming the Pokemon that was in the first position in my party instead of the one I had just received. After finally discovering the answer by dissecting different posts of different threads, I understand perfectly how it works.
Before we get started, here are the two main tutorials that I used to learn how to script using XSE:
diegoisawesome's Scripting Tutorial
tajaros's Scripting Tutorial
Please use these if you don't have a basic knowledge of scripting, as I will not be going over the fundamentals.
The two topics I'll be addressing:
First Pokemon You Receive
If you have a basic knowledge of scripting, you should have no difficulty writing a script that includes a nickname option for, say, the starter Pokemon in your hack. That being said, I might as well go over it a little bit.
#dynamic 0x800000
#org @start
checkflag 0x828
if 0x1 goto @done
msgbox @givepoke 0x2
setflag 0x828
givepokemon 0x1 0x5 0x0 0x0 0x0 0x0
fanfare 0x13E
msgbox @received 0x4
waitfanfare
closeonkeypress
msgbox @givenickname 0x5
compare 0x800D 0x1
if 0x1 call @nickname
release
end
#org @nickname
setvar 0x8004 0x0
fadescreen 0x1
special 0x9E
waitstate
return
#org @done
msgbox @alreadygave 0x2
release
end
#org @givepoke
= Here is your starter POKéMON.
#org @received
= [player] received a BULBASAUR!
#org @givenickname
= Would you like to give a nickname\nto BULBASAUR?
#org @alreadygave
= I already gave you your starter!
Firstly we see the flag 0x828. For Fire Red/Leaf Green hackers, this is the flag for enabling the Pokemon menu. You can find the flags for other games in the above tutorials I mentioned.
compare 0x800D 0x1 follows. 0x800D is the variable for LASTRESULT, and 0x1 means true or yes. So what the script is telling the game here is basically this: Compare the last result to the answer "Yes."
The next line says if 0x1 call @nickname. So the script is telling the game: If the answer was "Yes" (0x1), call the pointer @nickname. If the answer was not "Yes," the script releases the player and ends.
Now we call the @nickname pointer and setvar 0x8004 0x0, which is needed in order to tell the game the position of a Pokemon in our party. The rule for the value that describes a Pokemon's place in the party will be explained a bit later. Then we see the generic fadescreen 0x1 effect, and then special 0x9E. Once again, this is the command for the nickname event in Fire Red/Leaf Green. waitstate will make the game wait until you're done with the nickname, and return should be obvious to those who know the basics of scripting.
So there you have it. That's all there is to nicknaming the first Pokemon to arrive in your party. Now comes the part that gave me so much grief.
Pokemon You Receive in the Middle of the Game
The key commands we'll be going over are countpokemon, subvar and copyvar.
#dynamic 0x800000
#org @start
checkflag 0x828
if 0x1 goto @givepoke
msgbox @hello 0x2
release
end
#org @givepoke
checkflag 0x203
if 0x1 goto @how
msgbox @givebuzz 0x2
countpokemon
compare 0x800D 0x6
if 0x1 goto @toomany
setflag 0x203
givepokemon 0x7D 0x19 0x0 0x0 0x0 0x0
fanfare 0x13E
msgbox @received 0x4
waitfanfare
closeonkeypress
msgbox @givenickname 0x5
compare 0x800D 0x1
if 0x1 goto @nickname
release
end
#org @nickname
countpokemon
subvar 0x800D 0x1
copyvar 0x8004 0x800D
call @name
release
end
#org @name
fadescreen 0x1
special 0x9E
waitstate
return
#org @how
msgbox @howpoke 0x2
release
end
#org @toomany
msgbox @noroom 0x2
release
end
#org @hello
= Good day to you!
#org @givebuzz
= I want you to have this POKéMON.
#org @noroom
= You have no room for it!
#org @received
= [player] received an ELECTABUZZ!
#org @givenickname
= Would you like to give a nickname\nto ELECTABUZZ?
#org @howpoke
= How is my old POKéMON?
The first difference we see here is that I entered the command countpokemon. Obviously this tells the game to count the number of Pokemon in my party. The command after that in the script is compare 0x800D 0x6, which just tells the game to compare the LASTRESULT (which is the number of Pokemon in our party) to the number 6. This little portion isn't relevant to the nickname business I'm covering. This is simply telling the game that, if you have 6 Pokemon in your party already, you will not receive the Pokemon and a message will be displayed that says, "You have no room for it!"
Okay, now we'll go on to the nickname stuff.
Later on down in the script, after we call the pointer @nickname, we see countpokemon again, and then we see subvar 0x800D 0x1. This command tells the game to subtract 1 from the LASTRESULT observed, which is simply the number of Pokemon in our party (because of countpokemon). So, say for example, we have 4 Pokemon in our party (including the one we just received and want to nickname - in this case, ELECTABUZZ). The command countpokemon tells the game that we do indeed have 4 Pokemon in our party. Then, subvar 0x800D 0x1 subtracts 1 from that number, so the game has now stored the value of 3. This is relevant because a Pokemon's position in the party lineup is actually equal to [Position] - 1. diegoisawesome pointed this out in his tutorial.
Now, the Pokemon we just received and want to nickname is indeed the 4th Pokemon in our party. However, because of the rule [Position] - 1, its actual position in our party is read by the game as 0x3, not 0x4.
Because of this, we use copyvar 0x8004 0x800D. This copies the value of 0x3 and essentially "pastes" it into the variable 0x8004. So now the game knows that we will be nicknaming the Pokemon in position 0x3 of our party.
After all that, the script proceeds to use special 0x9E. The nickname command should run smoothly and you should be able to nickname the Pokemon you just received instead of something else, like "?????" or the first Pokemon in your party.
I do hope this helped some newbies like me understand how to efficiently write a full givepokemon script with a smooth nickname command and all. If you have questions feel free to ask, of course. This was my first tutorial so I'm sure it was very rough around the edges.
Before we get started, here are the two main tutorials that I used to learn how to script using XSE:
diegoisawesome's Scripting Tutorial
tajaros's Scripting Tutorial
Please use these if you don't have a basic knowledge of scripting, as I will not be going over the fundamentals.
The two topics I'll be addressing:
- Nickname Script for the First Pokemon You Receive
- Nickname Script for a Pokemon You Receive in the Middle of the Game
First Pokemon You Receive
If you have a basic knowledge of scripting, you should have no difficulty writing a script that includes a nickname option for, say, the starter Pokemon in your hack. That being said, I might as well go over it a little bit.
Spoiler:
#dynamic 0x800000
#org @start
checkflag 0x828
if 0x1 goto @done
msgbox @givepoke 0x2
setflag 0x828
givepokemon 0x1 0x5 0x0 0x0 0x0 0x0
fanfare 0x13E
msgbox @received 0x4
waitfanfare
closeonkeypress
msgbox @givenickname 0x5
compare 0x800D 0x1
if 0x1 call @nickname
release
end
#org @nickname
setvar 0x8004 0x0
fadescreen 0x1
special 0x9E
waitstate
return
#org @done
msgbox @alreadygave 0x2
release
end
#org @givepoke
= Here is your starter POKéMON.
#org @received
= [player] received a BULBASAUR!
#org @givenickname
= Would you like to give a nickname\nto BULBASAUR?
#org @alreadygave
= I already gave you your starter!
Firstly we see the flag 0x828. For Fire Red/Leaf Green hackers, this is the flag for enabling the Pokemon menu. You can find the flags for other games in the above tutorials I mentioned.
compare 0x800D 0x1 follows. 0x800D is the variable for LASTRESULT, and 0x1 means true or yes. So what the script is telling the game here is basically this: Compare the last result to the answer "Yes."
The next line says if 0x1 call @nickname. So the script is telling the game: If the answer was "Yes" (0x1), call the pointer @nickname. If the answer was not "Yes," the script releases the player and ends.
Now we call the @nickname pointer and setvar 0x8004 0x0, which is needed in order to tell the game the position of a Pokemon in our party. The rule for the value that describes a Pokemon's place in the party will be explained a bit later. Then we see the generic fadescreen 0x1 effect, and then special 0x9E. Once again, this is the command for the nickname event in Fire Red/Leaf Green. waitstate will make the game wait until you're done with the nickname, and return should be obvious to those who know the basics of scripting.
So there you have it. That's all there is to nicknaming the first Pokemon to arrive in your party. Now comes the part that gave me so much grief.
Pokemon You Receive in the Middle of the Game
The key commands we'll be going over are countpokemon, subvar and copyvar.
Spoiler:
#dynamic 0x800000
#org @start
checkflag 0x828
if 0x1 goto @givepoke
msgbox @hello 0x2
release
end
#org @givepoke
checkflag 0x203
if 0x1 goto @how
msgbox @givebuzz 0x2
countpokemon
compare 0x800D 0x6
if 0x1 goto @toomany
setflag 0x203
givepokemon 0x7D 0x19 0x0 0x0 0x0 0x0
fanfare 0x13E
msgbox @received 0x4
waitfanfare
closeonkeypress
msgbox @givenickname 0x5
compare 0x800D 0x1
if 0x1 goto @nickname
release
end
#org @nickname
countpokemon
subvar 0x800D 0x1
copyvar 0x8004 0x800D
call @name
release
end
#org @name
fadescreen 0x1
special 0x9E
waitstate
return
#org @how
msgbox @howpoke 0x2
release
end
#org @toomany
msgbox @noroom 0x2
release
end
#org @hello
= Good day to you!
#org @givebuzz
= I want you to have this POKéMON.
#org @noroom
= You have no room for it!
#org @received
= [player] received an ELECTABUZZ!
#org @givenickname
= Would you like to give a nickname\nto ELECTABUZZ?
#org @howpoke
= How is my old POKéMON?
The first difference we see here is that I entered the command countpokemon. Obviously this tells the game to count the number of Pokemon in my party. The command after that in the script is compare 0x800D 0x6, which just tells the game to compare the LASTRESULT (which is the number of Pokemon in our party) to the number 6. This little portion isn't relevant to the nickname business I'm covering. This is simply telling the game that, if you have 6 Pokemon in your party already, you will not receive the Pokemon and a message will be displayed that says, "You have no room for it!"
Okay, now we'll go on to the nickname stuff.
Spoiler:
You might recall that in the first script explained in this tutorial, we used setvar 0x8004 0x0. This is because we wanted to set the variable 0x8004 to value 0x0, which is the first position in your party. So, basically, we told the game that we wanted to target the Pokemon in that first position. However, more is needed if you want to tell the game to nickname a Pokemon in, say, the 4th position of your party, which will be explained now.
Later on down in the script, after we call the pointer @nickname, we see countpokemon again, and then we see subvar 0x800D 0x1. This command tells the game to subtract 1 from the LASTRESULT observed, which is simply the number of Pokemon in our party (because of countpokemon). So, say for example, we have 4 Pokemon in our party (including the one we just received and want to nickname - in this case, ELECTABUZZ). The command countpokemon tells the game that we do indeed have 4 Pokemon in our party. Then, subvar 0x800D 0x1 subtracts 1 from that number, so the game has now stored the value of 3. This is relevant because a Pokemon's position in the party lineup is actually equal to [Position] - 1. diegoisawesome pointed this out in his tutorial.
Now, the Pokemon we just received and want to nickname is indeed the 4th Pokemon in our party. However, because of the rule [Position] - 1, its actual position in our party is read by the game as 0x3, not 0x4.
Because of this, we use copyvar 0x8004 0x800D. This copies the value of 0x3 and essentially "pastes" it into the variable 0x8004. So now the game knows that we will be nicknaming the Pokemon in position 0x3 of our party.
After all that, the script proceeds to use special 0x9E. The nickname command should run smoothly and you should be able to nickname the Pokemon you just received instead of something else, like "?????" or the first Pokemon in your party.
I do hope this helped some newbies like me understand how to efficiently write a full givepokemon script with a smooth nickname command and all. If you have questions feel free to ask, of course. This was my first tutorial so I'm sure it was very rough around the edges.
Last edited: