Skip to content

Only log a rocket as fired when its ammo count drops - #465

Merged
Cooldude2606 merged 2 commits into
explosivegaming:mainfrom
bbassie:fix/rocket-fired-log
Sep 6, 2026
Merged

Only log a rocket as fired when its ammo count drops#465
Cooldude2606 merged 2 commits into
explosivegaming:mainfrom
bbassie:fix/rocket-fired-log

Conversation

@bbassie

@bbassie bbassie commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #242.

There is no fired event, and the deconstruction log wrote a line on every on_player_ammo_inventory_changed, which fires when rockets are loaded for the first time and when swapping between rocket types. The log now keeps the last seen name and count of each of the player's ammo slots (in storage, per player, cleared when they leave) and only records a shot when a slot holds the same ammo with one fewer, or empties from a single round. Loading, swapping and picking ammo up all change the name or increase the count, so none of them log.

Two smaller changes fell out of this: every ammo slot is checked rather than only the selected gun, and only the three configured ammo types (rocket, explosive rocket, atomic bomb) are logged, where before any ammo change produced a shot-<ammo> line.

Lua lint is clean and the scenario loads on my dev instance. Firing itself needs a player, so the count logic is untested in game.

Factorio has no fired event, so the log was written on every ammo
inventory change, which includes loading rockets for the first time and
swapping between rocket types. The last seen name and count of each ammo
slot is now kept per player, and a shot is only logged when a slot holds
the same ammo with one fewer, or empties from a single round. Only the
three configured ammo types are logged, rather than every ammo change.

Fixes explosivegaming#242
--- Forget the ammo of a player who left, their slots are read again on the next change
--- @param event EventData.on_player_left_game
local function on_player_left_game(event)
ammo_slots[event.player_index] = nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we clear on leave, this means that the first shot is never logged. This is a gap in coverage. We need to repopulate the table on player join before their ammo count changes for the first time.

Clearing the slots on leave meant nothing was known about a player's ammo
until it changed, so the first shot after rejoining was missed. The slots
are now read when a player joins and when they respawn, since a new
character starts empty and a stale single round would otherwise count as
a shot. The change handler reads the slots the same way and compares them
with what was stored.
@Cooldude2606
Cooldude2606 merged commit 58c2ad6 into explosivegaming:main Sep 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positives for rocket fired event log

2 participants