Advertisement
Guest User

Scripts to move maps

a guest
Jun 4th, 2025
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.28 KB | Gaming | 0 0
  1. YBN files exported to XML
  2.  
  3. import re
  4. import os
  5.  
  6. # Folder containing the .ybn.xml files
  7. folder_path = r"path/to/your/folder"  # Change this to your folder path
  8. # Make sure the path is correct and contains the .ybn.xml files
  9.  
  10. # Values to add to each coordinate
  11. add_x = 0     # Add to X
  12. add_y = 0     # Add to Y
  13. add_z = 0     # Add to Z
  14.  
  15. # Function to modify the coordinates
  16. def modify_coordinates(match):
  17.     prefix = match.group(1)  # Part before x
  18.     x_value = float(match.group(2))  # x value
  19.     y_value = float(match.group(3))  # y value
  20.     z_value = float(match.group(4))  # z value
  21.     suffix = match.group(5)  # Part after z
  22.  
  23.     # Add values to the coordinates
  24.     new_x = x_value + add_x
  25.     new_y = y_value + add_y
  26.     new_z = z_value + add_z
  27.  
  28.     # Return the modified line
  29.     return f'{prefix}x="{new_x}" y="{new_y}" z="{new_z}"{suffix}'
  30.  
  31. # Regular expression to find the three coordinates in specific tags
  32. pattern = re.compile(r'(<BoxMin |<BoxMax |<BoxCenter |<SphereCenter |<GeometryCenter )x="([-\d.]+)" y="([-\d.]+)" z="([-\d.]+)"( />)')
  33.  
  34. # Loop through all .xml files in the folder
  35. for filename in os.listdir(folder_path):
  36.     if filename.endswith(".ybn.xml"):
  37.         file_path = os.path.join(folder_path, filename)
  38.        
  39.         # Open the file and read its content
  40.         with open(file_path, "r") as file:
  41.             content = file.read()
  42.  
  43.         # Replace coordinates in the specified tags
  44.         content = pattern.sub(modify_coordinates, content)
  45.  
  46.         # Save the changes
  47.         with open(file_path, "w") as file:
  48.             file.write(content)
  49.  
  50.         print(f"Coordinates modified in: {filename}")
  51.  
  52. print("Process completed.")
  53.  
  54. ---------------------------------------------------------------------------------------------------------------------------------------
  55.  
  56. YMAP files exported to XML
  57.  
  58. import xml.etree.ElementTree as ET
  59. import os
  60.  
  61. # Folder that contains the .ymap.xml files
  62. folder_path = r"path/to/your/folder"  # Change this to your folder path
  63. # Make sure the path is correct and contains the .ymap.xml files
  64.  
  65. # Values to add or subtract from each coordinate
  66. # You can change these values as needed; to subtract, just use negative values like -100
  67. x = 0   # Add to X
  68. y = 0   # Add to Y
  69. z = 0   # Add to Z
  70.  
  71. def modify_attribute_values(element):
  72.     """ Modifies the x, y, z attributes if they exist. """
  73.     for coord in ['x', 'y', 'z']:
  74.         if coord in element.attrib:
  75.             value = float(element.attrib[coord])
  76.             if coord == 'x':
  77.                 element.attrib[coord] = str(value + x)
  78.             elif coord == 'y':
  79.                 element.attrib[coord] = str(value + y)
  80.             elif coord == 'z':
  81.                 element.attrib[coord] = str(value + z)
  82.  
  83. def modify_node_values(element):
  84.     """ Modifies the x, y, z nodes inside <position>. """
  85.     for item in element.findall("Item"):
  86.         for coord in ['x', 'y', 'z']:
  87.             node = item.find(coord)
  88.             if node is not None and 'value' in node.attrib:
  89.                 value = float(node.attrib['value'])
  90.                 if coord == 'x':
  91.                     node.attrib['value'] = str(value + x)
  92.                 elif coord == 'y':
  93.                     node.attrib['value'] = str(value + y)
  94.                 elif coord == 'z':
  95.                     node.attrib['value'] = str(value + z)
  96.  
  97. # Loop through all .ymap.xml files in the folder
  98. for filename in os.listdir(folder_path):
  99.     if filename.endswith(".ymap.xml"):
  100.         file_path = os.path.join(folder_path, filename)
  101.        
  102.         # Load the XML file
  103.         tree = ET.parse(file_path)
  104.         root = tree.getroot()
  105.  
  106.         # Modify elements with x, y, z attributes
  107.         for elem in root.iter():
  108.             if elem.tag in ['streamingExtentsMin', 'streamingExtentsMax', 'entitiesExtentsMin', 'entitiesExtentsMax', 'position']:
  109.                 modify_attribute_values(elem)
  110.  
  111.         # Modify the nodes inside <position>
  112.         for position in root.findall(".//position"):
  113.             modify_node_values(position)
  114.  
  115.         # Save the modified XML file with declaration
  116.         output_path = os.path.join(folder_path, filename)
  117.         tree.write(output_path, encoding="UTF-8", xml_declaration=True)
  118.  
  119.         print(f"Modified file: {filename}")
  120.  
  121. print("Process completed.")
  122.  
Tags: Gta5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement