Private
Public Access
1
0
Files
lua-prometheus-exporter/control.lua
Jan Grießhaber 149b085cb7 Initial Commit
2025-12-28 18:48:24 +01:00

49 lines
1.8 KiB
Lua

require("production-stats")
-- control.lua for factorio-prometheus-exporter
-- Adds a handler for player movement (on_player_changed_position)
---@param event EventData.on_tick
local function SendSurfaceStats(event)
if event.tick % 300 ~= 0 then return end
helpers.send_udp(52555, game.tick,1)
for _,surface in pairs(game.surfaces) do
local surface_name = surface.name
local productionStat = CreateItemStatisticsString(game.forces["player"].get_item_production_statistics(surface_name), surface)
local fluidStat = CreateFluidStatisticsString(game.forces["player"].get_fluid_production_statistics(surface_name), surface)
local deathStat = CreateDeathStatisticsString(game.forces["player"].get_kill_count_statistics(surface_name), surface)
helpers.send_udp(52555, productionStat..fluidStat..deathStat,1)
end
end
-- Register the handler for the player movement event
--script.on_event(defines.events.on_player_changed_position, on_player_moved)
script.on_event(defines.events.on_player_died, function(event)
local player = game.get_player(event.player_index)
if not player then return end
local index = event.player_index
helpers.send_udp(52555, ("player-death %s %d"):format(player.name, player.index),index)
end)
script.on_event(defines.events.on_player_joined_game, function(event)
local player = game.get_player(event.player_index)
if not player then return end
local index = event.player_index
helpers.send_udp(52555, ("player-join %s %d"):format(player.name, player.index),index)
end)
function GetAllPlayers()
for _,player in pairs(game.players) do
end
end
--script.on_event(defines.events.on_player_joined_game, on_player_joined)
--script.on_nth_tick(300, SendSurfaceStats)
script.on_event(defines.events.on_tick, SendSurfaceStats)