Practical BAR Modding Notes from Modding-0107

How to edit weapon damage stats in BAR using tweakdefs and Lua unitdefs iteration.

Tags: modding, weapondefs, unitdefs, lua, tweakunits

Editing weapon damage stats

Changing damage values in BAR requires targeting the correct path in the weapondefs table. The universal pattern iterates all units and reaches into each weapondef:

for name, ud in pairs(UnitDefs) do
  for weaponName, wd in pairs(ud.weapondefs) do
    wd.damage.default = 100
  end
end

This applies the change to every weapon on every unit. For global tweaks this works well. For targeted changes use a specific weapon name check.

Targeting a single weapon across all units

To modify one named weapon, add a guard:

for name, ud in pairs(UnitDefs) do
  if ud.weapondefs and ud.weapondefs.pineappleofdoom then
    ud.weapondefs.pineappleofdoom.damage.default = 40
  end
  end

The nil check on ud.weapondefs prevents errors on units that lack weapon definitions entirely. Every unit def does not carry the same subtables.

Tweakunits versus tweakdefs for single-unit edits

Looping through all of UnitDefs makes sense for bulk changes. For a single unit, tweakunits provides a cleaner interface without any Lua loops. The tradeoff is flexibility. Tweakunits accepts table-overwrite definitions without code. Tweakdefs runs actual Lua, which allows conditionals and loops.

Use tweakunits when changing one or two specific units. Use tweakdefs when the change affects many units or requires logic beyond simple value replacement.

Adding weapondefs without existing if statements

Some modders wrap changes in if statements that filter by unit name. Removing the filter allows the change to apply universally:

for name, ud in pairs(UnitDefs) do
  for weaponName, wd in pairs(ud.weapondefs) do
    if name == "legbastion" then
      wd.damage.default = 40
    end
  end
end

This pattern works but iterates the full unit list for a single unit. Direct access is more efficient for isolated changes.

Creed of Champions

Good modding habits translate to good game habits. Test thoroughly, use the right tool for the job, and share working code with others who are still figuring it out.

The removal of toxicity, the goal of fun and learning, makes for a refreshing spot to play and spend time. It has also made a game with plenty of complexity a bit less daunting to dive into.