Skip to content

Instantly share code, notes, and snippets.

@simi
Last active March 21, 2024 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simi/f623553c499dbb7bcd28d1756b805cae to your computer and use it in GitHub Desktop.
Save simi/f623553c499dbb7bcd28d1756b805cae to your computer and use it in GitHub Desktop.

Reforger mission rotation

NOTICE: Both scripts will rotate missions without checking state of previous game. That means on server crash next mission in list will be started from scratch. Use at your own risk.

Windows (PowerShell)

Originally posted by Uro at https://discord.com/channels/105462288051380224/976119935875026964/979127368973168690.

I wrote a PowerShell script that server admins using Windows can implement to programmatically change the server.json config file to switch missions/implement a mission rotation.

You need to run this PowerShell script before your server launches, so if you have things setup to restart the server when the mission ends and the server dies then execute this script prior to it restarting the server executable - a caveat to doing it this way is that it will always switch missions when your server restarts, even if it crashed unintentionally. Linux server operators could easily adapt this to a shell script to have similar functionality. File is documented internally, MIT licenced. https://gitlab.com/Uro1/scripts/-/blob/main/ArmaReforgerServer/serverJson_switch_mission.ps1

Linux (Bash)

Originally posted by Marko at https://discord.com/channels/105462288051380224/976119935875026964/979152350197452850.

Same thing but for linux, without fancy JSON processing cause ain't nobody got time for that. WARNING: Use at Your Own Risk

One downside is, that if user doesn't check if server crashed, it will load new campaign none the less

#!/bin/bash

# Path to config goes ere'
ConfFilePath=.config/ArmaReforgerServer/config.json

# Array of scenarioId to rotate
ScenarioArray=(
    '{FDE33AFE2ED7875B}Missions/23_Campaign_Montignac.conf'
    '{C700DB41F0C546E1}Missions/23_Campaign_NorthCentral.conf'
    '{1AEE808E7689FE54}Missions/23_Campaign_NWCoast.conf'
    '{6C3A09ACE0AD3721}Missions/23_Campaign_PinewoodLake.conf'
    '{D0BCF58CE5411856}Missions/23_Campaign_Ridge.conf'
    '{28802845ADA64D52}Missions/23_Campaign_SWCoast.conf'
    '{0FC71901A21374FA}Missions/23_Campaign_Tower.conf'
    '{28911C35F7B55579}Missions/23_Campaign_WestSmall.conf'
)
# Read current scenarioId from conf
CurScenario=$(cat $ConfFilePath | grep 'scenarioId' | cut -d "\"" -f4)
# Set fallback just in case
NextScenario=CurScenario

echo "Current scenario: $CurScenario"

ScenarioArrayCount=$((${#ScenarioArray[@]}-1));
for i in ${!ScenarioArray[@]};
do
    if [ "${ScenarioArray[$i]}" = "$CurScenario" ]; then
        # Find current scenarioId in array
        break
    fi
done

# Rotate if last
if (($i >= ScenarioArrayCount)); then
    i=0
else
    ((i=i+1))
fi

NextScenario="${ScenarioArray[$i]}"

# Replace id in file
sed -i "s%$CurScenario%$NextScenario%" $ConfFilePath
echo "Next scenario: $NextScenario"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment