1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-13 13:49:33 +02:00

75 lines
2.5 KiB
Lua
Raw Normal View History

2022-10-22 22:13:35 +02:00
local Event = require 'utils.event'
2022-10-19 22:51:01 -04:00
local Scheduler = require 'utils.scheduler'
2022-10-17 22:11:38 -04:00
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
2022-10-21 21:49:17 +02:00
local yellow = {r = 200, g = 200, b = 0}
2022-10-19 22:51:01 -04:00
-- Must be at least 1 minute
2022-10-21 21:49:17 +02:00
local minutes_to_die = 5
2022-10-19 22:51:59 -04:00
local one_minute = 60 * 60
2022-10-19 22:51:01 -04:00
local function on_player_died(event)
local this = ScenarioTable.get_table()
local player = game.players[event.player_index]
this.suicides[player.index] = nil
end
Event.add(defines.events.on_player_died, on_player_died)
2022-10-21 21:49:17 +02:00
local suicide_handler =
Scheduler.set(
function(data)
for i = 1, #data do
local this = ScenarioTable.get_table()
local player_index = data[i].player_index
local player = game.get_player(player_index)
if not player or not player.valid or not player.character then
return
end
2022-10-19 22:51:01 -04:00
2022-10-21 21:49:17 +02:00
if not this.suicides[player.index] then
-- the suicide was cancelled (the character died)
return
end
2022-10-19 22:51:01 -04:00
2022-10-21 21:49:17 +02:00
local minutes_remaining = this.suicides[player.index].minutes_remaining
2022-10-19 22:51:01 -04:00
2022-10-21 21:49:17 +02:00
if minutes_remaining <= 0 then
player.character.die()
this.suicides[player.index] = nil
2022-10-19 22:51:01 -04:00
else
2022-10-21 21:49:17 +02:00
if minutes_remaining == 1 then
player.print(minutes_remaining .. ' minute remaining until death.', yellow)
else
player.print(minutes_remaining .. ' minutes remaining until death.', yellow)
end
this.suicides[player.index].minutes_remaining = this.suicides[player.index].minutes_remaining - 1
Scheduler.timer(game.tick + one_minute, data[i].handler, {player_index = player.index, handler = data[i].handler})
2022-10-19 22:51:01 -04:00
end
end
end
2022-10-21 21:49:17 +02:00
)
2022-10-17 22:11:38 -04:00
commands.add_command(
2022-10-21 21:49:17 +02:00
'suicide',
'Kills the player',
function()
local this = ScenarioTable.get_table()
local player = game.player
2022-10-17 22:23:26 -04:00
2022-10-21 21:49:17 +02:00
if not player or not player.valid then
return
end
2022-10-17 22:23:26 -04:00
2022-10-21 21:49:17 +02:00
if this.suicides[player.index] then
player.print('You are already dying!', yellow)
return
2022-10-17 22:11:38 -04:00
end
2022-10-21 21:49:17 +02:00
this.suicides[player.index] = {minutes_remaining = minutes_to_die - 1}
Scheduler.timer(game.tick + one_minute, suicide_handler, {player_index = player.index, handler = suicide_handler})
player.print('You ate a poison pill. You will die in ' .. minutes_to_die .. ' minutes.', yellow)
end
2022-10-17 22:11:38 -04:00
)