Jump to content

Find mount mobs wihout folder


Recommended Posts

  • Active+ Member

Hello, this is a script that will help you fill in the empty spaces of the folder section of the mount caused by missing additions in mob_proto.

import os
import chardet

ITEM_PROTO_PATH = "item_proto.txt"
MOB_PROTO_PATH = "mob_proto.txt"
NPC_LIST_PATH = "npclist.txt"
LOG_FILE_PATH = "no_folder_mounts.txt"
MOB_NAMES_FILE_PATH = "mob_names.txt"
MOUNT_WITH_FOLDERS = "mount_with_folders.txt"
SERVER_DATA_FOLDER = "C:\\git\\CarbonSFv2\\server\\srv1\\share\\data\\monster"
SERVER_MISSING_FOLDERS = "server_missing_folders.txt"

MOUNT_TYPE = "ITEM_COSTUME"
MOUNT_SUBTYPE = "COSTUME_MOUNT"


MOUNT_LIST = []
MOUNT_WITH_NO_FOLDER = []


ITEM_TYPE = 2
ITEM_SUBTYPE = 3
ITEM_MOUNT_VALUE = 28

MOB_PROTO_MOUNT_VNUM = 0
MOB_PROTO_FOLDER_INDEX = 12


def process_file(file_path):
    with open(file_path, 'rb') as file:
        rawdata = file.read()
        encoding = chardet.detect(rawdata)['encoding']
    
    #convert to utf-8 if not already
    if encoding and encoding.lower() != 'utf-8':
        with open(file_path, 'r', encoding=encoding) as file:
            content = file.read()
        with open(file_path, 'w', encoding='utf-8') as file:
            file.write(content)

def checkCostumeMount(file_path):
    with open(file_path, 'r') as file:
        for line in file:
            if not line.strip():
                continue
            split = line.split('\t')
            try:
                if split[ITEM_TYPE] == MOUNT_TYPE and split[ITEM_SUBTYPE] == MOUNT_SUBTYPE:
                    MOUNT_LIST.append(split[ITEM_MOUNT_VALUE])
            except IndexError:
                print("Index Error on line: " + line)

def checkMobLine(file_path):
    process_file(file_path)
    with open(file_path, 'r', encoding='utf-8') as file:
        try:
            for line in file:
                if not line.strip():
                    continue
                    
                split = line.split('\t')
                try:
                    if split[MOB_PROTO_MOUNT_VNUM] in MOUNT_LIST and split[MOB_PROTO_FOLDER_INDEX] == "":
                        print("Mount with no folder: " + split[MOB_PROTO_MOUNT_VNUM])
                        MOUNT_WITH_NO_FOLDER.append(split[MOB_PROTO_MOUNT_VNUM])
                except IndexError:
                    print("Index Error on line: " + line)
        except UnicodeDecodeError:
            print("UnicodeDecodeError on line: " + line)

def writeIntoFile(file_path, log_file_path):
    logFile = open(log_file_path, 'w')
    with open(file_path, 'r') as file:
        for line in file:
            if not line.strip():
                continue
            split = line.split('\t')
            try:
                if split[0] in MOUNT_WITH_NO_FOLDER:
                    logFile.write(line)
            except IndexError:
                print("Index Error on line: " + line)
    logFile.close()

def setFolder(file_path):
    mountWithFolders = open(MOUNT_WITH_FOLDERS, 'w')
    with open(file_path, 'r') as file:
        for line in file:
            if not line.strip():
                continue
                
            split = line.split('\t')

            try:
                if split[0] in MOUNT_WITH_NO_FOLDER:
                    mountWithFolders.write(line)
            except IndexError:
                print("Index Error on line: " + line)
    mountWithFolders.close()

def checkFolderExist(folder_path):
    serverMissingFolders = open(SERVER_MISSING_FOLDERS, 'w')
    with open(MOUNT_WITH_FOLDERS, 'r') as file:
        for line in file:
            if not line.strip():
                continue
            split = line.split('\t')
            folder = os.path.join(folder_path, split[1])
            if not os.path.exists(folder):
                serverMissingFolders.write(folder + "\n")
            else:
                print("Folder exists: " + folder)
    serverMissingFolders.close()



def main():
    checkCostumeMount(ITEM_PROTO_PATH)
    checkMobLine(MOB_PROTO_PATH)
    writeIntoFile(MOB_NAMES_FILE_PATH, LOG_FILE_PATH)
    setFolder(NPC_LIST_PATH)
    checkFolderExist(SERVER_DATA_FOLDER)


if __name__ == "__main__":
    main()

 

Tutorial

Spoiler

In main.py

ITEM_TYPE = 2
ITEM_SUBTYPE = 3
ITEM_MOUNT_VALUE = 28
MOB_PROTO_MOUNT_VNUM = 0
MOB_PROTO_FOLDER_INDEX = 12

Configure the values in these sections according to your needs.
For example item_proto:
0->Vnum
1->locale_name
2->type
If the mount gets its mob number from value, check which column it is in and replace it with ITEM_MOUNT_VALUE.
Install the chardet package.

pip install chardet

Set the contents of the file like this:

item_proto.txt
mob_proto.txt
mob_names.txt
npclist.txt

After setting the file like this;
Run the script with Python.

python .\main.py

 

There are files for the vnums you need to complete in the mount_with_folder.txt file.
You can complete the missing

  • Metin2 Dev 2
  • muscle 1
  • Love 3
Link to comment
Share on other sites

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.