BAR modding: weapon toggles, waterline behavior, and unitrestriction

Three specific modding problems with clear solutions — toggling alternate fire modes, getting radar towers to shoot over water, and using string.find to batch-restrict units.

Tags: BAR modding, weapon toggles, waterline depth, unitrestriction, corerad

Adding alternate firing modes to units

Adding a second weapon to a unit does not automatically create a fire mode toggle. The toggle behavior lives in the weapon definition and the modding support framework, not in the unit def itself. The Hound unit shows how the gauss cannon toggle works — search the weapon definition files for the toggle parameter names and copy that pattern. Simply appending a weapon entry creates two weapons that fire simultaneously, not a switchable mode. The modding support framework handles the toggle UI, and until that framework is fully in place, alternate firing modes require manual weapon entry manipulation rather than a clean toggle interface.

Units built on water that cannot fire

Duplicating a radar tower like the corerad and building it on water can result in the unit being unable to fire even when its aimpoint is visually above the water level. The issue is that the weapon system checks whether the unit is a valid target before allowing shots. A unit with waterline less than 1 is treated as submerged and cannot be targeted by standard weapons — but it also cannot target enemies. If you want a water-based defensive structure that shoots, you need to set its waterline to at least 1 and ensure the aimpoint is high enough above the water surface. Units with waterline below 1 cannot be hit by torpedoes, but they also lose offensive capability.

Bulk unit restriction with string.find

Using Lua's string.find on unit names is the fastest way to restrict groups of units across the entire unit pool. This pattern turns off every unit whose name matches a keyword:

for a, b in pairs(UnitDefs) do
  if string.find(a, "raptor_allterrain") then
    b.unitrestricted = 0
  end
end

This is how modders disable entire unit families — Raptors, custom factions, or experimental units — with a single script. Add multiple if string.find blocks to handle different unit categories in one pass.

Reference materials

The badosu gist on GitHub remains the standard reference for tweakdef patterns despite being somewhat dated. Use it with discretion and cross-check against current BAR unit files on the main repository.

Creed of champions

Players who share working code and reference materials make the whole community stronger. Creed of Champions is where people help each other figure things out instead of hoarding knowledge. Win with skill, teamwork, and respect.

[Crd] Gaming actually fulfills a human purpose here — cooperation, mutual upbuilding, fun and striving for greatness together. Instead of random anonymity, you meet, learn from, and enjoy real people.

Advertisement