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
  • Good 1

Just a keyboard and some caffeine, making things work.

Traceback (most recent call last):
  File "/usr/home/renamedrop.py", line 16, in <module>
    vnum, name = line.strip().split('\t')
ValueError: not enough values to unpack (expected 2, got 1)

 

9 hours ago, avertusss said:
Traceback (most recent call last):
  File "/usr/home/renamedrop.py", line 16, in <module>
    vnum, name = line.strip().split('\t')
ValueError: not enough values to unpack (expected 2, got 1)

 

I think you need this

 

chardet & codecs

 

 

  • 1 month later...

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'
 

  • 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

 

Just a keyboard and some caffeine, making things work.

On 9/17/2023 at 8:20 PM, Grzyb said:

apt install python3-pip

pip3 install chardet

or

pip install chardet

 

None of the commands work:

pip3 install chardet

pip3: Command not found.

pip install chardet

pip: Command not found.

 

 

  • 1 month later...
On 9/21/2023 at 9:17 PM, Marcos17 said:

None of the commands work:

pip3 install chardet

pip3: Command not found.

pip install chardet

pip: Command not found.

 

 

Try with PyCharm IDE, gonna work fine

 

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • 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.