Jump to content

[Py Automation]item_list.txt generator


Recommended Posts

  • Premium
Posted (edited)

Hello, here's a item list generator, for them lazy people (or with really tired eyes)
Adds at eof, new item upgrades and respective location for icon/textures
Req python 3.11
 

import re


def generate_item_code(items):
    item_codes = []
    for item in items:
        icon_location = item["icon_location"]
        texture_location = item["texture_location"]
        vnums = item["vnums"]

        for item_id in vnums:
            for i in range(10):
                item_code = f"{item_id + i}\tWEAPON\t{icon_location.replace('*', str(item_id))}\t{texture_location.replace('*', str(item_id))}"
                item_codes.append(item_code)
    return item_codes


def write_to_txt(item_codes, file_path):
    with open(file_path, "r+") as file:
        existing_lines = file.readlines()
        for item_code in item_codes:
            if item_code + "\n" in existing_lines:
                item_vnum = re.split(r'\t+', item_code)[0]
                print(f"SKIPPED - Item code {item_vnum} already exists in item list")
            else:
                file.write(item_code + "\n")
                print(item_code)


if __name__ == "__main__":
    # In order to use the locations params
    # If ur file requires any prefix "0*.tga", before * include ur prefix, also ur desired extension .tga in my case

    location_dict = [
        {
            "icon_location": "icon/item/0*.tga",
            "texture_location": "d:/ymir work/item/weapon/0*.gr2",
            "vnums": [8190, 8290]
        }
    ]
    item_codes = generate_item_code(location_dict)
    txt_file_path = r"client_location\item_list.txt"
    write_to_txt(item_codes, txt_file_path)

 

Edited by astroNOT
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.