mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-12 02:28:02 +02:00
Automatically tag corpse after player died
This commit is contained in:
parent
85b7a40a2a
commit
9a0dfd78d1
@ -21,6 +21,7 @@ require "wells"
|
||||
require "custom_commands"
|
||||
require "tasklist"
|
||||
require "autodeconstruct"
|
||||
require "corpse_util"
|
||||
|
||||
local function player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
32
corpse_util.lua
Normal file
32
corpse_util.lua
Normal file
@ -0,0 +1,32 @@
|
||||
local ttl = 15*60*60
|
||||
local function on_init()
|
||||
global.corpse_util = {}
|
||||
global.corpse_util.tags = {}
|
||||
end
|
||||
|
||||
local function mark_corpse(event)
|
||||
local player = game.players[event.player_index]
|
||||
local name = player.name .. "'s corpse"
|
||||
local position = player.position
|
||||
local tag = player.force.add_chart_tag(player.surface, {icon={type="item", name="power-armor-mk2"}, position=position, text=name})
|
||||
if tag ~= nil then
|
||||
table.insert(global.corpse_util.tags, {tag, game.tick + ttl})
|
||||
end
|
||||
end
|
||||
|
||||
local function remove_corpse_marks()
|
||||
local tags = global.corpse_util.tags
|
||||
local size = #tags
|
||||
for i = size, 1, -1 do
|
||||
if game.tick >= tags[i][2] then
|
||||
if tags[i][1].valid then
|
||||
tags[i][1].destroy()
|
||||
end
|
||||
table.remove(tags, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.register(-1, on_init)
|
||||
Event.register(defines.events.on_player_died, mark_corpse)
|
||||
Event.register(defines.events.on_tick, remove_corpse_marks)
|
Loading…
Reference in New Issue
Block a user