• 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

11
Posts
4
Years
    • Seen Jul 24, 2021
    It was a dumb mistake, i was miss a reference in text part of the script
     

    NielsM

    BSBob
    12
    Posts
    7
    Years
  • How do map scripts work? I can't really figure it out by looking at other maps and all my tests end in a black screen when i enter the map.
    Thanks in advance
     

    Jaizu

    Average rom hacker
    281
    Posts
    14
    Years
  • How do map scripts work? I can't really figure it out by looking at other maps and all my tests end in a black screen when i enter the map.
    Thanks in advance

    You can try looking at this one as base, it has two types of scripts. One loading before transition and one after: https://pastebin.com/raw/YfS3twh3
    Also this:
    Code:
    #define MAP_SCRIPT_ON_LOAD 1 // Stuff that player isn't supposed to see, like setmaptiles
    #define MAP_SCRIPT_ON_FRAME_TABLE 2 // Runs after fadein finishes
    #define MAP_SCRIPT_ON_TRANSITION 3
    #define MAP_SCRIPT_ON_WARP_INTO_MAP_TABLE 4 // Runs before fadein finishes
    #define MAP_SCRIPT_ON_RESUME 5
    #define MAP_SCRIPT_ON_DIVE_WARP 6
    #define MAP_SCRIPT_ON_RETURN_TO_FIELD 7
     

    NielsM

    BSBob
    12
    Posts
    7
    Years
  • You can try looking at this one as base, it has two types of scripts. One loading before transition and one after: https://pastebin.com/raw/YfS3twh3
    Also this:
    Code:
    #define MAP_SCRIPT_ON_LOAD 1 // Stuff that player isn't supposed to see, like setmaptiles
    #define MAP_SCRIPT_ON_FRAME_TABLE 2 // Runs after fadein finishes
    #define MAP_SCRIPT_ON_TRANSITION 3
    #define MAP_SCRIPT_ON_WARP_INTO_MAP_TABLE 4 // Runs before fadein finishes
    #define MAP_SCRIPT_ON_RESUME 5
    #define MAP_SCRIPT_ON_DIVE_WARP 6
    #define MAP_SCRIPT_ON_RETURN_TO_FIELD 7

    thanks for the help, i didn't get the notation at first and i couldnt remember the types, but now i do!
     

    pokefreak890

    The One that will make everything great
    853
    Posts
    9
    Years
    • Seen May 18, 2023
    i still seem to be confused because im trying to add the megastones around the region and i used the giveitem_std command so when i put it in for the venusaurite and i tried to make the rom i got an error bad intrusion for it not sure where im supposed to put it and do i need to find free space myself for the rom to put it in or does it automatically do it for me???

    i want to know more about this as well because i do want to add legendaries as well in these routes so it would be helpful if i can understanding it better
     
    53
    Posts
    5
    Years
    • Seen Mar 9, 2022
    giveitem_std has been renamed to giveitem so "Error bad instruction" means the command isn't a valid one.

    Also no free space management is required for decomps! It automatically moves everything around to fit your new added stuff.
     
    55
    Posts
    14
    Years
    • Seen Feb 1, 2023
    Is givepcitem <item>, <quantity> still a valid command? I'm getting
    Code:
    Error: bad instruction `givepcitem 254,1'
    when I compile.
     
    Last edited:
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    Is givepcitem <item>, <quantity> still a valid command? I'm getting
    Code:
    Error: bad instruction `givepcitem 254,1'
    when I compile.

    It's probably called addpcitem now, based on asm/macros/event.inc.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    Note that in January of 2020 some of the commands were renamed in this commit and this commit. The upshot is the command names are add/remove instead of give/take in many cases now. So for example if takeitem doesn't work, try removeitem and vice-versa.
     
    2
    Posts
    3
    Years
  • When i try to draw a sprite on screen i get a compiler error
    data/maps/LittlerootTown/scripts.inc:1082: Error: bad instruction `drawmonpic 147,10,3'
    data/maps/LittlerootTown/scripts.inc:1087: Error: bad instruction `erasemonpic'
    Heres what my script looks like that has the drawmonpic
    Script_OgSS_1::
    lock
    faceplayer
    goto_if_set FLAG_UNUSED_0x2BB , Script_OgSS_Off
    goto_if_set FLAG_UNUSED_0x2BA , Script_OgSS_Off
    drawmonpic SPECIES_DRATINI, 10, 3
    msgbox Text_OgSS_1_YN, MSGBOX_YESNO
    compare VAR_RESULT, 0
    goto_if_eq Script_TakePkmn_1_No
    goto_if_ne Script_TakePkmn_1_Yes
    erasemonpic
    release
    end
     

    Lunos

    Random Uruguayan User
    3,114
    Posts
    15
    Years
  • When i try to draw a sprite on screen i get a compiler error
    data/maps/LittlerootTown/scripts.inc:1082: Error: bad instruction `drawmonpic 147,10,3'
    data/maps/LittlerootTown/scripts.inc:1087: Error: bad instruction `erasemonpic'

    Heres what my script looks like that has the drawmonpic
    Script_OgSS_1::
    lock
    faceplayer
    goto_if_set FLAG_UNUSED_0x2BB , Script_OgSS_Off
    goto_if_set FLAG_UNUSED_0x2BA , Script_OgSS_Off
    drawmonpic SPECIES_DRATINI, 10, 3
    msgbox Text_OgSS_1_YN, MSGBOX_YESNO
    compare VAR_RESULT, 0
    goto_if_eq Script_TakePkmn_1_No
    goto_if_ne Script_TakePkmn_1_Yes
    erasemonpic
    release
    end
    At some point after Avara wrote this tutorial, those commands were renamed. In Pokeemerald, they're showmonpic and hidemonpic now.
    https://github.com/pret/pokeemerald/blob/master/asm/macros/event.inc#L906
    https://github.com/pret/pokeemerald/blob/master/asm/macros/event.inc#L914
     
    24
    Posts
    3
    Years
    • Seen Aug 30, 2021
    How does the base game handle items in lying on the ground in Pokeballs? I was looking in the base game map scripts, but it looks like those functions are defined elsewhere
     
    24
    Posts
    3
    Years
    • Seen Aug 30, 2021
    Actually, I just found where they are!
    *\data\scripts\item_ball_scripts.inc

    Route104_EventScript_ItemPokeBall:: @ 8290D0C
    finditem ITEM_POKE_BALL
    end

    Do I need to define them here or is it okay for them to hang out in the map script files?
     
    1,309
    Posts
    12
    Years
    • She/Her
    • Seen Nov 24, 2023
    Actually, I just found where they are!
    *\data\scripts\item_ball_scripts.inc



    Do I need to define them here or is it okay for them to hang out in the map script files?

    You could put them in map script files if you wanted, personally I leave them in the .inc for tidiness/so I know they're all in the one spot :)
     
    24
    Posts
    3
    Years
    • Seen Aug 30, 2021
    How do I tell the game to start a double battle when you're in sight of two trainers at once?
     
    1,309
    Posts
    12
    Years
    • She/Her
    • Seen Nov 24, 2023
    How do I tell the game to start a double battle when you're in sight of two trainers at once?

    Sorry I'm so late responding to your question! All I did was ensure that the sight view radius was the same on each trainer and then set them up so they were across from each other and that seemed to work fine on its own. You've probably found that out by now but just in case anyone else wanted to know.
     
    1,309
    Posts
    12
    Years
    • She/Her
    • Seen Nov 24, 2023
    Time-based Scripts
    The gettime command can be used to set the values of variables 0x8000, 0x8001, and 0x8002 to the in-game hour, minute, and second respectively. This is an example script for a NPC who gives different greetings depending on the hour.
    Code:
    Script_HourDemonstration::
    	lock
    	faceplayer
    	gettime
    	compare VAR_0x8000, 4
    	goto_if_le Script_Night
    	compare VAR_0x8000, 12
    	goto_if_lt Script_Morning
    	compare VAR_0x8000, 18
    	goto_if_ge Script_Night
    	msgbox Text_Day, MSGBOX_DEFAULT
    	release
    	end
    
    Script_Morning::
    	msgbox Text_Morning, MSGBOX_DEFAULT
    	release
    	end
    
    Script_Night::
    	msgbox Text_Night, MSGBOX_DEFAULT
    	release
    	end
    
    Text_Morning:
    	.string "Good morning.$"
    
    Text_Day:
    	.string "Good day.$"
    
    Text_Night:
    	.string "Good evening.$"
    You could swap out the values to check for a particular minute or second too, if you wanted to run a very specific event that only occurs at a very specific time!
     
    1,309
    Posts
    12
    Years
    • She/Her
    • Seen Nov 24, 2023
    Fanfares

    First things first, you can find a list of labels for sound effects and music in "include\constants\songs.h".

    In not so many words a fanfare is a short jingle, for example, the healing sound in Pokémon Centers. To use one in your script, use these commands:
    Code:
    playfanfare [Label]
    waitfanfare
    waitfanfare means the script will wait for the jingle to finish playing before continuing. So, let's say we wanted to play the fanfare sound for obtaining a Gym Badge.
    Code:
    playfanfare MUS_OBTAIN_BADGE
    waitfanfare
    And that's it!

    Sound Effects

    Sound effects can bring a lot of life to overworld gameplay. For sounds, we'd use the following:
    Code:
    playse [Label]
    That's all. If you want to make the script wait for the sound to finish before continuing, you can add waitse if you want to. For example, if you'd have liked to use a sound effect for an exclamation point emote on your player:
    Code:
    ...
    playse SE_PIN
    applymovement OBJ_EVENT_ID_PLAYER, Movement_ResidenceHalls_Dorm_Exclamation
    waitmovement 0
    ...
    
    Movement_Exclamation:
    	emote_exclamation_mark
    	step_end
     
    4
    Posts
    3
    Years
    • Seen Aug 19, 2021
    Hello,

    Thank you very much for these, they are very useful and easy to understand !

    I was moving things around in Littleroot Town inside porymap, and I saw that some npcs seemed to have a tile attributed to them before a specific flag is cleared.

    Like for exemple, for the player character. He seems to start at a specific location after jumping out of the truck, either as male or female, and I can't find where I could change his designated tile once he is out of the truck.

    I found this segment of the script that seems to be what I'm looking for, but I changed it and it didn't do anything :

    LittlerootTown_EventScript_StepOffTruckMale::
    lockall
    setvar VAR_0x8004, 4 (<--- I changed this value)
    setvar VAR_0x8005, 11 (<--- I changed this value)
    call LittlerootTown_EventScript_GoInsideWithMom
    setflag FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_TRUCK
    warpsilent MAP_LITTLEROOT_TOWN_BRENDANS_HOUSE_1F, 255, 8, 8
    waitstate
    releaseall
    end

    LittlerootTown_EventScript_StepOffTruckFemale::
    lockall
    setvar VAR_0x8004, 22 (<--- I changed this value)
    setvar VAR_0x8005, 10 (<--- I changed this value)
    call LittlerootTown_EventScript_GoInsideWithMom
    setflag FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_TRUCK
    warpsilent MAP_LITTLEROOT_TOWN_MAYS_HOUSE_1F, 255, 2, 8
    waitstate
    releaseall
    end


    I don't know if a tutorial on how to modify the original script would be of interest to anyone besides me, but I couldn't find that info anywhere.
     
    Last edited:
    Back
    Top