Skip to content

Instantly share code, notes, and snippets.

@Ethorbit
Created October 20, 2024 01:51
Show Gist options
  • Save Ethorbit/62acb9471a16d3a5953f57c8298e962a to your computer and use it in GitHub Desktop.
Save Ethorbit/62acb9471a16d3a5953f57c8298e962a to your computer and use it in GitHub Desktop.
Bash script to replace all SWEP.Primary.Damage = # with SWEP.Primary.Damage = nZCSODmg(#), meant for patching CSO weapons en masse
#!/usr/bin/env bash
WEAPON_LUA_PATH="$1"
patch_damage() {
weapon_lua_file="$1"
primary_damage_line=$(cat "$weapon_lua_file" | grep "SWEP.Primary.Damage")
# File has no SWEP.Primary.Damage set, probably not a weapon
[ -z "$primary_damage_line" ] && return
primary_damage_number=$(echo "$primary_damage_line" | grep -oE "[0-9]+" | head -n 1)
sed -i "s/SWEP.Primary.Damage.*/SWEP.Primary.Damage = nZCSODmg($primary_damage_number)/g" "$weapon_lua_file"
echo "Replacing $primary_damage_line with SWEP.Primary.Damage = nZCSODmg($primary_damage_number) in $weapon_lua_file"
}
export -f patch_damage
find "$WEAPON_LUA_PATH" -type f -name "*.lua" -exec bash -c 'patch_damage "$0"' {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment