mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Added Death logger
This commit is contained in:
@@ -8,5 +8,5 @@ return {
|
|||||||
auto_collect_bodies=false, -- enables items being returned to the spawn point in chests upon death
|
auto_collect_bodies=false, -- enables items being returned to the spawn point in chests upon death
|
||||||
show_map_markers=true, -- shows markers on the map where bodies are
|
show_map_markers=true, -- shows markers on the map where bodies are
|
||||||
include_time_of_death=true, -- weather to include the time of death on the map marker
|
include_time_of_death=true, -- weather to include the time of death on the map marker
|
||||||
map_icon='' -- the icon that the map marker shows '' means no icon
|
map_icon=nil -- the icon that the map marker shows; nil means no icon; format as a SingleID
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ return {
|
|||||||
-- QoL Addons
|
-- QoL Addons
|
||||||
'modules.addons.chat-popups',
|
'modules.addons.chat-popups',
|
||||||
'modules.addons.damage-popups',
|
'modules.addons.damage-popups',
|
||||||
|
'modules.addons.death-markers',
|
||||||
-- Config Files
|
-- Config Files
|
||||||
'config.command_auth_admin', -- commands tagged with admin_only are blocked for non admins
|
'config.command_auth_admin', -- commands tagged with admin_only are blocked for non admins
|
||||||
'config.command_auth_runtime_disable', -- allows commands to be enabled and disabled during runtime
|
'config.command_auth_runtime_disable', -- allows commands to be enabled and disabled during runtime
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ end
|
|||||||
--- Formats tick into a clean format, denominations from highest to lowest
|
--- Formats tick into a clean format, denominations from highest to lowest
|
||||||
-- long will use words rather than letters
|
-- long will use words rather than letters
|
||||||
-- time will use : separates
|
-- time will use : separates
|
||||||
|
-- string will return a string not a locale string
|
||||||
-- when a denomination is false it will overflow into the next one
|
-- when a denomination is false it will overflow into the next one
|
||||||
-- @tparam ticks number the number of ticks that represents a time
|
-- @tparam ticks number the number of ticks that represents a time
|
||||||
-- @tparam options table a table of options to use for the format
|
-- @tparam options table a table of options to use for the format
|
||||||
@@ -150,7 +151,8 @@ function Public.format_time(ticks,options)
|
|||||||
minutes=true,
|
minutes=true,
|
||||||
seconds=false,
|
seconds=false,
|
||||||
long=false,
|
long=false,
|
||||||
time=false
|
time=false,
|
||||||
|
string=false
|
||||||
}
|
}
|
||||||
-- Basic numbers that are used in calculations
|
-- Basic numbers that are used in calculations
|
||||||
local max_days, max_hours, max_minutes, max_seconds = ticks/5184000, ticks/216000, ticks/3600, ticks/60
|
local max_days, max_hours, max_minutes, max_seconds = ticks/5184000, ticks/216000, ticks/3600, ticks/60
|
||||||
@@ -174,18 +176,28 @@ function Public.format_time(ticks,options)
|
|||||||
suffix = ''
|
suffix = ''
|
||||||
suffix_2 = ''
|
suffix_2 = ''
|
||||||
end
|
end
|
||||||
local div = 'time-format.simple-format-tagged'
|
local div = options.string and ' ' or 'time-format.simple-format-tagged'
|
||||||
if options.time then
|
if options.time then
|
||||||
div = 'time-format.simple-format-div'
|
div = options.string and ':' or 'time-format.simple-format-div'
|
||||||
suffix = false
|
suffix = false
|
||||||
end
|
end
|
||||||
-- Adds formatting
|
-- Adds formatting
|
||||||
if suffix ~= false then
|
if suffix ~= false then
|
||||||
rtn_days = {suffix..'days'..suffix_2,rtn_days}
|
if options.string then
|
||||||
rtn_hours = {suffix..'hours'..suffix_2,rtn_hours}
|
-- format it as a string
|
||||||
rtn_minutes = {suffix..'minutes'..suffix_2,rtn_minutes}
|
local long = suffix == ''
|
||||||
rtn_seconds = {suffix..'seconds'..suffix_2,rtn_seconds}
|
rtn_days = long and rtn_days..' days' or rtn_days..'d'
|
||||||
|
rtn_hours = long and rtn_hours..' hours' or rtn_hours..'h'
|
||||||
|
rtn_minutes = long and rtn_minutes..' minutes' or rtn_minutes..'m'
|
||||||
|
rtn_seconds = long and rtn_seconds..' seconds' or rtn_seconds..'s'
|
||||||
|
else
|
||||||
|
rtn_days = {suffix..'days'..suffix_2,rtn_days}
|
||||||
|
rtn_hours = {suffix..'hours'..suffix_2,rtn_hours}
|
||||||
|
rtn_minutes = {suffix..'minutes'..suffix_2,rtn_minutes}
|
||||||
|
rtn_seconds = {suffix..'seconds'..suffix_2,rtn_seconds}
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
-- weather string or not it has same format
|
||||||
rtn_days = string.format('%02d',rtn_days)
|
rtn_days = string.format('%02d',rtn_days)
|
||||||
rtn_hours = string.format('%02d',rtn_hours)
|
rtn_hours = string.format('%02d',rtn_hours)
|
||||||
rtn_minutes = string.format('%02d',rtn_minutes)
|
rtn_minutes = string.format('%02d',rtn_minutes)
|
||||||
@@ -193,18 +205,17 @@ function Public.format_time(ticks,options)
|
|||||||
end
|
end
|
||||||
-- The final return is construed
|
-- The final return is construed
|
||||||
local rtn
|
local rtn
|
||||||
if options.days then
|
local append = function(dom,value)
|
||||||
rtn = rtn_days
|
if dom and options.string then
|
||||||
end
|
rtn = rtn and rtn..div..value or value
|
||||||
if options.hours then
|
elseif dom then
|
||||||
rtn = rtn and {div,rtn,rtn_hours} or rtn_hours
|
rtn = rtn and {div,rtn,value} or value
|
||||||
end
|
end
|
||||||
if options.minutes then
|
|
||||||
rtn = rtn and {div,rtn,rtn_minutes} or rtn_minutes
|
|
||||||
end
|
|
||||||
if options.seconds then
|
|
||||||
rtn = rtn and {div,rtn,rtn_seconds} or rtn_seconds
|
|
||||||
end
|
end
|
||||||
|
append(options.day,rtn_days)
|
||||||
|
append(options.hours,rtn_hours)
|
||||||
|
append(options.minutes,rtn_minutes)
|
||||||
|
append(options.seconds,rtn_seconds)
|
||||||
return rtn
|
return rtn
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
84
modules/addons/death-logger.lua
Normal file
84
modules/addons/death-logger.lua
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
local Event = require 'utils.event'
|
||||||
|
local Game = require 'utils.game'
|
||||||
|
local Global = require 'utils.global'
|
||||||
|
local config = require 'config.death_logger'
|
||||||
|
local format_time = ext_require('expcore.common','format_time')
|
||||||
|
|
||||||
|
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}
|
||||||
|
}
|
||||||
|
Global.register(deaths,function(tbl)
|
||||||
|
deaths = tbl
|
||||||
|
end)
|
||||||
|
|
||||||
|
--- Creates a new death marker and saves it to the given death
|
||||||
|
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})
|
||||||
|
message = message..' at '..time
|
||||||
|
end
|
||||||
|
death.tag = player.force.add_chart_tag(player.surface,{
|
||||||
|
position=death.position,
|
||||||
|
icon=config.map_icon,
|
||||||
|
text=message
|
||||||
|
})
|
||||||
|
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
|
||||||
|
local map_tag = death.tag
|
||||||
|
local corpse = death.corpse
|
||||||
|
-- Check the corpse is valid
|
||||||
|
if corpse and corpse.valid then
|
||||||
|
-- Corpse is valid check the map tag
|
||||||
|
if not map_tag or not map_tag.valid then
|
||||||
|
-- Map tag is not valid make a new one
|
||||||
|
create_map_tag(death)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Corpse is not valid so remove the map tag
|
||||||
|
if map_tag and map_tag.valid then
|
||||||
|
map_tag.destroy()
|
||||||
|
end
|
||||||
|
-- Move the death to the archive
|
||||||
|
death.corpse = nil
|
||||||
|
death.tag = nil
|
||||||
|
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)
|
||||||
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
local corpse = player.surface.find_entity('character-corpse',player.position)
|
||||||
|
local death = {
|
||||||
|
player_name = player.name,
|
||||||
|
time_of_death = event.tick,
|
||||||
|
position = player.position,
|
||||||
|
corpse = corpse
|
||||||
|
}
|
||||||
|
if config.show_map_markers then
|
||||||
|
create_map_tag(death)
|
||||||
|
end
|
||||||
|
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)
|
||||||
|
check_map_tags()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- this is so other modules can access the logs
|
||||||
|
return function()
|
||||||
|
return deaths
|
||||||
|
end
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
local Event = require 'utils.event'
|
|
||||||
local Game = require 'utils.game'
|
|
||||||
local Global = require 'utils.global'
|
|
||||||
local Commands = require 'expcore.commands'
|
|
||||||
local config = require 'config.death_markers'
|
|
||||||
local opt_require, format_time = ext_require('expcore.common','opt_require','format_time_simple')
|
|
||||||
opt_require 'config.command_auth_runtime_disable' -- if the file is present then we can disable the commands rather than not load them
|
|
||||||
|
|
||||||
local bodies = {
|
|
||||||
--{player_name='Cooldude2606',time_of_death='15H 15M',body=LuaEntity,tag=LuaCustomChartTag}
|
|
||||||
}
|
|
||||||
Global.register(bodies,function(tbl)
|
|
||||||
bodies = tbl
|
|
||||||
end)
|
|
||||||
|
|
||||||
--- Checks that all map tags are present and valid
|
|
||||||
-- adds missing ones, deletes expired ones
|
|
||||||
local function check_map_tags()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Teleports the owner of a body to the body
|
|
||||||
local function teleport_player(body)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Teleports the items in a body to a certain position putting it in chests
|
|
||||||
-- if there are no chests close by them some are created
|
|
||||||
local function teleport_items(body,position)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
Event.add(defines.events.on_player_died,function(event)
|
|
||||||
|
|
||||||
end)
|
|
||||||
|
|
||||||
local check_period = 60*60*5 -- five minutes
|
|
||||||
Event.on_nth_tick(check_period,function(event)
|
|
||||||
|
|
||||||
end)
|
|
||||||
Reference in New Issue
Block a user