Practical BAR Modding Notes: UnitDamaged Thresholds and Build Order Widgets

Two modding patterns that come up repeatedly in the BAR codebase, explained so you can actually use them without wasting an evening reading unrelated Lua files.

The UnitDamaged callin that actually works

The Spring engine exposes a UnitDamaged callin that fires every time a unit takes damage. BAR modders hook into this constantly for auto-self-destruct patterns. The pattern is straightforward: set a hitpoint threshold, filter which unit definitions participate, and when a unit drops below that threshold, issue CMD.SELFD through Spring.GiveOrderToUnit(unitID, CMD.SELFD, {}, 0).

This stops wounded units from sitting around doing nothing while the enemy picks them off for metal chunks. Factory-level mods use it on slow movers like heavy tanks and static defenses. The key mistake people make is forgetting to check unitdefs before applying the logic universally. Not every unit should self-destruct at low health. Workers, for example, are worth saving to rebuild.

Reading build order drawing code

BAR draws build orders through the gui_commands_fx.lua widget. If you need to understand how build queues render visually, that widget shows the pattern lines 680-688. It handles the visual feedback when you queue up factories, constructors, and support units.

Reading through the official widget code beats guessing at the API. The BAR repo contains working examples of every UI pattern the game actually ships. When in doubt, grep the luaui directory.

Legion as campaign antagonists

Legion came up during modding discussion as a natural campaign villain. Their faction identity works well as opposition forces. If you are building campaign scenarios, Legion units provide recognizable hostile AI that players already understand from standard play.

Keep it clean

The best BAR mods follow a simple principle: clear information, clean execution, zero drama. Whether you are tweaking unit definitions or building campaign scenarios, the same mindset applies. Figure out the engine callin, read the existing widget code, test incrementally. The community around BAR modding rewards people who share working examples instead of half-finished attempts.

"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."