Private
Public Access
1
0

Added more functions

Streamlined the process
This commit is contained in:
Jan Grießhaber
2025-12-29 16:32:47 +01:00
parent 149b085cb7
commit 5accb091b0
6 changed files with 133 additions and 112 deletions

View File

@@ -1,48 +1,42 @@
require("production-stats")
require("pollution-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
tickInterval = tonumber(settings.global["factorio-prometheus-exporter-tick-interval"].value) or 300
udpAddress = tonumber(settings.startup["factorio-prometheus-exporter-udp-address"].value) or 52555
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
serverIndex = 1
if game.is_multiplayer() then
serverIndex = 0
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)
storage.playerDeathCount[event.player_index] = (storage.playerDeathCount[event.player_index] or 0) + 1
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)
helpers.send_udp(udpAddress, ("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_runtime_mod_setting_changed, function(event)
if event.setting == "factorio-prometheus-exporter-tick-interval" then
tickInterval = settings.global["factorio-prometheus-exporter-tick-interval"].value
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)
--script.on_event(defines.events.on_tick, SendSurfaceStats)
script.on_nth_tick(tickInterval, SendProductionStats)
script.on_nth_tick(tickInterval, SendFluidProductionStats)
script.on_nth_tick(tickInterval, GetPollutionStats)