Adjusting projectile speed and reload in BAR tweakdefs

Changing weapon reload and projectile velocity for all units requires iterating over multiple weapon levels inside each unitdef. Missing the nested iteration is the most common code error.

Tags: beyond all reason, modding, weapondefs, tweakdefs, projectile speed, lua, unitdefs

The nested weapon problem

UnitDefs holds a weapondefs subtable per unit. Each weapondefs entry can contain multiple weapon definitions. Accessing weapondefs.reloadtime directly only catches units with exactly one weapon and fails silently for everything else.

The correct approach iterates over UnitDefs, checks for weapondefs existence, then iterates over the weapondefs subtable to modify each weapon individually.

Reload and velocity changes

Dividing reloadtime by a factor and multiplying weaponvelocity by the same factor keeps a weapon's effective range behavior similar while making it fire faster with quicker projectiles. A delta of 1.8 gives noticeably snappier engagements.

Always check that the specific property exists before modifying it. Not every weapon has reloadtime or weaponvelocity defined.

Finding widget examples

The BAR GitHub repository contains widget examples. Any widget with a cmd_ or gui_ prefix demonstrates UI drawing, click handling, or unit interaction. Start with those to understand the patterns before writing your own.

Creed of champions

Learning to mod BAR teaches precision and patience. Those habits translate directly into better in-game decision making. Creed of Champions brings together players who value careful play and mutual support.

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