v21.1 Modifying gamedata from scripts

This thread pertains to v21.1 of Pokémon Essentials.

Ilonias

Rookie
Member
Joined
May 12, 2021
Posts
9
Age
23
I am currently making a game where I want the metadata of multiple maps to be modified for story reasons in the middle of a playthrough, however I cannot seem to find an easy way to do so...

I want to edit the names of the maps. So "Owlbourgh town" would become "Micesqueek City" for example. Does anyone have an idea how I could get this to work?
 
Solution
I found an inelegant solution, using the base from the debug editor. posting it here for the next person who might need it.

Ruby:
def pbEditMapMetadataIl(map_id)
    mapinfos = pbLoadMapInfos
    data = []
    map_name = mapinfos[map_id].name
    metadata = GameData::MapMetadata.try_get(map_id)
    metadata = GameData::MapMetadata.new({:id => map_id}) if !metadata
    properties = GameData::MapMetadata.editor_properties
   
    properties.each do |property|
        val = metadata.get_property_for_PBS(property[0])
        val = property[1].defaultValue if val.nil? && property[1].respond_to?(:defaultValue)
        data.push(val)
    end
   
    # Data order = ID, Name, outdoor, Showarea, Bicycle, Bicycle always, Healingspot...

Lucidious89

Champion
Member
Joined
Nov 12, 2020
Posts
682
Age
34
I am currently making a game where I want the metadata of multiple maps to be modified for story reasons in the middle of a playthrough, however I cannot seem to find an easy way to do so...

I want to edit the names of the maps. So "Owlbourgh town" would become "Micesqueek City" for example. Does anyone have an idea how I could get this to work?
Couldn't you just make a duplicate map that is identical in every way except it has a different name? Then just have the player transfer to that map instead after the switch is triggered in the story that would change its name.
 

Ilonias

Rookie
Member
Joined
May 12, 2021
Posts
9
Age
23
Couldn't you just make a duplicate map that is identical in every way except it has a different name? Then just have the player transfer to that map instead after the switch is triggered in the story that would change its name.
I would, however the game I am making involves randomizing certain aspects of the map. This also means the new name will be randomized, meaning I cannot preset it in the metadata file to get it to work that way, lest I create a map with each naming option.
 

Ilonias

Rookie
Member
Joined
May 12, 2021
Posts
9
Age
23
I'll elaborate on why setting the data upfront in the metadata isn't what I am looking for. I am making a game in which the region is randomized, from route to route and placement of cities and locations. I got the world randomizer to work, so now I can just input a couple dozen maps and the script generates the map connections, while alternating between routes and cities and special locations. Now I want to make sure these maps are randomly named, and the routes will be named in ascending order. For this to work however, I would need to edit the metadata in the randomizer script.

It did already work for the map connection editor, but I can't seem to figure out the way to do it with the metadata.

Sorry if my previous examples were insufficient, and it might not even be possible in an easy manner but I was just curious to know if anyone had encountered or solved this earlier.
 

LinKazamine

Elite Trainer
Member
Joined
May 24, 2023
Posts
288
Well, you could look at how the translation thing works. Why I'm saying it? Because the name displayed for the maps is picked from the translated archives in the data instead of directly their metadata. I don't know how it works, but maybe it'll help in what you want.
 

Ilonias

Rookie
Member
Joined
May 12, 2021
Posts
9
Age
23
I found an inelegant solution, using the base from the debug editor. posting it here for the next person who might need it.

Ruby:
def pbEditMapMetadataIl(map_id)
    mapinfos = pbLoadMapInfos
    data = []
    map_name = mapinfos[map_id].name
    metadata = GameData::MapMetadata.try_get(map_id)
    metadata = GameData::MapMetadata.new({:id => map_id}) if !metadata
    properties = GameData::MapMetadata.editor_properties
   
    properties.each do |property|
        val = metadata.get_property_for_PBS(property[0])
        val = property[1].defaultValue if val.nil? && property[1].respond_to?(:defaultValue)
        data.push(val)
    end
   
    # Data order = ID, Name, outdoor, Showarea, Bicycle, Bicycle always, Healingspot ([mapId,x,y]),Weather(Type,chance),mapPosition,divemap,darkmap,safariMap,snapedges,stillReflections,Dungeon,battleback,wildbattlebgm,trainerbattlebgm,wildvictorybgm,trainervictorybgm,wildcaptureme,mapsize,environment,flags
    #                0   1        2        3        4         5                    6                        7                    8            9        10        11            12        13                    14        15        16                17                18                19                    20            21        22            23
    data[1] = "New Map Name" # This can be a variable or sth similair ofcourse.
   
    # Idk why this work and what it does tbh. But it does transfer the data and writes it down in the pbs, crucially without overwriting old data of different maps.
    schema = GameData::MapMetadata.schema
    metadata_hash = {}
    properties.each_with_index do |prop, i|
      case prop[0]
      when "ID"
        metadata_hash[schema["SectionName"][0]] = data[i]
      else
        metadata_hash[schema[prop[0]][0]] = data[i]
      end
    end
    metadata_hash[:pbs_file_suffix] = metadata.pbs_file_suffix
    # Add map metadata's data to records
    GameData::MapMetadata.register(metadata_hash)
    GameData::MapMetadata.save
    Compiler.write_map_metadata
end
 
Solution
Top