Private
Public Access
1
0
Files
lua-prometheus-exporter/game-stats.lua
2026-01-10 18:24:52 +01:00

120 lines
4.3 KiB
Lua

---Sends all mod infos for the current game, should only be called on the first load of the map since mods don't change during runtime
function GetMods()
local mods = script.active_mods
local modstring = "---mod-info---\n"
for k, v in pairs(mods) do
modstring = modstring .. ("%s:%s\n"):format(k, v)
end
SendChunked(modstring)
end
function GetPlayerColors()
local colorParts = {}
colorParts[#colorParts + 1] = "---player-colors---\n"
for index, player in pairs(game.players) do
local colorSettings = player.color
colorParts[#colorParts + 1] = ("%d:%s:%d:%d:%d:%d"):format(index, player.name, colorSettings.r, colorSettings.g,
colorSettings.b, colorSettings.a)
end
return table.concat(colorParts, "\n")
end
function GetPlayerKills()
local killParts = {}
killParts[#killParts + 1] = "---player-kills---\n"
for killerIndex, victims in pairs(storage.playerKillCount) do
for victimIndex, kills in pairs(victims) do
local killerName = game.players[killerIndex].name
local victimName = game.players[victimIndex].name
killParts[#killParts + 1] = ("%s:%s:%s:%s:%d"):format(killerName, killerIndex, victimName, victimIndex, kills)
end
end
return table.concat(killParts, "\n")
end
function SendPlayerEntityStats()
local entityParts = {}
entityParts[#entityParts + 1] = "---player-build-stats---"
for playerIndex, items in pairs(storage.constructedEntites) do
local playerName = game.players[playerIndex].name
for itemName, itemCount in pairs(items) do
entityParts[#entityParts + 1] = ("%s:%s:constructed:%s:%s"):format(playerIndex, playerName, itemName, itemCount)
end
end
SendChunked("---player-build-stats---\n" .. table.concat(entityParts,"\n"))
entityParts = {}
entityParts[#entityParts + 1] = "---player-build-stats---"
for playerIndex, items in pairs(storage.deconstructedEntities) do
local playerName = game.players[playerIndex].name
for itemName, itemCount in pairs(items) do
entityParts[#entityParts + 1] = ("%s:%s:deconstructed:%s:%s"):format(playerIndex, playerName, itemName, itemCount)
end
end
SendChunked("---player-build-stats---\n" .. table.concat(entityParts,"\n"))
end
function GetMapSeed()
return ("---map-seed---\n%d"):format(game.surfaces["nauvis"].map_gen_settings.seed)
end
function GetRocketsLaunched()
return ("---rocket-launches---\n%d"):format(game.forces["player"].rockets_launched)
end
---Concats all player online times into a single string
---Takes all players that ever visited the server into account
---@return string
function GetPlayerTime()
local timeParts = {}
timeParts[#timeParts + 1] = "---player-times---\n"
for _, player in pairs(game.players) do
timeParts[#timeParts + 1] = ("%s:%d:%d"):format(player.name, player.index, player.online_time)
end
return table.concat(timeParts, "\n")
end
---comment
---@return string
function GetPlayerDeaths()
local deathParts = {}
deathParts[#deathParts + 1] = "---player-deaths---\n"
for _, player in pairs(game.players) do
deathParts[#deathParts + 1] = ("%s:%d:%d"):format(player.name, player.index,
storage.playerDeathCount[player.index] or 0)
end
return table.concat(deathParts, "\n")
end
function onPlayerDeath(event)
SendChunked(("---player-died---\n%s:%s:%d"):format(event.player_index,game.players[event.player_index].name,event.tick))
end
function GetPlayerDeathCauses()
local deathParts = {}
deathParts[#deathParts + 1] = "---player-death-cause---\n"
for playerIndex, deathCauses in pairs(storage.playerDeathCause) do
for causeName, causeCount in pairs(deathCauses) do
deathParts[#deathParts + 1] = ("%s:%d:%s:%d"):format(game.players[playerIndex].name, playerIndex, causeName,
causeCount)
end
end
return table.concat(deathParts, "\n")
end
function GetTotalPlayTime()
return ("---game-time---\n%d:%d"):format(game.tick, game.ticks_played)
end
function CheckReactor(event)
if not event and not event.entity then return end
if event.entity.name == "nuclear-reactor" then
if event.entity.temperature >= 900 then
storage.nuclearReactorDeaths = (storage.nuclearReactorDeaths or 0) + 1
end
end
end
function GetReactorExplosions()
return "---reactor-explosion---\n" .. (storage.nuclearReactorDeaths or 0)
end