• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OpenTibia Convert Correct Mon Values To Xml Values

iNux

Intermediate OT User
Joined
Jan 19, 2019
Messages
214
Reaction score
111
Hello,

While working on my project, an 8.0 server based on the Real Tibia, I have been updating and fixing its formulas, values, and behaviors based on RealOTS for learning and experimental purposes. Today, I decided to release my script that converts values (currently only converts speed, defense, and armor) from the .mon files and updates your .xml monster files. I believe that most of the formulas were still the same in 8.0. Perhaps they have changed afterward, but I love the formulas and behaviors of the old Tibia, so I decided to keep it that way, at least for my project and interest.

Instead of having to check everything and change everything manually, I decided to create a script for it as I noticed that most of the creatures' values were wrong, especially speed, defense, and armor.

Perhaps someone can use it or is doing the same thing right now
Python:
# Usage: python MonToXML.py
# Description: This script reads the .mon files in the specified folder and updates the corresponding .xml files with the speed, defense and armor values.


import os
import re
from lxml import etree

def parseMonFile(filepath):
    with open(filepath, 'r') as file:
        content = file.read()
    name_match = re.search(r'Name\s*=\s*"([^"]+)"', content)
    speed_match = re.search(r'GoStrength,\s*(\d+),', content)
    defend_match = re.search(r'Defend\s*=\s*(\d+)', content)
    armor_match = re.search(r'Armor\s*=\s*(\d+)', content)

    if name_match and speed_match and defend_match and armor_match:
        name = name_match.group(1)
        speed = int(speed_match.group(1))
        defend = int(defend_match.group(1))
        armor = int(armor_match.group(1))
        return name, speed, defend, armor
    return None, None, None, None

def updateXmlFile(filepath, creature_data):
    parser = etree.XMLParser(remove_blank_text=True)
    tree = etree.parse(filepath, parser)
    root = tree.getroot()
    name = root.attrib.get('name')

    if name in creature_data:
        speed, defend, armor = creature_data[name]

        root.attrib['speed'] = str(speed)

        defenses = root.find('defenses')
        if defenses is not None:
            defenses.attrib['defense'] = str(defend)
            defenses.attrib['armor'] = str(armor)

        tree.write(filepath, encoding="UTF-8", xml_declaration=True, pretty_print=True)

def main():
    mon_folder = 'your_mon_folder' # Path to the folder containing the .mon files
    xml_folder = 'your_xml_folder' # Path to the folder containing the .xml files

    creature_data = {}

    for filename in os.listdir(mon_folder):
        if filename.endswith('.mon'):
            mon_filepath = os.path.join(mon_folder, filename)
            name, speed, defend, armor = parseMonFile(mon_filepath)
            if name and speed is not None and defend is not None and armor is not None:
                creature_data[name] = (speed, defend, armor)

    for filename in os.listdir(xml_folder):
        if filename.endswith('.xml'):
            xml_filepath = os.path.join(xml_folder, filename)
            updateXmlFile(xml_filepath, creature_data)

if __name__ == "__main__":
    main()
 
Back
Top