Use exp_statistics in place of the legacy statistics

Remove the tracking and config from exp_legacy along with its
exp-statistics locale, which now ships with exp_statistics.

The player stats GUI stays in exp_scenario and reads the new module. It
uses the online player dropdown from exp_scenario's elements, so moving
it would make exp_statistics depend on exp_scenario, and its
exp_scenario.gui.playerdata permission is already in the seeded roles.

The readme data tab shows the statistics from the new module above the
remaining PlayerData.Statistics children, which is only LocalLanguage
now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-14 22:45:15 +00:00
1 parent d1b22dd4e7
commit 237200e6c8
10 files changed
+38 -488

No files matched your search

@@ -5,7 +5,4 @@
-- @config File-Loader
return {
"expcore.player_data", -- must be loaded first to register event handlers
--- Data
"modules.data.statistics",
}
-46
View File
@@ -1,46 +0,0 @@
--- A list of all tracked statistics and the events which trigger them
-- @config Statistics
local e = defines.events -- order as per lua api as it was easier just to go down the list
return {
MapsPlayed = true, --- @setting MapsPlayed If the number of maps which a player has played should be tracked
Playtime = true, --- @setting Playtime If playtime is tracked for a player, play time measured in minutes
AfkTime = true, --- @setting AfkTime If afk time is tracked for a player, play time measured in minutes, afk is once a player does nothing for 5 minutes
DistanceTravelled = true, --- @setting DistanceTravelled If distance Travelled is checked, only counts if not afk
MachinesRemoved = true, --- @setting MachinesRemoved If removed machines are tracked, includes marked for decon and player mined entity
TreesDestroyed = true, --- @setting OreMined If ore mined is tracked for a player, includes marked for decon and player mined entity but only trees
OreMined = true, --- @setting OreMined If ore mined is tracked for a player, includes player mined entity but only ore
DamageDealt = true, --- @setting DamageDealt If damage dealt is tracked for a player, includes any damage to entities not on the same force or neutral
Kills = true, --- @setting Kills If kills are tracked for a player, includes all kills not on same force or neutral
RocketsLaunched = true, --- @setting RocketsLaunched If the number of rockets launched should be tracked, done for all players on the force
ResearchCompleted = true, --- @setting ResearchCompleted If the number of researches completed should be tracked, done for all players on the force
counters = { --- @setting counters Simple statistics that just go up by one each time an event happens
MachinesBuilt = e.on_built_entity,
MapTagsMade = e.on_chart_tag_added,
ChatMessages = e.on_console_chat,
CommandsUsed = e.on_console_command,
ItemsPickedUp = e.on_picked_up_item,
TilesBuilt = e.on_player_built_tile,
ItemsCrafted = e.on_player_crafted_item,
DeconstructionPlannerUsed = e.on_player_deconstructed_area,
Deaths = e.on_player_died,
JoinCount = e.on_player_joined_game,
TilesRemoved = e.on_player_mined_tile,
CapsulesUsed = e.on_player_used_capsule,
EntityRepaired = e.on_player_repaired_entity,
},
display_order = { --- @setting display_order The order that the statistics should be shown in when in a gui or command
"Playtime", "AfkTime",
"MapsPlayed", "JoinCount",
"ChatMessages", "CommandsUsed",
"RocketsLaunched", "ResearchCompleted",
"MachinesBuilt", "MachinesRemoved",
"TilesBuilt", "TilesRemoved",
"TreesDestroyed", "OreMined",
"ItemsCrafted", "ItemsPickedUp",
"Kills", "Deaths",
"DamageDealt", "DistanceTravelled",
"CapsulesUsed", "EntityRepaired",
"DeconstructionPlannerUsed", "MapTagsMade",
},
}
-66
View File
@@ -19,72 +19,6 @@ Bonus=Player Bonus
Bonus-tooltip=The bonus given to your character
Bonus-value-tooltip=Change by using /bonus
[exp-statistics]
MapsPlayed=Maps Played
MapsPlayed-tooltip=The number of unique maps you have played on
JoinCount=Join Count
JoinCount-tooltip=The number of times you have joined our servers
Playtime=Playtime
Playtime-tooltip=The amount of time you have spent on our servers
AfkTime=AFK Time
AfkTime-tooltip=The amount of time you have been AFK on our servers
ChatMessages=Messages
ChatMessages-tooltip=The number of messages you have sent in chat
CommandsUsed=Commands
CommandsUsed-tooltip=The number of commands you have used
RocketsLaunched=Rockets Launched
RocketsLaunched-tooltip=The number of rockets launched while you were online
ResearchCompleted=Research Completed
ResearchCompleted-tooltip=The number of research projects completed while you were online
MachinesBuilt=Machines Built
MachinesBuilt-tooltip=The number of machines you have built
MachinesRemoved=Machines Removed
MachinesRemoved-tooltip=The number of machines you have removed
TilesBuilt=Tiles Placed
TilesBuilt-tooltip=The number of tiles you have placed
TilesRemoved=Tiles Removed
TilesRemoved-tooltip=The number of tiles you have removed
TreesDestroyed=Trees Destroyed
TreesDestroyed-tooltip=The number of trees you have destroyed
OreMined=Ore Mined
OreMined-tooltip=The amount of ore you have mined
ItemsCrafted=Items Crafted
ItemsCrafted-tooltip=The number of items you have crafted
ItemsPickedUp=Items Picked Up
ItemsPickedUp-tooltip=The number of items you have picked up
Kills=Kills
Kills-tooltip=The number of biters and biter bases you have squished
Deaths=Deaths
Deaths-tooltip=The number of times you have died
DamageDealt=Damage Dealt
DamageDealt-tooltip=The amount of damage you have dealt to other forces
DistanceTravelled=Distance Travelled
DistanceTravelled-tooltip=The total distance in tiles that you have travelled
CapsulesUsed=Capsules Used
CapsulesUsed-tooltip=The number of capsules you have used
EntityRepaired=Machines Repaired
EntityRepaired-tooltip=The number of machines which you have repaired
DeconstructionPlannerUsed=Decon Planner Used
DeconstructionPlannerUsed-tooltip=The number of times you have used the deconstruction planner
MapTagsMade=Map Tags Created
MapTagsMade-tooltip=The number of map tags you have created
DamageDeathRatio=Damage Death Ratio
DamageDeathRatio-tooltip=Damage over Death
KillDeathRatio=Kill Death Ratio
KillDeathRatio-tooltip=Kill over Death
SessionTime=Session Time
SessionTime-tooltip=Session Time
BuildRatio=Build Ratio
BuildRatio-tooltip=Build over Remove
RocketPerHour=Rocket Per Hour
RocketPerHour-tooltip=Rocket Launched Over Play Time in Hour
TreeKillPerMinute=Tree Kill Per Minute
TreeKillPerMinute-tooltip=Tree Destroyed Per Minute
NetPlayTime=Net Play Time
NetPlayTime-tooltip=Net Play Time
AFKTimeRatio=AFK Time Ratio
AFKTimeRatio-tooltip=AFK Time over Play Time
# expcore
[expcore-data]
description-preference=Allows you to set/get your data saving preference.
-66
View File
@@ -19,72 +19,6 @@ Bonus=人物附加屬性
Bonus-tooltip=你的人物附加屬性
Bonus-value-tooltip=使用 /bonus 來更改
[exp-statistics]
MapsPlayed=地圖遊玩次數
MapsPlayed-tooltip=你在本服務器遊玩過的地圖數
JoinCount=登入次數
JoinCount-tooltip=你在本服務器遊玩的次數
Playtime=遊玩時間
Playtime-tooltip=你在本服務器遊玩的時間
AfkTime=掛機時間
AfkTime-tooltip=你在本服務器掛機的時間
ChatMessages=傳送信息次數
ChatMessages-tooltip=你在本服務器發送信息的次數
CommandsUsed=使用指令次數
CommandsUsed-tooltip=你在本服務器使用指令的次數
RocketsLaunched=火箭發射次數
RocketsLaunched-tooltip=你在本服務器在線時所發射過火箭的次數
ResearchCompleted=研究次數
ResearchCompleted-tooltip=你在本服務器在線時完成研究的次數
MachinesBuilt=機器建造次數
MachinesBuilt-tooltip=你在本服務器建造過機器的次數
MachinesRemoved=機器拆除次數
MachinesRemoved-tooltip=你在本服務器拆除過機器的次數
TilesBuilt=地磚建造次數
TilesBuilt-tooltip=你在本服務器建造過地磚的次數
TilesRemoved=地磚拆除次數
TilesRemoved-tooltip=你在本服務器拆除過地磚的次數
TreesDestroyed=樹木拆除次數
TreesDestroyed-tooltip=你在本服務器拆除過樹木的次數
OreMined=挖礦次數
OreMined-tooltip=你在本服務器挖掘礦的次數
ItemsCrafted=物品合成數
ItemsCrafted-tooltip=你在本服務器合成過物品的次數
ItemsPickedUp=物品拾起數
ItemsPickedUp-tooltip=你在本服務器起過物品的次數
Kills=撃殺數
Kills-tooltip=你在本服務器殺過的敵人數量
Deaths=死亡次數
Deaths-tooltip=你在本服務器死過的數量
DamageDealt=傷害量
DamageDealt-tooltip=你在本伺服器對敵人所造成的傷害量
DistanceTravelled=移動距離
DistanceTravelled-tooltip=你在本服務器的總移動距離
CapsulesUsed=膠囊使用次數
CapsulesUsed-tooltip=你在本服務器使用過膠囊的次數
EntityRepaired=機器維修次數
EntityRepaired-tooltip=你在本服務器維修過機器的次數
DeconstructionPlannerUsed=拆除規劃器使用次數
DeconstructionPlannerUsed-tooltip=你在本服務器使用過拆除規劃器的次數
MapTagsMade=地圖標籤數量
MapTagsMade-tooltip=你在本服務器放過的地圖標籤數量
DamageDeathRatio=傷害死亡比
DamageDeathRatio-tooltip=傷害除以死亡
KillDeathRatio=撃殺死亡比
KillDeathRatio-tooltip=撃殺除以死亡
SessionTime=平均遊玩時間
SessionTime-tooltip=平均遊玩時間
BuildRatio=建築比
BuildRatio-tooltip=建築次數除以拆除次數
RocketPerHour=每小時火箭發射次數
RocketPerHour-tooltip=火箭發射次數除以遊玩時間
TreeKillPerMinute=每分鐘樹木拆除數
TreeKillPerMinute-tooltip=樹木拆除數除以遊玩時間
NetPlayTime=淨遊玩時間
NetPlayTime-tooltip=遊玩時間減掛機時間
AFKTimeRatio=掛機時間比
AFKTimeRatio-tooltip=掛機時間除以遊玩時間
# expcore
[expcore-data]
description-preference=允許寫入資料。
-66
View File
@@ -19,72 +19,6 @@ Bonus=人物附加屬性
Bonus-tooltip=你的人物附加屬性
Bonus-value-tooltip=使用 /bonus 來更改
[exp-statistics]
MapsPlayed=地圖遊玩次數
MapsPlayed-tooltip=你在本服務器遊玩過的地圖數
JoinCount=登入次數
JoinCount-tooltip=你在本服務器遊玩的次數
Playtime=遊玩時間
Playtime-tooltip=你在本服務器遊玩的時間
AfkTime=掛機時間
AfkTime-tooltip=你在本服務器掛機的時間
ChatMessages=傳送信息次數
ChatMessages-tooltip=你在本服務器發送信息的次數
CommandsUsed=使用指令次數
CommandsUsed-tooltip=你在本服務器使用指令的次數
RocketsLaunched=火箭發射次數
RocketsLaunched-tooltip=你在本服務器在線時所發射過火箭的次數
ResearchCompleted=研究次數
ResearchCompleted-tooltip=你在本服務器在線時完成研究的次數
MachinesBuilt=機器建造次數
MachinesBuilt-tooltip=你在本服務器建造過機器的次數
MachinesRemoved=機器拆除次數
MachinesRemoved-tooltip=你在本服務器拆除過機器的次數
TilesBuilt=地磚建造次數
TilesBuilt-tooltip=你在本服務器建造過地磚的次數
TilesRemoved=地磚拆除次數
TilesRemoved-tooltip=你在本服務器拆除過地磚的次數
TreesDestroyed=樹木拆除次數
TreesDestroyed-tooltip=你在本服務器拆除過樹木的次數
OreMined=挖礦次數
OreMined-tooltip=你在本服務器挖掘礦的次數
ItemsCrafted=物品合成數
ItemsCrafted-tooltip=你在本服務器合成過物品的次數
ItemsPickedUp=物品拾起數
ItemsPickedUp-tooltip=你在本服務器起過物品的次數
Kills=撃殺數
Kills-tooltip=你在本服務器殺過的敵人數量
Deaths=死亡次數
Deaths-tooltip=你在本服務器死過的數量
DamageDealt=傷害量
DamageDealt-tooltip=你在本伺服器對敵人所造成的傷害量
DistanceTravelled=移動距離
DistanceTravelled-tooltip=你在本服務器的總移動距離
CapsulesUsed=膠囊使用次數
CapsulesUsed-tooltip=你在本服務器使用過膠囊的次數
EntityRepaired=機器維修次數
EntityRepaired-tooltip=你在本服務器維修過機器的次數
DeconstructionPlannerUsed=拆除規劃器使用次數
DeconstructionPlannerUsed-tooltip=你在本服務器使用過拆除規劃器的次數
MapTagsMade=地圖標籤數量
MapTagsMade-tooltip=你在本服務器放過的地圖標籤數量
DamageDeathRatio=傷害死亡比
DamageDeathRatio-tooltip=傷害除以死亡
KillDeathRatio=撃殺死亡比
KillDeathRatio-tooltip=撃殺除以死亡
SessionTime=平均遊玩時間
SessionTime-tooltip=平均遊玩時間
BuildRatio=建築比
BuildRatio-tooltip=建築次數除以拆除次數
RocketPerHour=每小時火箭發射次數
RocketPerHour-tooltip=火箭發射次數除以遊玩時間
TreeKillPerMinute=每分鐘樹木拆除數
TreeKillPerMinute-tooltip=樹木拆除數除以遊玩時間
NetPlayTime=淨遊玩時間
NetPlayTime-tooltip=遊玩時間減掛機時間
AFKTimeRatio=掛機時間比
AFKTimeRatio-tooltip=掛機時間除以遊玩時間
# expcore
[expcore-data]
description-preference=允許寫入資料。
@@ -1,208 +0,0 @@
local ExpUtil = require("modules/exp_util")
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Storage = require("modules/exp_util/storage") --- @dep utils.global
local config = require("modules.exp_legacy.config.statistics") --- @dep config.statistics
local floor = math.floor
local afk_required = 5 * 3600 -- 5 minutes
--- Stores players who have been created, required to avoid loss of data
local new_players = {}
Storage.register(new_players, function(tbl)
new_players = tbl
end)
--- Stores the statistics on a player
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
local AllPlayerData = PlayerData.All
local Statistics = PlayerData.Statistics
Statistics:set_metadata{
display_order = config.display_order,
}
--- Update your statistics with any which happened before the data was valid
Statistics:on_load(function(player_name, player_statistics)
local existing_data = AllPlayerData:get(player_name)
if existing_data and existing_data.valid then return end
local counters = config.counters
-- Merge all data from before you data loaded
for key, value in pairs(Statistics:get(player_name, {})) do
if config[key] or counters[key] then
if not player_statistics[key] then
player_statistics[key] = value
else
player_statistics[key] = player_statistics[key] + value
end
end
end
-- Increment your maps played if this is your first time on this map
if new_players[player_name] then
new_players[player_name] = nil
local ctn = player_statistics.MapsPlayed
player_statistics["MapsPlayed"] = ctn and ctn + 1 or 1
end
return player_statistics
end)
local long_time_format = ExpUtil.format_time_factory_locale{ format = "long", coefficient = 3600, hours = true, minutes = true }
local short_time_format = ExpUtil.format_time_factory_locale{ format = "short", coefficient = 3600, hours = true, minutes = true }
--- Add MapsPlayed if it is enabled
if config.MapsPlayed then
Statistics:combine("MapsPlayed")
Event.add(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
new_players[player.name] = true
end)
end
--- Add Playtime and AfkTime if it is enabled
if config.Playtime or config.AfkTime then
local playtime, afk_time
if config.Playtime then
playtime = Statistics:combine("Playtime")
playtime:set_metadata{ stringify = long_time_format, stringify_short = short_time_format }
end
if config.AfkTime then
afk_time = Statistics:combine("AfkTime")
afk_time:set_metadata{ stringify = long_time_format, stringify_short = short_time_format }
end
Event.on_nth_tick(3600, function()
if game.tick == 0 then return end
for _, player in pairs(game.connected_players) do
if playtime then playtime:increment(player) end
if afk_time and player.afk_time > afk_required then afk_time:increment(player) end
end
end)
end
--- Add DistanceTravelled if it is enabled
if config.DistanceTravelled then
local stat = Statistics:combine("DistanceTravelled")
stat:set_metadata{ unit = " tiles" }
Event.add(defines.events.on_player_changed_position, function(event)
local player = game.players[event.player_index]
if not player.valid or not player.connected or player.afk_time > afk_required then return end
stat:increment(player)
end)
end
--- Add MachinesRemoved and TreesDestroyed and config.OreMined if it is enabled
if config.MachinesRemoved or config.TreesDestroyed or config.OreMined then
local machines, trees, ore
if config.MachinesRemoved then machines = Statistics:combine("MachinesRemoved") end
if config.TreesDestroyed then trees = Statistics:combine("TreesDestroyed") end
if config.OreMined then ore = Statistics:combine("OreMined") end
local function on_event(event)
if not event.player_index then return end -- Check player is valid
local player = game.players[event.player_index]
if not player.valid or not player.connected then return end
local entity = event.entity -- Check entity is valid
if not entity.valid then return end
if entity.type == "resource" then
ore:increment(player)
elseif entity.type == "tree" then
trees:increment(player)
elseif entity.force == player.force then
machines:increment(player)
end
end
Event.add(defines.events.on_marked_for_deconstruction, on_event)
Event.add(defines.events.on_player_mined_entity, on_event)
end
--- Vehicles which credit their driver, or failing that their passenger, with what they hit
local crewed_vehicles = { car = true, ["spider-vehicle"] = true, locomotive = true }
--- Get the connected player behind the cause of damage or a death, nil for turrets, trains without a crew and the like
--- @param cause LuaEntity?
--- @return LuaPlayer?
local function get_cause_player(cause)
if not cause or not cause.valid then return nil end
local occupant = cause --- @type LuaEntity | LuaPlayer
if crewed_vehicles[cause.type] then
local crew = cause.get_driver() or cause.get_passenger()
if not crew then return nil end
occupant = crew
end
local player --- @type LuaPlayer?
if occupant.object_name == "LuaPlayer" then
player = occupant --[[@as LuaPlayer]]
elseif occupant.type == "character" then
player = occupant.player
end
if not player or not player.valid or not player.connected then return nil end
return player
end
--- Check that damage or a death counts against an entity, it must be hostile to the player
--- @param entity LuaEntity
--- @param player LuaPlayer
--- @return boolean
local function is_hostile(entity, player)
return entity.valid and entity.force ~= player.force and entity.force.name ~= "neutral"
end
--- Add DamageDealt if it is enabled
if config.DamageDealt then
local stat = Statistics:combine("DamageDealt")
Event.add(defines.events.on_entity_damaged, function(event)
local player = get_cause_player(event.cause)
if not player or not is_hostile(event.entity, player) then return end
stat:increment(player, floor(event.final_damage_amount))
end)
end
--- Add Kills if it is enabled
if config.Kills then
local stat = Statistics:combine("Kills")
Event.add(defines.events.on_entity_died, function(event)
local player = get_cause_player(event.cause)
if not player or not is_hostile(event.entity, player) then return end
stat:increment(player)
end)
end
--- Add RocketsLaunched if it is enabled
if config.RocketsLaunched then
local stat = Statistics:combine("RocketsLaunched")
Event.add(defines.events.on_rocket_launched, function(event)
local silo = event.rocket_silo -- Check silo is valid
if not silo or not silo.valid then return end
local force = silo.force -- Check force is valid
if not force or not force.valid then return end
for _, player in pairs(force.connected_players) do
stat:increment(player)
end
end)
end
--- Add RocketsLaunched if it is enabled
if config.ResearchCompleted then
local stat = Statistics:combine("ResearchCompleted")
Event.add(defines.events.on_research_finished, function(event)
local research = event.research -- Check research is valid
if event.by_script or not research or not research.valid then return end
local force = research.force -- Check force is valid
if not force or not force.valid then return end
for _, player in pairs(force.connected_players) do
stat:increment(player)
end
end)
end
--- Add all the remaining statistics from the config
for statistic, event_name in pairs(config.counters) do
local stat = Statistics:combine(statistic)
Event.add(event_name, function(event)
if not event.player_index then return end
local player = game.players[event.player_index]
if not player.valid or not player.connected then return end
stat:increment(player)
end)
end