Only log a rocket as fired when its ammo count drops - #465
Merged
Conversation
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
Cooldude2606
requested changes
Sep 6, 2026
| --- 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 |
Member
There was a problem hiding this comment.
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
approved these changes
Sep 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.