Enhance player kill tracking and update lab scanning logic
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"Lua.workspace.userThirdParty": [
|
"Lua.workspace.userThirdParty": [
|
||||||
"c:\\Users\\jangr\\AppData\\Roaming\\Code\\User\\workspaceStorage\\071322d83ef859d27b899371aa0efcc4\\justarandomgeek.factoriomod-debug\\sumneko-3rd"
|
"c:\\Users\\jangr\\AppData\\Roaming\\Code\\User\\workspaceStorage\\ebd0abbb61655c51088fab51f622e068\\justarandomgeek.factoriomod-debug\\sumneko-3rd"
|
||||||
],
|
],
|
||||||
"Lua.workspace.checkThirdParty": "ApplyInMemory",
|
"Lua.workspace.checkThirdParty": "ApplyInMemory",
|
||||||
"factorio.versions": [
|
"factorio.versions": [
|
||||||
|
|||||||
56
control.lua
56
control.lua
@@ -10,6 +10,8 @@ udpAddress = 52555
|
|||||||
isInitialized = false
|
isInitialized = false
|
||||||
sendIndex = 0
|
sendIndex = 0
|
||||||
serverIndex = 0
|
serverIndex = 0
|
||||||
|
scannedGrids = false
|
||||||
|
scannedLabs = false
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
enableMod = false,
|
enableMod = false,
|
||||||
@@ -82,6 +84,7 @@ script.on_configuration_changed(function()
|
|||||||
storage.scannedGrids = storage.scannedGrids or false
|
storage.scannedGrids = storage.scannedGrids or false
|
||||||
storage.scannedLabs = storage.scannedLabs or false
|
storage.scannedLabs = storage.scannedLabs or false
|
||||||
ScanNetworks()
|
ScanNetworks()
|
||||||
|
ScanLabs()
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -131,23 +134,29 @@ end)
|
|||||||
|
|
||||||
|
|
||||||
script.on_event(defines.events.on_player_died, function(event)
|
script.on_event(defines.events.on_player_died, function(event)
|
||||||
if event.cause.is_player() then
|
if event.cause and event.cause.player~=nil then
|
||||||
local killer_index = event.cause.player.index
|
|
||||||
|
local killer = event.cause.player
|
||||||
|
if not killer then return end
|
||||||
|
local killer_index = killer.index
|
||||||
|
|
||||||
local victim_index = event.player_index
|
local victim_index = event.player_index
|
||||||
|
log(("Player ID %d killed player ID %d"):format(killer_index,victim_index))
|
||||||
|
|
||||||
storage.playerKillCount[killer_index] =
|
storage.playerKillCount[killer_index] =
|
||||||
storage.playerKillCount[killer_index] or {}
|
storage.playerKillCount[killer_index] or {}
|
||||||
|
|
||||||
storage.playerKillCount[killer_index][victim_index] =
|
storage.playerKillCount[killer_index][victim_index] =
|
||||||
(storage.playerKillCount[killer_index][victim_index] or 0) + 1
|
(storage.playerKillCount[killer_index][victim_index] or 0) + 1
|
||||||
end
|
end
|
||||||
--local player = game.get_player(event.player_index)
|
|
||||||
storage.playerDeathCount[event.player_index] = (storage.playerDeathCount[event.player_index] or 0) + 1
|
storage.playerDeathCount[event.player_index] = (storage.playerDeathCount[event.player_index] or 0) + 1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function SendGameStats(event)
|
function SendGameStats()
|
||||||
|
if options.enablePlayers then
|
||||||
local returnParts = {}
|
local returnParts = {}
|
||||||
GetMods()
|
GetMods()
|
||||||
returnParts[#returnParts+1] = GetMapSeed()
|
returnParts[#returnParts+1] = GetMapSeed()
|
||||||
@@ -156,6 +165,7 @@ function SendGameStats(event)
|
|||||||
returnParts[#returnParts+1] = GetPlayerDeaths()
|
returnParts[#returnParts+1] = GetPlayerDeaths()
|
||||||
returnParts[#returnParts+1] = GetPlayerKills()
|
returnParts[#returnParts+1] = GetPlayerKills()
|
||||||
helpers.send_udp(udpAddress, table.concat(returnParts, "\n"), serverIndex)
|
helpers.send_udp(udpAddress, table.concat(returnParts, "\n"), serverIndex)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function SendAll(event)
|
function SendAll(event)
|
||||||
@@ -171,23 +181,24 @@ function SendAll(event)
|
|||||||
end
|
end
|
||||||
isInitialized = true
|
isInitialized = true
|
||||||
|
|
||||||
--log("ServerIndex is "..serverIndex.." now")
|
if scannedGrids == false then
|
||||||
|
|
||||||
if storage.scannedGrids == false then
|
|
||||||
ScanNetworks()
|
ScanNetworks()
|
||||||
storage.scannedGrids = true
|
scannedGrids = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if storage.scannedLabs == false then
|
if scannedLabs == false then
|
||||||
ScanLabs()
|
ScanLabs()
|
||||||
|
scannedLabs = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if options.enableMod==true then
|
if options.enableMod==true then
|
||||||
|
|
||||||
if (event.tick % math.floor(tickInterval/8) ~= 0) then return end
|
local interval = math.max(1, math.floor(tickInterval / 9))
|
||||||
|
if event.tick % interval ~= 0 then return end
|
||||||
|
|
||||||
sendIndex = (sendIndex % 8) + 1
|
|
||||||
|
sendIndex = (sendIndex % 9) + 1
|
||||||
if sendIndex == 1 then SendProductionStats() end
|
if sendIndex == 1 then SendProductionStats() end
|
||||||
if sendIndex == 2 then SendPollutionStats() end
|
if sendIndex == 2 then SendPollutionStats() end
|
||||||
if sendIndex == 3 then SendKillStats() end
|
if sendIndex == 3 then SendKillStats() end
|
||||||
@@ -196,12 +207,8 @@ function SendAll(event)
|
|||||||
if sendIndex == 6 then SendResearchStats() end
|
if sendIndex == 6 then SendResearchStats() end
|
||||||
if sendIndex == 7 then SendLogisticStats() end
|
if sendIndex == 7 then SendLogisticStats() end
|
||||||
if sendIndex == 8 then SendPowerStats() end
|
if sendIndex == 8 then SendPowerStats() end
|
||||||
|
if sendIndex == 9 then SendGameStats()end
|
||||||
if(event.tick % tickInterval*2 == 0) then
|
end
|
||||||
if options.enablePlayers then
|
|
||||||
SendGameStats(event) end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function UpdateStorage(event)
|
function UpdateStorage(event)
|
||||||
@@ -222,8 +229,11 @@ function RemoveStorage(event)
|
|||||||
if event.entity.type == "electric-pole" then
|
if event.entity.type == "electric-pole" then
|
||||||
RemovePowerPole(event)
|
RemovePowerPole(event)
|
||||||
end
|
end
|
||||||
|
--log(event.entity.name)
|
||||||
if event.entity.name == "crash-site-spaceship" then
|
if event.entity.name == "crash-site-spaceship" then
|
||||||
|
--log(event.name)
|
||||||
if event.name == defines.events.on_player_mined_entity then
|
if event.name == defines.events.on_player_mined_entity then
|
||||||
|
--log("in ban call")
|
||||||
if settings.global["factorio-metrics-exporter-enable_denkmalschutz"].value == true then
|
if settings.global["factorio-metrics-exporter-enable_denkmalschutz"].value == true then
|
||||||
game.ban_player(event.player_index,"You violated the rules of DENKMALSCHUTZ!!!")
|
game.ban_player(event.player_index,"You violated the rules of DENKMALSCHUTZ!!!")
|
||||||
end
|
end
|
||||||
@@ -234,11 +244,11 @@ end
|
|||||||
script.on_event(defines.events.on_tick, SendAll)
|
script.on_event(defines.events.on_tick, SendAll)
|
||||||
|
|
||||||
--Script hooks for power and lab stats
|
--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_built_entity,UpdateStorage,{{filter = "type", type = "electric-pole"},{filter ="type", type="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_player_mined_entity, RemoveStorage,{{filter = "type", type = "electric-pole"},{filter ="type", type="lab"},{filter = "type", type="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_built_entity,UpdateStorage,{{filter = "type", type = "electric-pole"},{filter ="type", type="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_robot_mined_entity,RemoveStorage,{{filter = "type", type = "electric-pole"},{filter ="type", type="lab"},{filter = "type", type="container"}})
|
||||||
script.on_event(defines.events.on_entity_died,RemoveStorage,{{filter = "type", type = "electric-pole" or "lab" or "container"}})
|
script.on_event(defines.events.on_entity_died,RemoveStorage,{{filter = "type", type = "electric-pole"},{filter ="type", type="lab"},{filter = "type", type="container"}})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ function GetPlayerKills()
|
|||||||
killParts[#killParts+1] = "---player-kills---\n"
|
killParts[#killParts+1] = "---player-kills---\n"
|
||||||
for killerIndex, victims in pairs(storage.playerKillCount) do
|
for killerIndex, victims in pairs(storage.playerKillCount) do
|
||||||
for victimIndex, kills in pairs(victims) do
|
for victimIndex, kills in pairs(victims) do
|
||||||
local killerName = game.players(killerIndex)
|
local killerName = game.players[killerIndex].name
|
||||||
local victimName = game.players(victimIndex)
|
local victimName = game.players[victimIndex].name
|
||||||
killParts[#killParts+1] = ("%s:%s:%s:%s:%d"):format(killerIndex,killerName,victimIndex,victimName,kills)
|
killParts[#killParts+1] = ("%s:%s:%s:%s:%d"):format(killerName,killerIndex,victimName,victimIndex,kills)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return table.concat(killParts,"\n")
|
return table.concat(killParts,"\n")
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ function ScanLabs()
|
|||||||
storage.labs[lab.unit_number] = lab
|
storage.labs[lab.unit_number] = lab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
storage.scannedLabs = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user