DayZ
Auto update DayZ server script (app, mods, etc)
Sorry, but not sure where exactly to post and apologies if this post gets messy. Been messing around with my DayZ dedicated server. Wanted to get it fairly automated and used ChatGPT to accomplish this from my basic startup .bat file. Took a while since ChatGPT wants to break what it has already accomplished by changing code when you specifically inform it to utilize the exact same code. Anyways...ChatGPT and a very frustrated me came up with the following batch file that will take a simple mod list (modlist.txt with a mod's numeric id and @modname) and

1. proceed to create a new @mod folder if it doesn't exist
2. use the numeric id and copy the contents from the Workshop folder
3. Update all mods from the modlist.txt in the server directory folder
4. Create a launch parameter mod list for starting the server
5. Loop through each mod folder to copy keys to server key folder (in case new mod added)
6. Start your server with custom parameters
7. Auto restart your server within specified time frame

-----------------------------------------------------------------------------------------------
The main thing that needs to be updated is the modlist.txt file. An example of the format is the following (id @modname):

1559212036 @CF
2545327648 @Dabs Framework
2116157322 @DayZ-Expansion-Licensed
2572331007 @DayZ-Expansion-Bundle
1828439124 @VPPAdminTools
------------------------------------------------------------------------------------------------

Here is some recommendations that I did for my setup
1. Put my server folder in the root C:\DayZServer
2. Put steamcmd folder in C:\DayZServer. Login once inside the directory and you should not need a password in your .bat file
3.Place modlist.txt in C:\DayZServer
4.Make sure you have Steam installed and logged in on same PC. i have a second copy of DayZ and separate account for this one. May need to disable steam guard to have this work 100%.
5.Be sure to add mods through steam workshop like normal (click + icon). i don't know if this is required because when testing a couple mods that I didn't add via Steam app it still worked.

Here is the .bat code

------------------------------------------------------------------------------------------------
@echo off
setlocal enabledelayedexpansion

:: SteamCMD configuration
set "STEAMCMD_PATH=C:\DayZServer\steamcmd"
:: Set the Steam login credentials
set "STEAM_USERNAME=your_username"
:: Reminder: For security reasons, you might want to input the password during execution.
:: Set the server directory where mods will be installed or updated
set "SERVER_DIR=C:\DayZServer"
:: Path to the modlist file
set "MODLIST_PATH=C:\DayZServer\modlist.txt"
:: DayZ App ID
set "DAYZ_APP_ID=221100"
:: Steam Workshop content directory
set "WORKSHOP_CONTENT_DIR=C:\Program Files (x86)\Steam\steamapps\workshop\content\221100"
::Set Keys Directory
set "KEYS_DIR=%SERVER_DIR%\keys"

:modFoldersAndContent
:: Creating mod folders based on modlist.txt and copying contents from the workshop
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
set "numericID=%%a"
set "modName=%%b"
if not exist "%SERVER_DIR%\%%b\" (
echo Creating missing mod folder: %%b
mkdir "%SERVER_DIR%\%%b"
echo Copying contents for: %%b from !numericID!
xcopy "%WORKSHOP_CONTENT_DIR%\!numericID!\*" "%SERVER_DIR%\%%b\*" /E /I /Y
)
)

:: Update mods using SteamCMD
echo Updating DayZ Mods...
:: Initialize SteamCMD script with force_install_dir before login
echo force_install_dir "%SERVER_DIR%" > "%SERVER_DIR%\steamcmd_script.txt"
echo login %STEAM_USERNAME% >> "%SERVER_DIR%\steamcmd_script.txt"
::Add app_update to keep server base updated. Will add significant time to server startup
echo app_update %DAYZ_APP_ID% validate >> "%SERVER_DIR%\steamcmd_script.txt"
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
echo workshop_download_item %DAYZ_APP_ID% %%a >> "%SERVER_DIR%\steamcmd_script.txt"
)
echo quit >> "%SERVER_DIR%\steamcmd_script.txt"
:: Execute the constructed SteamCMD command sequence from a script file
"%STEAMCMD_PATH%\steamcmd.exe" +runscript "%SERVER_DIR%\steamcmd_script.txt"

:: Initialize the mods string for server launch
set "MODS="

:: Construct the mod launch parameter from the modlist
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
set "modFolder=%%b"
set "MODS=!MODS!;!modFolder!"
)

:: Remove the leading semicolon from the mods string
set "MODS=!MODS:~1!"

echo Mods to be loaded: !MODS!

:: Section to copy keys from each mod's keys folder to the server's keys directory
:: Ensure the target keys directory exists
if not exist "%KEYS_DIR%" mkdir "%KEYS_DIR%"

:: Loop through each mod folder to copy keys
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
if exist "%SERVER_DIR%\%%b\keys\*" (
xcopy "%SERVER_DIR%\%%b\keys\*" "%KEYS_DIR%" /E /I /Y
)
)

:start
:: Server configurations
set "serverName=your_server_name"
set "serverLocation=C:\DayZServer"
set "profile=your_profile_name"
set "serverPort=2302"
set "serverConfig=serverDZ.cfg"
set "serverCPU=4"

title %serverName% batch
cd /d "%serverLocation%"
echo (%time%) %serverName% started.


:: Launch parameters
::output to ensure modlist is correct for start command
echo start "DayZ Server" /min DayZServer_x64.exe "-mod=%MODS%" -profiles=%profile% -config=%serverConfig% -port=%serverPort% -cpuCount=%serverCPU% -dologs -adminlog -netlog -freezecheck
start "DayZ Server" /min DayZServer_x64.exe "-mod=%MODS%" -profiles=%profile% -config=%serverConfig% -port=%serverPort% -cpuCount=%serverCPU% -dologs -adminlog -netlog -freezecheck

:: Wait before restarting server process
timeout /t 14400 /nobreak

:: Optionally kill DayZ Server process before restarting
taskkill /im DayZServer_x64.exe /F

goto modFoldersAndContent

------------------------------------------------------------------------------------------------

I'm sure there are more efficient ways of doing this. I was struggling to find info online that wasn't way over my head, so had to go the ChatGPT route.

Please tell me if you recommend any changes or have some questions. I am sure it is overkill. Hope this can help someone with their server.
< >
Showing 1-2 of 2 comments
Shads76 Mar 3 @ 6:37am 
Looks good to me! (haven't tested it yet), I to wanted to create a .bat file that did exactly this myself when i used to run servers but just didn't have the time. I only had a basic one that copied trader files and .xml loot table files etc so i could edit them while the server was still running, and they would update on restart. I have saved your posted info for later use (also subbed to the discussion). Thank you for sharing :)
wxndr May 10 @ 6:40am 
Tried it out, so it copies the name of the folder of a mod but doesn't actually move any files into that directory so it ends up being an empty mod essentially.
< >
Showing 1-2 of 2 comments
Per page: 1530 50