Jump to content

Automatic Translation of Drop from mob_drop_item.txt and special_item_group.txt Files


Recommended Posts

Video:

Code:
 

# The script automatically translates the drop from mob_drop_item.txt and special_item_group.txt files, utilizing the information in the locale_name.txt file
import chardet
import codecs
def detect_encoding(filename):
    with open(filename, 'rb') as f:
        result = chardet.detect(f.read())
    return result['encoding']
with codecs.open('item_names.txt', 'r', encoding='cp1250') as source_file:
    contents = source_file.read()
with codecs.open('item_names_utf8.txt', 'w', encoding='utf-8') as target_file:
    target_file.write(contents)
with open('item_names_utf8.txt', 'r', encoding='utf-8') as f:
    item_names = {}
    for line in f:
        if 'VNUM' in line or 'LOCALE_NAME' in line:
            continue
        vnum, name = line.strip().split('\t')
        item_names[vnum] = name
drop_cpp_encoding = detect_encoding('drop.txt')
with open('drop.txt', 'r', encoding=drop_cpp_encoding) as f:
    lines = f.readlines()
new_lines = []
for line in lines:
    if line.startswith('Group') or 'exp' in line:
        new_lines.append(line)
    else:
        parts = line.split('\t')
        if len(parts) > 2 and parts[2] in item_names:
            line = line.rstrip() + ' // ' + item_names[parts[2]] + '\n'
        new_lines.append(line)
with open('drop2.txt', 'w', encoding='utf-8') as f:
    f.writelines(new_lines)

 

  • Metin2 Dev 6

Grzyb.ovh

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
On 6/30/2023 at 4:44 PM, Marcos17 said:

I tried using the script and got the following error...

Error:

Traceback (most recent call last):
  File "/txt/converter.py", line 3, in <module>
    import chardet
ModuleNotFoundError: No module named 'chardet'
 

apt install python3-pip

pip3 install chardet

or

pip install chardet

 

Grzyb.ovh

Link to comment
Share on other sites

  • 1 month later...

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.