• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Pokeemerald] Scripting Tutorial

19
Posts
7
Years
    • Seen Mar 29, 2024
    Your way to explain is pretty good.

    I'm not a native English speaker, and I've understood everything. I know how to script in binary hacking, but read this is very useful to introduce myself to the decomp scripting. I hope you will continue writing this tutorials. A loop tutorial would be great :)
     
    1,309
    Posts
    12
    Years
    • She/Her
    • Seen Nov 24, 2023
    Display Pokémon Sprite
    You might not use it too often throughout your hack, but showing a Pokémon's sprite can add a little something extra to scripts where the Pokémon is being discussed.
    Code:
    showmonpic [Pokémon], [X-Co-ord], [Y-Co-ord]
    So you need to specify the sprite you want to display and the X/Y co-ordinates of the screen where you want the box containing the sprite to be drawn. The Pokémon species list is in "include\constants\species.h" if you need it. And to hide the box again:
    Code:
    hidemonpic
    Nice and straight forward. A full script example:
    Code:
    Script_DisplaySpriteDemo::
    	lock
    	faceplayer
    	showmonpic SPECIES_DRATINI, 10, 3
    	msgbox Text_DisplaySpriteDemo, MSGBOX_DEFAULT
    	hidemonpic
    	release
    	end
    
    Text_DisplaySpriteDemo:
    	.string "Have you seen this Pokémon?$"
    Co-ordinates of 10, 3 will display the box containing the specified sprite in the middle of the screen. And that's pretty much it!
     
    Last edited by a moderator:
    1,309
    Posts
    12
    Years
    • She/Her
    • Seen Nov 24, 2023
    Screen Fading Effects
    It's easy to give the overworld a "fading out" effect - useful for cutscenes and such - by using the fadescreen command which looks like this:
    Code:
    fadescreen [Fade Type Number]
    What do I mean by "fade type number"? Here are the numbers for fading out to black and then reverting to normal:
    Avara said:
    fadescreen 1 – Screen fades to black.
    fadescreen 0 - Screen fades from black back to normal.
    Time for an example script and gif so you can see how it looks in-game!
    Code:
    Script_FadescreenExample::
    	msgbox Text_FadescreenExample, MSGBOX_DEFAULT
    	fadescreen 1
    	fadescreen 0
    	end
    
    Text_FadescreenExample:
    	.string "Screen fading to black.$"
    Scripting Tutorial

    It's also possible to create a white version of the same effect by swapping out the 1 and 0 for 3 and 2 respectively.
    Code:
    Script_FadescreenExample::
    	msgbox Text_FadescreenExample, MSGBOX_DEFAULT
    	fadescreen 3
    	fadescreen 2
    	end
    
    Text_FadescreenExample:
    	.string "Screen fading to white.$"
    Scripting Tutorial

    To serve as a reminder, here is a list of all the fadescreen types for quick reference:
    Avara said:
    fadescreen 3 – Screen fades to white.
    fadescreen 2 – Screen fades from white back to normal.

    fadescreen 1 – Screen fades to black.
    fadescreen 0 - Screen fades from black back to normal.
     
    1,309
    Posts
    12
    Years
    • She/Her
    • Seen Nov 24, 2023
    Play Pokémon Cry
    Using Pokémon cries as a sound effect is another super easy thing to do, all you need is the playmoncry command:
    Code:
    playmoncry [Pokémon], 0
    Followed by waitmoncry, which doesn't have any arguments. Just as it looks, it simply means the script will continue after the cry has finished playing.
    Code:
    Script_CryDemo::
    	lock
    	faceplayer
    	playmoncry SPECIES_ARBOK, 0
    	msgbox Text_CryDemo, MSGBOX_DEFAULT
    	waitmoncry
            closemessage
    	release
    	end
    
    Text_CryDemo:
    	.string "Arbok: Hisssss!$"
    Shouldn't need much explanation, but I'll break it down just in case: Arbok's cry will play, a message box will appear as the cry plays and will close once the cry has finished playing.
     
    180
    Posts
    6
    Years
    • Seen Apr 15, 2024
    Now, i have to say
    This is truly amazing, but there's also a "addobject [id]" and a "hideobjectat [id], [mapname]" functions. both of them are very useful and both helped me with a Wally event that i was doing
     
    1,309
    Posts
    12
    Years
    • She/Her
    • Seen Nov 24, 2023
    Diego Mertens said:
    Now, i have to say
    This is truly amazing, but there's also a "addobject [id]" and a "hideobjectat [id], [mapname]" functions. both of them are very useful and both helped me with a Wally event that i was doing
    Definitely true! This amongst many other things was something I'd planned to add on to this tutorial. However, seeing as other scripting systems have recently been created for the decomps - such as PoryScript and Dragonsbreath - I decided it might not be worth updating this guide as much if those were to be more widely used, in case I was wasting my time writing a tutorial for something that'd soon be obsolete and not relevant. Will wait a little while and see what happens. Here's to the future!
     
    Last edited:
    53
    Posts
    5
    Years
    • Seen Mar 9, 2022
    Definitely true! This amongst many other things was something I'd planned to add on to this tutorial. However, seeing as other scripting systems have recently been created for the decomps - such as PoryScript and Dragonsbreath - I decided it might not be worth updating this guide as much if those were to be more widely used, in case I was wasting my time writing a tutorial for something that'd soon be obsolete and not relevant. Will wait a little while and see what happens. Here's to the future!

    Poryscript still uses these same commands with just parentheses to enclose the arguments, so it's well-worth maybe even slightly gearing your tutorial towards it as the main difference lies in easier conditional checking.
     
    50
    Posts
    6
    Years
    • Seen Oct 20, 2023
    Poryscript still uses these same commands with just parentheses to enclose the arguments, so it's well-worth maybe even slightly gearing your tutorial towards it as the main difference lies in easier conditional checking.

    Well, it does a little more than that. Adding branch controls and loop and making goto obsolate for example. With the same mindset one could say the same about decomp scripting and classical XSE scripts, since the default commands stay the same.
     
    180
    Posts
    6
    Years
    • Seen Apr 15, 2024
    Giving Eggs
    This section will cover how to give your player a Pokémon Egg.
    Code:
    giveegg [Pokémon]
    Super easy.
    Code:
    Script_GiveEggDemo::
    	lock
    	faceplayer
    	msgbox Text_EggQuestion, MSGBOX_YESNO
    	compare VAR_RESULT, 0
    	goto_if_eq Script_PlayerAnsweredNo
    	getpartysize
    	compare VAR_RESULT, 6
    	goto_if_eq Script_PlayerHasFullParty
    	giveegg SPECIES_LARVITAR
    	playfanfare MUS_FANFA4
    	msgbox Text_ReceivedEgg, MSGBOX_DEFAULT
    	waitfanfare
    	release
    	end
    
    Script_PlayerHasFullParty::
    	msgbox Text_PlayerHasFullParty, MSGBOX_DEFAULT
    	release
    	end
    
    Script_PlayerAnsweredNo::
    	msgbox Text_PlayerAnsweredNo, MSGBOX_DEFAULT
    	release
    	end
    
    Text_EggQuestion:
    	.string "Will you take this Egg?$"
    
    Text_PlayerAnsweredNo:
    	.string "Oh, that's too bad.$"
    
    Text_ReceivedEgg:
    	.string "{PLAYER} received the Egg!$"
    
    Text_PlayerHasFullParty:
    	.string "Your party is full.\n"
    	.string "There's no room for this Egg.$"
    If you've read the other sections of the tutorial, you'll see that this script asks the player whether or not they would like to accept the Egg. After that, if the player responds with "YES", it'll check if they have space in their party before giving it to them. I also already explained how to use getpartysize in the Giving Pokémon section, so I won't bother going over that again.

    How do I set up Egg moves for them?
    Like, I want to give the player X Pokémon that knows moves that can only be learned via breeding... How can I do this?
     

    Lunos

    Random Uruguayan User
    3,114
    Posts
    15
    Years
  • How do I set up Egg moves for them?
    Like, I want to give the player X Pokémon that knows moves that can only be learned via breeding... How can I do this?
    There's the setmonmove command which you can probably use for that task. By default, it's used to give a Pichu Egg via Mystery Event that knows Surf, apparently.
    At first glance, it looks like the arguments the macro needs seem to be the Party Slot where your Egg is in, followed by the move slot you want the move to be set in and then stating the desired move.

    For more information, look into the data/scripts/mevent_pichu.inc file if you're using Pokeemerald.
     
    Last edited:
    4
    Posts
    4
    Years
    • Seen Apr 29, 2020
    Is there a way to find out which Offsets in the compiled rom belongs to which data in the disassembly?
    I ask that becuse I try to fix Emeralds faulty PRNG in pokeemerald.
    I found a fix from HackMew (Search in your Browser for 'Pokemon Emerald RNG fix' (Sorry, I can't post links because I haven't made 5 posts)).
    The problem is that the fix is for a compiled rom and I don't now where the routines are in pokeemerald that I must edit.
     
    2
    Posts
    7
    Years
    • Seen Nov 24, 2021
    Is there a way to find out which Offsets in the compiled rom belongs to which data in the disassembly?
    I ask that becuse I try to fix Emeralds faulty PRNG in pokeemerald.
    I found a fix from HackMew (Search in your Browser for 'Pokemon Emerald RNG fix' (Sorry, I can't post links because I haven't made 5 posts)).
    The problem is that the fix is for a compiled rom and I don't now where the routines are in pokeemerald that I must edit.

    You can fix the RNG by editing main.c and specifically putting the line
    Code:
    SeedRngWithRtc();
    below
    Code:
    InitMapMusic();
     
    180
    Posts
    6
    Years
    • Seen Apr 15, 2024
    How do I move the camera?
    Like, I want to show something that the player can't usually see, and I want to move the camera...
     
    4
    Posts
    4
    Years
    • Seen Apr 29, 2020
    It generates me an error, saying that it's not definied
    .
    That happens because SeedRngWithRtc(); is defined only in Ruby and Sapphire.
    In Emerald the developers removed the routine and replaced by SeedRngAndSetTrainerId(), which they copied from Firered/Leafgreen.
    Interestingly SeedRngAndSetTrainerId(); isn't used in src/main.c in pokefirered.
    Instead it is used in main/title_screen.c, in the routine SetTitleScreenScene_Cry(s16 * data) in case 2.
    This was forgotten in pokeemerald and causes the bug. The routine SetTitleScreenScene_Cry(s16 * data) doesn't exist in main/title_screen.c in pokeemerald.
    so to fix that put SeedRngAndSetTrainerId() between static void Task_TitleScreenPhase3(u8 taskId)
    {
    and if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & START_BUTTON)).
    Alternatively you could do what TetsuyaGR did, just with SeedRngAndSetTrainerId(); instead of SeedRngWithRtc();, that would work as well.

    Edit: That fix is not working.
     
    Last edited:
    180
    Posts
    6
    Years
    • Seen Apr 15, 2024
    .
    That happens because SeedRngWithRtc(); is defined only in Ruby and Sapphire.
    In Emerald the developers removed the routine and replaced by SeedRngAndSetTrainerId(), which they copied from Firered/Leafgreen.
    Interestingly SeedRngAndSetTrainerId(); isn't used in src/main.c in pokefirered.
    Instead it is used in main/title_screen.c, in the routine SetTitleScreenScene_Cry(s16 * data) in case 2.
    This was forgotten in pokeemerald and causes the bug. The routine SetTitleScreenScene_Cry(s16 * data) doesn't exist in main/title_screen.c in pokeemerald.
    so to fix that put SeedRngAndSetTrainerId() between static void Task_TitleScreenPhase3(u8 taskId)
    {
    and if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & START_BUTTON)).
    Alternatively you could do what TetsuyaGR did, just with SeedRngAndSetTrainerId(); instead of SeedRngWithRtc();, that would work as well.

    Edit: That fix is not working.
    i already fixed it, and it's as simple as adding also the RS function and calling it where you described, since is what was left abandoned... and also a little tweaks in the SeedRngAndSetTrainerId thing, but it easy.
     
    11
    Posts
    4
    Years
    • Seen Jul 24, 2021
    Hi. I copy and past the script for givemon but when i complie. Giveme a error in the line of the givemon saying it has to many parameters. Do yo know what could happens?
     
    1,591
    Posts
    10
    Years
    • Seen Mar 20, 2024
    Hi. I copy and past the script for givemon but when i complie. Giveme a error in the line of the givemon saying it has to many parameters. Do yo know what could happens?

    Hey, givemon has less been changed to take less input parameters, so instead of:
    Code:
    givemon SPECIES_DRATINI, 5, ITEM_DRAGON_FANG, 0x0, 0x0, 0
    you'd just do:
    Code:
    givemon SPECIES_DRATINI, 5, ITEM_DRAGON_FANG
     
    11
    Posts
    4
    Years
    • Seen Jul 24, 2021
    Thanks but When i do that. And compile the script, give me another error saying my script has no reference to event_script. When i go to the event file in the map theres the script listed but still cant do it work.
     
    1,591
    Posts
    10
    Years
    • Seen Mar 20, 2024
    Thanks but When i do that. And compile the script, give me another error saying my script has no reference to event_script. When i go to the event file in the map theres the script listed but still cant do it work.
    Could you post your whole script, or the lines that are giving you the error? Can't tell you exactly what that means without seeing your code.
     
    Back
    Top