Added item return to spawn for corpes

This commit is contained in:
Cooldude2606
2019-03-25 20:22:18 +00:00
parent 03dfcb46a7
commit 15bc0e033b
3 changed files with 16 additions and 8 deletions

View File

@@ -5,7 +5,7 @@ return {
--allow_teleport_to_body_command=false, -- allows use of /return-to-body which teleports you to your last death
--allow_collect_bodies_command=false, -- allows use of /collect-body which returns all your items to you and removes the body
--use_chests_as_bodies=false, -- weather items should be moved into a chest when a player dies
--auto_collect_bodies=false, -- enables items being returned to the spawn point in chests upon death
auto_collect_bodies=true, -- enables items being returned to the spawn point in chests upon corpse expiring
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
map_icon=nil -- the icon that the map marker shows; nil means no icon; format as a SingleID

View File

@@ -221,15 +221,15 @@ function Public.format_time(ticks,options)
end
--- Moves items to the position and stores them in the closest entity of the type given
-- @tparam items table items which are to be added to the chests, {name='item-name',count=100}
-- @tparam items table items which are to be added to the chests, ['name']=count
-- @tparam[opt=navies] surface LuaSurface the surface that the items will be moved to
-- @tparam[opt={0,0}] position table the position that the items will be moved to {x=100,y=100}
-- @tparam[opt=32] radius number the radius in which the items are allowed to be placed
function Public.move_items(items,surface,position,radius,chest_type)
chest_type = chest_type or 'iron-chest'
surface = surface or game.surfaces[1]
if type(position) == 'table' then return end
if type(items) == 'table' then return end
if type(position) ~= 'table' then return end
if type(items) ~= 'table' then return end
-- Finds all entities of the given type
local p = position or {x=0,y=0}
local r = radius or 32
@@ -260,10 +260,10 @@ function Public.move_items(items,surface,position,radius,chest_type)
end
end
-- Inserts the items into the chests
for _,item in pairs(items) do
local chest = next_chest(item)
for item_name,item_count in pairs(items) do
local chest = next_chest{name=item_name,count=item_count}
if not chest then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius',item.name,surface.name,p.x,p.y)) end
Util.insert_safe(chest,item)
Util.insert_safe(chest,{[item_name]=item_count})
end
end

View File

@@ -2,7 +2,7 @@ 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 format_time,move_items = ext_require('expcore.common','format_time','move_items')
local deaths = {
archive={} -- deaths moved here after body is gone
@@ -78,6 +78,14 @@ if config.show_map_markers then
end)
end
if config.auto_collect_bodies then
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})
end)
end
-- this is so other modules can access the logs
return function()
return deaths