Added use chests as bodies

This commit is contained in:
Cooldude2606
2019-03-25 20:32:17 +00:00
parent 15bc0e033b
commit ea1de6a2b4
3 changed files with 12 additions and 2 deletions

View File

@@ -4,7 +4,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
use_chests_as_bodies=false, -- weather items should be moved into a chest when a player dies
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

View File

@@ -239,7 +239,7 @@ function Public.move_items(items,surface,position,radius,chest_type)
-- Makes a new emtpy chest when it is needed
local function make_new_chest()
local pos = surface.find_non_colliding_position(chest_type,position,32,1)
local chest = surface.surface.create_entity{name=chest_type,position=pos}
local chest = surface.create_entity{name=chest_type,position=pos,force='neutral'}
table.insert(entities,chest)
count = count + 1
return chest
@@ -260,11 +260,14 @@ function Public.move_items(items,surface,position,radius,chest_type)
end
end
-- Inserts the items into the chests
local last_chest
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_name]=item_count})
last_chest = chest
end
return last_chest
end
return Public

View File

@@ -58,6 +58,13 @@ end
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)
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)
chest.destructible = false
corpse.destroy()
corpse = chest
end
local death = {
player_name = player.name,
time_of_death = event.tick,