Creating a fake metal extractor with BAR tweakunits

How to build a pseudo mex using metalmake and energyupkeep values instead of actual extraction mechanics in custom BAR games.

Tags: bar modding, fake mex, metalmake, energymake, unitdefs, tweakunits

Metalmake versus extraction

A real metal extractor pulls metal from a specific map feature. A fake mex generates metal directly on the unit without needing a resource spot underneath it. This distinction matters when designing custom game modes or scenario maps where you want economic production at locations that lack natural deposits. The commander unit already has a metalmake value. In the Cortex commander file (corcom.lua), line 37 shows metalmake set to 2. That gives every commander two metal per second from nothing. You can raise that number to simulate a mex attached to the commander.

Writing the tweak definition

To apply metalmake changes across all factions, you can loop through each faction's commander unit and modify the UnitDefs table: ``` local UnitDefs, Factions = UnitDefs or {}, {"arm", "cor", "leg"} for _, faction in pairs(Factions) do local Unit = faction .. "com" if UnitDefs[Unit] then UnitDefs[Unit].metalmake = 50 UnitDefs[Unit].energyupkeep = -500 end end ``` This approach sets every faction's commander to produce 50 metal per second while consuming 500 energy. The negative energyupkeep means the commander draws energy from your grid, creating a tradeoff you can balance.

Finding the right unit properties

Each unit's Lua definition file lists available fields like metalmake, energymake, energystorage, and energyupkeep. The Spring Engine wiki documents unit definition fields, though it sometimes lags behind the latest Spring-based engines. Always check the actual unit Lua file in the BAR repository for current field names and default values. Geo feature files like armgeo.lua contain energymake values for map decorators. Metalmake does not appear in geo files because geo features define visual decoration, not economic output. Metalmake belongs in unit definitions.

Limitations to know about

Tweakdefs cannot create new unit types. It can only modify properties of existing units. If you want a standalone fake mex unit, you need a full mod that defines a new unit in a proper content directory, not just tweakdefs. Tweakunits works within the same constraint: it overrides existing unit properties but does not introduce new units into the game. For a true custom unit, your mod needs its own unit definition file with model references, build options, and gadget hooks. That sits outside the tweakdefs system entirely.

Why modders build this stuff

Custom game modes and practice scenarios benefit from controlled economy. Setting up a fake mex lets you create a predictable income source that does not depend on map layout. That is useful for testing build orders, practicing economic timing, or designing tutorial content where you control every variable players encounter.

"It is so easy to get on with everyone and there is zero toxicity. Just fun games of BAR which can have quite a toxic community usually." [Crd]

Clans like Creed of Champions use custom game modes for training nights and teaching sessions. Being able to control income levels means instructors can slow down or speed up games to match student readiness levels.

Advertisement