Counting units, disabling gadgets, and modifying spy explosions in BAR

Modding Beyond All Reason covers three common problems. Tracking specific unit counts during a match requires engine callbacks. Gadget control through tweak units has hard limits. Weapon explosions like the spy bomb live in separate weapon definition files that need special handling.

Tags: beyond all reason, MetaUnit count, tweakunits, gadget disabling, spy explosion, unit tracking, lua modding

Counting units on the map

Getting the count of a specific unit type in real time uses the MetaUnitCreated() and MetaUnitDestroyed() engine callbacks. Each callback fires when a unit spawns or dies. Track the numbers yourself by incrementing on creation and decrementing on destruction.

This bookkeeping approach gives you an always-current count without polling every frame, which would waste resources.

Disabling gadgets through tweakunits

Direct gadget enable or disable is not available through the tweakunits interface. The workaround intentionally triggers an error in the gadget to force it down. This is not elegant but it functions in practice.

Players trying to selectively enable commander hats through tweaks find this limitation a real blocker.

Changing the spy explosion

The spy bomb explosion lives in spybombx.lua under the weapons directory. Tweakunits can swap it to a different preexisting explosion type but cannot create entirely custom explosion effects through the tweak system alone.

Practical modding limits

Understanding what tweaks can and cannot do saves time. The engine callback system for unit counting is the right tool for that job. Tweakunits handles unit statistics but not gadget lifecycle management.

[Crd] 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.