• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • 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.

Event Script Extractor

Swdfm

Game and Resource Developer
  • 275
    Posts
    6
    Years
    • he/him
    • UK
    • Seen May 3, 2025
    Do you know when you are extracting text for your game, and you get every single text from every event on every map.
    Well, I thought it would be useful to do it for scripts as well!
    With this script I wrote the other day, it allows you to obtain every single script from every map.
    This can be useful if you want to check if you have implemented a definition somewhere, and don't want to go trawling through all the events it could be on.

    Enjoy, and please give credit to Swdfm!
    As far as I know, his works on every version after v16 (incl. v18!)

    Code:
    #===============================================================================
    # * Event Script Extractor - by Swdfm (Credits will be appreciated)
    #===============================================================================
    #   A cool script that allows you to see your Event scripts all in one document.
    #   Place above Main
    #===============================================================================
    #   Call with pbExtractEventScripts
    #===============================================================================
    
    # Roughly how many events you think the map with the most events has.
    MAXEVENTCHECKER = 200 
    
    # The largest map ID number in your game.
    AMOUNTOFMAPS = 600
    
    # Name of the .txt document that the scripts are output to.
    OUTPUTTEXTFILE = "outfile.txt"
    
    # Whether you want to declare the map number
    WRITEMAPNUMBERS = true
    
    # Whether you want to declare the event number
    WRITEEVENTNUMBERS = true
    
    # Whether you want to declare the event page
    WRITEPAGENUMBERS = true
    
    # Whether you want the headings to be written for event pages with no scripts in.
    # Only relevant if one of above three is true
    INCLUDEEMPTIES = false
    
    # Whether you want Conditional Branch Scripts to be declared here.
    WRITECONDITIONAL = true
    
    # Text placed in front of Conditional Branch Scripts to show difference.
    # Only relevant if above is true.
    CONDITIONALTEXT = "[CB] "
    
    #===============================================================================
    
      def pbExtractEventScripts
        refreshrate = [[40,(8000/MAXEVENTCHECKER).floor].min,1].max
        writeanything = WRITEMAPNUMBERS || WRITEEVENTNUMBERS || WRITEPAGENUMBERS
        File.open(OUTPUTTEXTFILE,"wb"){|f| 
          f.write("================= Event Scripts ==================\r\n")
        }
        for mapid in 1..AMOUNTOFMAPS
          if pbRgssExists?(sprintf("Data/Map%03d.rxdata",mapid.to_i))
            realmap=$MapFactory.getMapNoAdd(mapid.to_i)
            map = load_data(sprintf("Data/Map%03d.rxdata", realmap.map_id))
            if WRITEMAPNUMBERS
              File.open(OUTPUTTEXTFILE,"ab"){|f| 
                f.write("==================================================\r\n")
              }
            end
            for i in 1...MAXEVENTCHECKER
              for event in map.events.values
                if event.id == i
                  count = 1
                  for page in event.pages
                    if writeanything && INCLUDEEMPTIES
                      File.open(OUTPUTTEXTFILE,"ab"){|f| 
                        f.write("=========  ")
                        f.write("[Map "+realmap.map_id.to_s+"]") if WRITEMAPNUMBERS
                        f.write("  [Event "+i.to_s+"]") if WRITEEVENTNUMBERS
                        f.write("  [Page "+count.to_s+"]") if WRITEPAGENUMBERS
                        f.write("  =========")
                        f.write("\r\n")
                      }
                    end
                    empty = true
                    for thing in page.list
                      if thing.code == 355 || thing.code == 655
                        string = thing.parameters[0]
                        if !INCLUDEEMPTIES && empty && writeanything
                          File.open(OUTPUTTEXTFILE,"ab"){|f| 
                            f.write("=========  ")
                            f.write("[Map "+realmap.map_id.to_s+"]") if WRITEMAPNUMBERS
                            f.write("  [Event "+i.to_s+"]") if WRITEEVENTNUMBERS
                            f.write("  [Page "+count.to_s+"]") if WRITEPAGENUMBERS
                            f.write("  =========")
                            f.write("\r\n")
                          }
                          empty = false
                        end
                        File.open(OUTPUTTEXTFILE,"ab"){|f| 
                          f.write(string)
                          f.write("\r\n")
                        }
                      elsif thing.code == 111 && WRITECONDITIONAL
                        if thing.parameters[0] == 12
                          string = thing.parameters[1]
                          if !INCLUDEEMPTIES && empty && writeanything
                            File.open(OUTPUTTEXTFILE,"ab"){|f| 
                              f.write("=========  ")
                              f.write("[Map "+realmap.map_id.to_s+"]") if WRITEMAPNUMBERS
                              f.write("  [Event "+i.to_s+"]") if WRITEEVENTNUMBERS
                              f.write("  [Page "+count.to_s+"]") if WRITEPAGENUMBERS
                              f.write("  =========")
                              f.write("\r\n")
                            }
                            empty = false
                          end
                          File.open(OUTPUTTEXTFILE,"ab"){|f| 
                            f.write(CONDITIONALTEXT+string)
                            f.write("\r\n")
                          }
                        end
                      end
                    end
                    count += 1
                  end
                end
              end
            end
          end
          # Necessary to avoid potential script hanging/taking too long.
          Kernel.pbMessage(_INTL("{1}\\WTNP[0]",mapid)) if mapid%refreshrate == 0
        end
        Kernel.pbMessage(_INTL("Done!"))
      end
     
    Hello! I like all the options you give for formatting the scripts output! Sorry to hijack the thread slightly, but I do have this script to output all commands in all events: https://www.pokecommunity.com/threads/437101
    It can generate hundreds of thousands of lines, though, so this definitely looks like a more efficient way of going through ONLY scripts if that's the main thing you need to see.
     
    Hello! I like all the options you give for formatting the scripts output! Sorry to hijack the thread slightly, but I do have this script to output all commands in all events: https://www.pokecommunity.com/threads/437101
    It can generate hundreds of thousands of lines, though, so this definitely looks like a more efficient way of going through ONLY scripts if that's the main thing you need to see.
    Sorry, I had no idea that this had been done before. Still, it was a nice achievement at the time!
     
    Back
    Top