Fixed Existing Lua Check Errors

This commit is contained in:
Cooldude2606
2020-05-26 18:21:10 +01:00
parent 2aaeb06be3
commit 32507492b8
76 changed files with 1622 additions and 1617 deletions

View File

@@ -5,13 +5,13 @@ local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Global = require 'utils.global' --- @dep utils.global
local config = require 'config.death_logger' --- @dep config.death_logger
local format_time,move_items = _C.format_time, _C.move_items --- @dep expcore.common
local format_time, move_items = _C.format_time, _C.move_items --- @dep expcore.common
local deaths = {
archive={} -- deaths moved here after body is gone
--{player_name='Cooldude2606',time_of_death='15H 15M',position={x=0,y=0},corpse=LuaEntity,tag=LuaCustomChartTag}
--{player_name='Cooldude2606', time_of_death='15H 15M', position={x=0, y=0}, corpse=LuaEntity, tag=LuaCustomChartTag}
}
Global.register(deaths,function(tbl)
Global.register(deaths, function(tbl)
deaths = tbl
end)
@@ -20,10 +20,10 @@ local function create_map_tag(death)
local player = Game.get_player_from_any(death.player_name)
local message = player.name..' died'
if config.include_time_of_death then
local time = format_time(death.time_of_death,{hours=true,minutes=true,string=true})
local time = format_time(death.time_of_death, {hours=true, minutes=true, string=true})
message = message..' at '..time
end
death.tag = player.force.add_chart_tag(player.surface,{
death.tag = player.force.add_chart_tag(player.surface, {
position=death.position,
icon=config.map_icon,
text=message
@@ -33,7 +33,7 @@ end
--- Checks that all map tags are present and valid
-- adds missing ones, deletes expired ones
local function check_map_tags()
for index,death in ipairs(deaths) do
for index, death in ipairs(deaths) do
local map_tag = death.tag
local corpse = death.corpse
-- Check the corpse is valid
@@ -51,19 +51,19 @@ local function check_map_tags()
-- Move the death to the archive
death.corpse = nil
death.tag = nil
table.insert(deaths.archive,death)
table.remove(deaths,index)
table.insert(deaths.archive, death)
table.remove(deaths, index)
end
end
end
-- when a player dies a new death is added to the records and a map marker is made
Event.add(defines.events.on_player_died,function(event)
Event.add(defines.events.on_player_died, function(event)
local player = Game.get_player_by_index(event.player_index)
local corpse = player.surface.find_entity('character-corpse',player.position)
local corpse = player.surface.find_entity('character-corpse', player.position)
if config.use_chests_as_bodies then
local items = corpse.get_inventory(defines.inventory.character_corpse).get_contents()
local chest = move_items(items,corpse.surface,corpse.position)
local chest = move_items(items, corpse.surface, corpse.position)
chest.destructible = false
corpse.destroy()
corpse = chest
@@ -77,22 +77,22 @@ Event.add(defines.events.on_player_died,function(event)
if config.show_map_markers then
create_map_tag(death)
end
table.insert(deaths,death)
table.insert(deaths, death)
end)
-- every 5 min all bodies are checked for valid map tags
if config.show_map_markers then
local check_period = 60*60*5 -- five minutes
Event.on_nth_tick(check_period,function(event)
Event.on_nth_tick(check_period, function()
check_map_tags()
end)
end
if config.auto_collect_bodies then
Event.add(defines.events.on_character_corpse_expired,function(event)
Event.add(defines.events.on_character_corpse_expired, function(event)
local corpse = event.corpse
local items = corpse.get_inventory(defines.inventory.character_corpse).get_contents()
move_items(items,corpse.surface,{x=0,y=0})
move_items(items, corpse.surface, {x=0, y=0})
end)
end