Bump version to 0.1.6, add player kill tracking, and enhance power/lab stats handling
This commit is contained in:
77
control.lua
77
control.lua
@@ -10,7 +10,6 @@ udpAddress = 52555
|
||||
isInitialized = false
|
||||
sendIndex = 0
|
||||
serverIndex = 0
|
||||
LabsScanned = false
|
||||
|
||||
options = {
|
||||
enableMod = false,
|
||||
@@ -34,6 +33,11 @@ script.on_init(function ()
|
||||
storage.totalResearchSpeed = 0
|
||||
storage.totalReseachProductivity = 0
|
||||
storage.labs = {}
|
||||
storage.playerKillCount = {}
|
||||
storage.representativePoles = {}
|
||||
|
||||
storage.scannedGrids = false
|
||||
storage.scannedLabs = false
|
||||
sendIndex = 0
|
||||
|
||||
options.enableMod = settings.global["factorio-metrics-exporter-enable"].value
|
||||
@@ -73,6 +77,11 @@ script.on_configuration_changed(function()
|
||||
storage.totalLabCount = storage.totalLabCount or 0
|
||||
storage.totalReseachProductivity = storage.totalReseachProductivity or 0
|
||||
storage.totalResearchSpeed = storage.totalResearchSpeed or 0
|
||||
storage.playerKillCount = storage.playerKillCount or {}
|
||||
storage.representativePoles = storage.representativePoles or {}
|
||||
storage.scannedGrids = storage.scannedGrids or false
|
||||
storage.scannedLabs = storage.scannedLabs or false
|
||||
ScanNetworks()
|
||||
end
|
||||
)
|
||||
|
||||
@@ -122,10 +131,22 @@ end)
|
||||
|
||||
|
||||
script.on_event(defines.events.on_player_died, function(event)
|
||||
if event.cause.is_player() then
|
||||
local killer_index = event.cause.player.index
|
||||
local victim_index = event.player_index
|
||||
|
||||
storage.playerKillCount[killer_index] =
|
||||
storage.playerKillCount[killer_index] or {}
|
||||
|
||||
storage.playerKillCount[killer_index][victim_index] =
|
||||
(storage.playerKillCount[killer_index][victim_index] or 0) + 1
|
||||
end
|
||||
--local player = game.get_player(event.player_index)
|
||||
storage.playerDeathCount[event.player_index] = (storage.playerDeathCount[event.player_index] or 0) + 1
|
||||
end)
|
||||
|
||||
|
||||
|
||||
function SendGameStats(event)
|
||||
local returnParts = {}
|
||||
returnParts[#returnParts+1] = GetMods()
|
||||
@@ -149,22 +170,23 @@ function SendAll(event)
|
||||
end
|
||||
isInitialized = true
|
||||
|
||||
log("ServerIndex is "..serverIndex.." now")
|
||||
--log("ServerIndex is "..serverIndex.." now")
|
||||
|
||||
if PowerGridScanned == false then
|
||||
GenerateNetworks()
|
||||
if storage.scannedGrids == false then
|
||||
ScanNetworks()
|
||||
storage.scannedGrids = true
|
||||
end
|
||||
|
||||
if LabsScanned == false then
|
||||
GenerateLabInfo()
|
||||
if storage.scannedLabs == false then
|
||||
ScanLabs()
|
||||
end
|
||||
|
||||
|
||||
if options.enableMod==true then
|
||||
|
||||
if (event.tick % math.floor(tickInterval/7) ~= 0) then return end
|
||||
if (event.tick % math.floor(tickInterval/8) ~= 0) then return end
|
||||
|
||||
sendIndex = (sendIndex % 7) + 1
|
||||
sendIndex = (sendIndex % 8) + 1
|
||||
if sendIndex == 1 then SendProductionStats() end
|
||||
if sendIndex == 2 then SendPollutionStats() end
|
||||
if sendIndex == 3 then SendKillStats() end
|
||||
@@ -172,6 +194,7 @@ function SendAll(event)
|
||||
if sendIndex == 5 then SendBuildStats() end
|
||||
if sendIndex == 6 then SendResearchStats() end
|
||||
if sendIndex == 7 then SendLogisticStats() end
|
||||
if sendIndex == 8 then SendPowerStats() end
|
||||
|
||||
if(event.tick % tickInterval*2 == 0) then
|
||||
if options.enablePlayers then
|
||||
@@ -180,13 +203,41 @@ function SendAll(event)
|
||||
end
|
||||
end
|
||||
|
||||
function UpdateStorage(event)
|
||||
if not event then return end
|
||||
if event.entity.type == "lab" then
|
||||
UpdateLabs(event)
|
||||
end
|
||||
if event.entity.type == "electric-pole" then
|
||||
AddPowerPole(event)
|
||||
end
|
||||
end
|
||||
|
||||
function RemoveStorage(event)
|
||||
if not event then return end
|
||||
if event.entity.type =="lab" then
|
||||
RemoveLab(event)
|
||||
end
|
||||
if event.entity.type == "electric-pole" then
|
||||
RemovePowerPole(event)
|
||||
end
|
||||
if event.entity.name == "crash-site-spaceship" then
|
||||
if event.name == defines.events.on_player_mined_entity then
|
||||
if settings.global["factorio-metrics-exporter-enable_denkmalschutz"].value == true then
|
||||
game.ban_player(event.player_index,"You violated the rules of DENKMALSCHUTZ!!!")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
script.on_event(defines.events.on_tick, SendAll)
|
||||
|
||||
--Script hooks for power stats
|
||||
script.on_event(defines.events.on_built_entity,UpdateGrids,{{filter = "type", type = "electric-pole"}})
|
||||
script.on_event(defines.events.on_player_mined_entity, PurgeNetworks,{{filter = "type", type = "electric-pole"}})
|
||||
script.on_event(defines.events.on_robot_built_entity,UpdateGrids,{{filter = "type", type = "electric-pole"}})
|
||||
script.on_event(defines.events.on_robot_mined_entity,PurgeNetworks,{{filter = "type", type = "electric-pole"}})
|
||||
--Script hooks for power and lab stats
|
||||
script.on_event(defines.events.on_built_entity,UpdateStorage,{{filter = "type", type = "electric-pole" or "lab"}})
|
||||
script.on_event(defines.events.on_player_mined_entity, RemoveStorage,{{filter = "type", type = "electric-pole"or "lab" or "container"}})
|
||||
script.on_event(defines.events.on_robot_built_entity,UpdateStorage,{{filter = "type", type = "electric-pole" or "lab"}})
|
||||
script.on_event(defines.events.on_robot_mined_entity,RemoveStorage,{{filter = "type", type = "electric-pole" or "lab" or "container"}})
|
||||
script.on_event(defines.events.on_entity_died,RemoveStorage,{{filter = "type", type = "electric-pole" or "lab" or "container"}})
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user