Files
factorio-scenario-ExpCluster/exp_scenario/module/control/report_jail.lua
T
bbassie 2e53e4668d Move jail into exp_scenario
With the role system finished the jail module has nothing legacy left in
it, so it moves to exp_scenario/module/control/jail.lua and the copy in
exp_legacy is removed. The module takes LuaPlayer only, requires a reason,
returns false rather than nil when there is nothing to do, and exposes its
event ids as Jail.on_player_jailed and Jail.on_player_unjailed in the same
shape as exp_util's selection events.
2026-09-05 19:18:04 +00:00

39 lines
1.5 KiB
Lua

--[[-- Control - Report Jail
When a player is reported, the player is automatically jailed if the combined playtime of the reporters exceeds the reported player
]]
local ExpUtil = require("modules/exp_util")
local Jail = require("modules/exp_scenario/control/jail")
local Reports = require("modules.exp_legacy.modules.control.reports")
local max = math.max
local format_player_name = ExpUtil.format_player_name_locale
--- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters
--- @param player LuaPlayer
--- @param by_player_name string
--- @param reason string
--- @return number
local function reporter_playtime(player, by_player_name, reason)
local by_player = game.get_player(by_player_name)
return by_player and by_player.online_time or 0
end
--- Check if the player has too many reports against them (based on playtime)
local function on_player_reported(event)
local player = assert(game.get_player(event.player_index))
local total_playtime = Reports.count_reports(player, reporter_playtime)
-- Total time greater than the players own time, or 30 minutes, which ever is greater
if Reports.count_reports(player) > 1 and total_playtime > max(player.online_time * 2, 108000) then
Jail.jail_player(player, "<reports>", "Reported by too many players, please wait for a moderator.")
game.print{ "exp_report-jail.chat-jailed", format_player_name(player) }
end
end
return {
events = {
[Reports.events.on_player_reported] = on_player_reported,
}
}