Jump to content

Some little helper scripts for modders


stuck1a

Recommended Posts

Hey there,

I just wanted to share some of my util scripts I recently use with IDEA run configurations. Maybe anyone else will benefit from it, too.

The batch scripts will of course only work under windows.

 

UpdateSteamWorkshopObject.bat

@ECHO off
:: Update-Script for Zomboid Steam-WorkshopItems
:: Usage-Example:
:: UpdateSteamWorkshopObject 522891356

:: Adjust these paths as needed
SET steamcmd=E:/Programme/SteamCMD/steamcmd.exe
SET steamdir=E:/Programme/Steam

"%steamcmd%"  +force_install_dir "%steamdir%" +login anonymous +workshop_download_item 108600 %~1 +quit

 

 

HardresetDebugServer.bat

:: Path to your dev servers "zomboid" directory
:: Use with care, it will delete all multiplayer save files within in and the server database file
SET zomboid_directory=E:\Development\Java Workspace\ProjectZomboidModding\appdata
SET servername=DebugServer

DEL "%zomboid_directory%\db\%servername%.db" /F /Q
DEL "%zomboid_directory%\Saves\Multiplayer\" /S /F /Q
FOR /D %%a IN ("%zomboid_directory%\Saves\Multiplayer\*.*") DO RD /Q /S "%%a"
EXIT

 

 

spawnpoints2objects.lua

-- Script to convert spawnpoints in the format like given in spawnpoints.lua files to the format required for objects.lua in maps.
-- I mainly use this to fix/adjust spawnpoints of 3rd party maps I adapt.

-- EXAMPLE DATA. Replace as needed
spawnpoints = {
  unemployed = {
    { worldX = 38, worldY = 23, posX = 80,  posY = 124, posZ = 0 },
    { worldX = 38, worldY = 22, posX = 243, posY = 96,  posZ = 0 },
    { worldX = 38, worldY = 22, posX = 94,  posY = 102, posZ = 0 },
    { worldX = 38, worldY = 22, posX = 12,  posY = 124, posZ = 0 },
    { worldX = 37, worldY = 22, posX = 197, posY = 130, posZ = 0 },
  },
  cook = {
    { worldX = 38, worldY = 23, posX = 122, posY = 12, posZ = 1 },
    { worldX = 38, worldY = 22, posX = 12,  posY = 287, posZ = 0 },
  },
}



for profession, entries in pairs(spawnpoints) do
  local prof = tostring(profession)
  if prof == 'unemployed' then prof = 'all' end
  for _, v in pairs(entries) do
    print("{ name = '', type = 'SpawnPoint', x = "..v.worldX*300+v.posX..", y = "..v.worldY*300+v.posY..", z = "..(v.posZ or "0")..", width = 1, height = 1, properties = { Professions = '"..prof.."' } },")
  end
end


-- THIS WILL OUTPUT:
-- { name = '', type = 'SpawnPoint', x = 11522, y = 6912, z = 1, width = 1, height = 1, properties = { Professions = 'cook' } },
-- { name = '', type = 'SpawnPoint', x = 11412, y = 6887, z = 0, width = 1, height = 1, properties = { Professions = 'cook' } },
-- { name = '', type = 'SpawnPoint', x = 11480, y = 7024, z = 0, width = 1, height = 1, properties = { Professions = 'all' } },
-- { name = '', type = 'SpawnPoint', x = 11643, y = 6696, z = 0, width = 1, height = 1, properties = { Professions = 'all' } },
-- { name = '', type = 'SpawnPoint', x = 11494, y = 6702, z = 0, width = 1, height = 1, properties = { Professions = 'all' } },
-- { name = '', type = 'SpawnPoint', x = 11412, y = 6724, z = 0, width = 1, height = 1, properties = { Professions = 'all' } },
-- { name = '', type = 'SpawnPoint', x = 11297, y = 6730, z = 0, width = 1, height = 1, properties = { Professions = 'all' } },

 

 

 

GetMapSizeFromWorldmapXML.php

#!/usr/bin/php
<?php

//
// This scripts excepts a path to a worldmap.xml file and calculate the map boundaries out of its content.
// You can add optional padding. By default, I've set it to 10 extra squares on each edge.
// Might be used for auto-generation of MapDefinitions as well (simply parse or adjust the output string in this case)
//

// EXAMPLE OUTPUT FOR THE WORLDMAP.XML OF BEDFORD FALLS:
// XML cell analysis done!
// (xmin, ymin, xmax, ymax) = 12890, 9890, 14410, 11410


/********* OPTIONS ***********/
const TILES_PER_CELL = 300;
const BOUND_PADDING  = 10;
/*****************************/

$xmin = null;
$ymin = null;
$xmax = null;
$ymax = null;
$cells = [];
if ( !$argv || !$argv[1] || $argv[1] == '' ) {
  echo 'Missing argument';
  exit(1);
}
if ( !file_exists($argv[1]) ) {
  echo "File {$argv[1]} not found";
  exit(1);
}
$xml = file_get_contents($argv[1]);
$xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach ( $xml as $elem ) {
  if ( $elem->getName() == 'cell' ) { $cells[] = $elem; }
}
foreach ( $cells as $cell ) {
  foreach ( $cell->attributes() as $name => $value ) {
    if ( $name == 'x' ) {
      $current = (int)$value * TILES_PER_CELL;
      foreach ( $cell->children() as $feature ) {
        if ( $feature->getName() == 'feature' ) {
          foreach ( $feature->children() as $geometry ) {
            if ( $geometry->getName() == 'geometry' ) {
              foreach ( $geometry->children() as $coordinates ) {
                if ( $coordinates->getName() == 'coordinates' ) {
                  foreach ( $coordinates->children() as $point ) {
                    if ( $point->getName() == 'point' ) {
                      foreach ( $point->attributes() as $key => $val ) {
                        if ( $key == 'x' ) {
                          if ( $xmax == null || $xmax < $current + $val ) { $xmax = $current + $val; }
                          if ( $xmin == null || $xmin > $current + $val ) { $xmin = $current + $val; }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    } elseif ( $name == 'y' ) {
      $current = (int)$value * TILES_PER_CELL;
      foreach ( $cell->children() as $feature ) {
        if ( $feature->getName() == 'feature' ) {
          foreach ( $feature->children() as $geometry ) {
            if ( $geometry->getName() == 'geometry' ) {
              foreach ( $geometry->children() as $coordinates ) {
                if ( $coordinates->getName() == 'coordinates' ) {
                  foreach ( $coordinates->children() as $point ) {
                    if ( $point->getName() == 'point' ) {
                      foreach ( $point->attributes() as $key => $val ) {
                        if ( $key == 'y' ) {
                          if ( $ymax == null || $ymax < $current + $val ) { $ymax = $current + $val; }
                          if ( $ymin == null || $ymin > $current + $val ) { $ymin = $current + $val; }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

$xmin -= BOUND_PADDING;
$ymin -= BOUND_PADDING;
$xmax += BOUND_PADDING;
$ymax += BOUND_PADDING;

echo "\n\nXML cell analysis done!\n";
echo "(xmin, ymin, xmax, ymax) = ${xmin}, ${ymin}, ${xmax}, ${ymax}\n";
exit(0);
?>

If you add the this PHP script as remote tool, you can simply right click on any valid worldmap.xml and call the script. Works similar like the in-game map definitions tool.

Here is my remote tool definition as example:

image.thumb.png.0bb2271568739fbb3e59302b999f5d33.png

 

 

 

Well, I guess that's enough so far.

 

Best regards,

stuck1a

Edited by stuck1a
style
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...