Go Back   The PokéCommunity Forums > ROM Hacking > Tools, Tutorials & Resources
Reload this Page [Tutorial] Scripting Nicknames for New Pokemon (XSE) (FireRed/LeafGreen)

Notices
For all updates, view the main page.

Tools, Tutorials & Resources Various tools to help you develop your hacks can be found here.
New threads in this forum are to be approved by a moderator before they are displayed.



Reply
 
Thread Tools
  #1    
Old January 13th, 2014 (08:51 PM). Edited January 14th, 2014 by Butterslave.
Butterslave's Avatar
Butterslave Butterslave is offline
 
Join Date: Mar 2009
Gender: Male
Posts: 38
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:
  • 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.
Reply With Quote
  #2    
Old January 14th, 2014 (04:13 PM).
diegoisawesome's Avatar
diegoisawesome diegoisawesome is offline
Please understand
Silver Tier
 
Join Date: Dec 2007
Location: Goldenrod City, Johto
Age: 18
Gender: Male
Nature: Quirky
Posts: 971
Just as a recommendation, you should use setvar 0x8004 0x0 before the special in the first script; otherwise, 0x8004 is not necessarily already set to 0x0 and can still cause issues.
__________________


My other resources:
My Website
diegoisawesome's MEGA-HUGE XSE Scripting Tutorial
diegoisawesome's Miscellaneous Finds
The Ruins of Alph Puzzles
Diego's Miscellaneous Patches
GBA Intro Manager
Reply With Quote
  #3    
Old January 14th, 2014 (08:10 PM).
Butterslave's Avatar
Butterslave Butterslave is offline
 
Join Date: Mar 2009
Gender: Male
Posts: 38
Thanks! I completely forgot to put that in.
Reply With Quote
  #4    
Old January 17th, 2014 (06:20 AM).
Astraea's Avatar
Astraea Astraea is offline
The Storm of Friendship
 
Join Date: Sep 2013
Location: Otago, New Zealand
Age: 18
Gender: Male
Nature: Brave
Posts: 2,087
Send a message via Skype™ to Astraea
I didn't understand copy var and can you give a script by which an event will trigger when you'll have a bulbasaur with you and will not if you dont? And a script- Suppose if i have a bulbasaur then a bulbasaur OW will appear and if i have an ivysaur then ivysaur OW will appear!
__________________

'There is no age for evolution, when it comes to evolving yourself into a better person'
Reply With Quote
  #5    
Old January 17th, 2014 (01:59 PM). Edited January 17th, 2014 by Butterslave.
Butterslave's Avatar
Butterslave Butterslave is offline
 
Join Date: Mar 2009
Gender: Male
Posts: 38
Quote originally posted by IndianCharizard#:
I didn't understand copy var and can you give a script by which an event will trigger when you'll have a bulbasaur with you and will not if you dont? And a script- Suppose if i have a bulbasaur then a bulbasaur OW will appear and if i have an ivysaur then ivysaur OW will appear!
Okay, I will try to explain it more.

In truth, the simplest way to describe copyvar is that it tells the game to make a variable equal to the value of another variable. So, when we tell the game copyvar 0x8004 0x800D, we are telling it to make the value of 0x8004 equal to the value of 0x800D, which is the LASTRESULT. Again, this is crucial to understand - the variable 0x800D is the LASTRESULT.

So, in our script, what is the LASTRESULT? Since we used the command countpokemon, the LASTRESULT that the game acquired is simply the number of Pokemon in our party (in my example, I said I had 4 Pokemon in my party). Therefore, the game now knows that 4 is the value of the LASTRESULT, also known as 0x800D.

Remember, I said that a Pokemon's position in the party is equal to [Position] - 1. This can be confusing, I understand. Say I have a Pokemon in the 4th spot of my party. What does that mean? It means that, to the game, its actual position is 0x3, because [4] - 1 = 3, and 3 in hex is 0x3.

Now, when using copyvar, it must be written like this:
copyvar [variable you want to insert a value into] [variable from which you are copying a value].

So, knowing this, we use copyvar 0x8004 0x800D because we are telling the game to copy the value of 0x800D (LASTRESULT) and insert it into 0x8004. This is because 0x8004 is the variable used by the game when dealing with certain Pokemon in the party.

I hope that made things more clear. If not, I will continue to try to help. I am a patient person. It may also help to check out diegoisawesome's tutorial (the link can be found in my original post). He talks about copyvar as well.

Now, moving on to your other questions.

In order to do what you asked, you have to make the game check if you have Bulbasaur in your party.

This is done by first telling the game to set the variable 0x8004 equal to the value of Bulbasaur himself. What is Bulbasaur's value? It is his Pokemon number in hex. His Pokemon number is 1, so in hex it's 0x1. So, we would write: setvar 0x8004 0x1.


After this, we will use the command special2 0x800D 0x17C. This tells the game to check if the LASTRESULT (0x800D) is in your party. What is the LASTRESULT? It's 0x1. What is 0x1? It's Bulbasaur! 0x1 is the LASTRESULT observed by the game because we set the variable 0x8004 to the value of 0x1 in our last command.

Then, we use compare 0x800D 0x1. This, once again, tells the game to check if the LASTRESULT is true (remember, 0x1 when dealing with compare means true or yes).

Here is the full script that I wrote:
Spoiler:
#dynamic 0x800000

#org @start
setvar 0x8004 0x1
special2 0x800D 0x17C
compare 0x800D 0x1
if 0x1 goto @script
release
end

#org @script
msgbox @bulba 0x6
setvar 0x4039 0x2
release
end

#org @bulba
= Yes! I have a BULBASAUR!


So, if we have a Bulbasaur in our party, a message will be displayed that says "Yes! I have a BULBASAUR!" If not, nothing will happen. (At the end of the script I wrote setvar 0x4039 0x2 so that the script would not repeat itself.) Obviously, you could change the script to be much more than a simple message appearing. If you wanted you could make it a lot more complex, like including a trainerbattle or whatever.

As for making an OW sprite of Bulbasaur appear, you would have to import a Bulbasaur OW sprite into the game and then place it on a map in Advance Map. Then you'd have to make him invisible by either using a level script or strategically placed script tile(s) that hides the sprite and sets a flag. Then, when you would want Bulbasaur's sprite to show up, you would use the commands clearflag and showsprite.

Ask if you have more questions.
Reply With Quote
  #6    
Old January 17th, 2014 (03:33 PM).
Astraea's Avatar
Astraea Astraea is offline
The Storm of Friendship
 
Join Date: Sep 2013
Location: Otago, New Zealand
Age: 18
Gender: Male
Nature: Brave
Posts: 2,087
Send a message via Skype™ to Astraea
Quote originally posted by Butterslave:
Okay, I will try to explain it more. In truth, the simplest way to describe copyvar is that it tells the game to make a variable equal to the value of another variable. So, when we tell the game copyvar 0x8004 0x800D, we are telling it to make the value of 0x8004 equal to the value of 0x800D, which is the LASTRESULT. Again, this is crucial to understand - the variable 0x800D is the LASTRESULT. So, in our script, what is the LASTRESULT? Since we used the command countpokemon, the LASTRESULT that the game acquired is simply the number of Pokemon in our party (in my example, I said I had 4 Pokemon in my party). Therefore, the game now knows that 4 is the value of the LASTRESULT, also known as 0x800D. Remember, I said that a Pokemon's position in the party is equal to [Position] - 1. This can be confusing, I understand. Say I have a Pokemon in the 4th spot of my party. What does that mean? It means that, to the game, its actual position is 0x3, because [4] - 1 = 3, and 3 in hex is 0x3. Now, when using copyvar, it must be written like this: copyvar [variable you want to insert a value into] [variable from which you are copying a value]. So, knowing this, we use copyvar 0x8004 0x800D because we are telling the game to copy the value of 0x800D (LASTRESULT) and insert it into 0x8004. This is because 0x8004 is the variable used by the game when dealing with certain Pokemon in the party. I hope that made things more clear. If not, I will continue to try to help. I am a patient person. It may also help to check out diegoisawesome's tutorial (the link can be found in my original post). He talks about copyvar as well. Now, moving on to your other questions. In order to do what you asked, you have to make the game check if you have Bulbasaur in your party. This is done by first telling the game to set the variable 0x8004 equal to the value of Bulbasaur himself. What is Bulbasaur's value? It is his Pokemon number in hex. His Pokemon number is 1, so in hex it's 0x1. So, we would write: setvar 0x8004 0x1. After this, we will use the command special2 0x800D 0x17C. This tells the game to check if the LASTRESULT (0x800D) is in your party. What is the LASTRESULT? It's 0x1. What is 0x1? It's Bulbasaur! 0x1 is the LASTRESULT observed by the game because we set the variable 0x8004 to the value of 0x1 in our last command. Then, we use compare 0x800D 0x1. This, once again, tells the game to check if the LASTRESULT is true (remember, 0x1 when dealing with compare means true or yes). Here is the full script that I wrote:
Spoiler:
#dynamic 0x800000 #org @start setvar 0x8004 0x1 special2 0x800D 0x17C compare 0x800D 0x1 if 0x1 goto @script release end #org @script msgbox @bulba 0x6 setvar 0x4039 0x2 release end #org @bulba = Yes! I have a BULBASAUR!
So, if we have a Bulbasaur in our party, a message will be displayed that says "Yes! I have a BULBASAUR!" If not, nothing will happen. (At the end of the script I wrote setvar 0x4039 0x2 so that the script would not repeat itself.) Obviously, you could change the script to be much more than a simple message appearing. If you wanted you could make it a lot more complex, like including a trainerbattle or whatever. As for making an OW sprite of Bulbasaur appear, you would have to import a Bulbasaur OW sprite into the game and then place it on a map in Advance Map. Then you'd have to make him invisible by either using a level script or strategically placed script tile(s) that hides the sprite and sets a flag. Then, when you would want Bulbasaur's sprite to show up, you would use the commands clearflag and showsprite. Ask if you have more questions.
Well that enough info, i wanted but i'll contact you in the future for help.
__________________

'There is no age for evolution, when it comes to evolving yourself into a better person'
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

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 UTC -8. The time now is 05:09 PM.