mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-05-13 21:56:29 +02:00
planet_prison: add an afk timer
Adds an afk timer, 90 minutes. After that time you die.
This commit is contained in:
parent
1f12c2602f
commit
6eb1486574
@ -6,6 +6,7 @@ local _common = require("planet_prison.mod.common")
|
||||
local _layers = require("planet_prison.mod.layers")
|
||||
local _ai = require("planet_prison.mod.ai")
|
||||
local _bp = require("planet_prison.mod.bp")
|
||||
local _afk = require("planet_prison.mod.afk")
|
||||
global.this._config = require("planet_prison.config")
|
||||
|
||||
global.this.maps = {
|
||||
@ -531,6 +532,10 @@ local function unlink_old_blueprints(name)
|
||||
end
|
||||
end
|
||||
|
||||
local function kill_player(p)
|
||||
p.character.die()
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
local s = global.this.surface
|
||||
if not s then
|
||||
@ -549,6 +554,10 @@ local function on_tick()
|
||||
|
||||
_layers.do_job(surf)
|
||||
cause_event(s)
|
||||
|
||||
if (game.tick + 1) % 100 == 0 then
|
||||
_afk.on_inactive_players(90, kill_player)
|
||||
end
|
||||
end
|
||||
|
||||
local function make_ore_patch(e)
|
||||
|
19
maps/planet_prison/mod/afk.lua
Normal file
19
maps/planet_prison/mod/afk.lua
Normal file
@ -0,0 +1,19 @@
|
||||
local public = {}
|
||||
local _evt = require("utils.event")
|
||||
|
||||
--[[
|
||||
on_inactive_players - Performs operation on inactive players from the game
|
||||
if they exceed time.
|
||||
@param time - Maximum time a player can be inactive.
|
||||
@param func - Callback that will be called.
|
||||
--]]
|
||||
public.on_inactive_players = function(time, func)
|
||||
for _, p in pairs(game.connected_players) do
|
||||
local afk = p.afk_time / 60 / 60
|
||||
if afk >= time then
|
||||
func(p)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return public
|
Loading…
x
Reference in New Issue
Block a user