Back to Browse

Exporting Items from the RPG Maker MZ Database to a CSV

2.3K views
Premiered Mar 29, 2024
8:21

Hey all, when the steam links and Kickstarter links become available, I'll drop them here. Scroll down for the code. RPG Maker ASSETS https://level-up-design.itch.io/ Code in Video Copy from Items to CSV print("Script started...") import json import csv # Path to your RPG Maker MZ project's Items.json file. # Update this path to where your actual Items.json file is located. items_json_path = r'C:\Users\youtpathhere\Items.json' csv_output_path = 'items.csv' # Load the items from the JSON file. with open(items_json_path, 'r', encoding='utf-8') as file: items = json.load(file) # Open a new CSV file for writing. with open(csv_output_path, 'w', newline='', encoding='utf-8') as file: writer = csv.writer(file) # Write the header row. writer.writerow(['ID', 'Name']) # Write each item's ID and name. for item in items: if item: # Check if the item is not None. item_id = item['id'] item_name = item['name'] writer.writerow([item_id, item_name]) print(f'CSV file has been created at {csv_output_path}.') Code for Update External CSV import csv import re from pathlib import Path def read_csv_to_dict(filename, key_column, value_column): result = {} with open(filename, mode='r', newline='', encoding='utf-8') as csvfile: reader = csv.DictReader(csvfile) for row in reader: key = row[key_column].strip().lower() # Convert to lowercase to match case-insensitively value = row[value_column].strip() if key: # Only add non-empty keys result[key] = value return result def prefix_item_name(match, item_id): found_item = match.group(0) replacement = f"{item_id} {found_item}" print(f"Replacing '{found_item}' with '{replacement}'") return replacement def prefix_item_names_in_recipes(recipes_filename, item_mapping): modified_rows = [] with open(recipes_filename, mode='r', newline='', encoding='utf-8') as csvfile: reader = csv.reader(csvfile) headers = next(reader) modified_rows.append(headers) for row_number, row in enumerate(reader, start=1): modified_row = [] for cell in row: for item_name, item_id in item_mapping.items(): if item_name: # Only process non-empty item names pattern = re.compile(r'\b{}\b'.format(re.escape(item_name)), flags=re.IGNORECASE) cell = pattern.sub(lambda match: prefix_item_name(match, item_id), cell) modified_row.append(cell) modified_rows.append(modified_row) if row_number % 100 == 0: print(f"Processed row {row_number}") # Print progress every 100 rows return modified_rows def write_csv(filename, rows): with open(filename, mode='w', newline='', encoding='utf-8') as csvfile: writer = csv.writer(csvfile) writer.writerows(rows) def main(): print("Reading item mapping...") item_name_to_id = read_csv_to_dict('items.csv', 'Name', 'ID') print("Item to ID mapping:") for item, id in item_name_to_id.items(): print(f"'{item}': '{id}'") print("Prefixing item names in recipes...") modified_recipes = prefix_item_names_in_recipes('recipes.csv', item_name_to_id) output_filename = 'modified_recipes_corrected.csv' print(f"Writing modified recipes to {output_filename}...") write_csv(output_filename, modified_recipes) print("Done. Modified recipes have been saved.") if __name__ == "__main__": main() If this is your first time on the channel seeing one of my videos then a huge 'Welcome to Level Up Design.' On this channel, I share tips and tricks, tutorials, and overall RPG related content.

Download

0 formats

No download links available.

Exporting Items from the RPG Maker MZ Database to a CSV | NatokHD