|
| 1 | +--[[-- Control - Report Jail |
| 2 | +When a player is reported, the player is automatically jailed if the combined playtime of the reporters exceeds the reported player |
| 3 | +]] |
| 4 | + |
| 5 | +local ExpUtil = require("modules/exp_util") |
| 6 | +local Jail = require("modules.exp_legacy.modules.control.jail") |
| 7 | +local Reports = require("modules.exp_legacy.modules.control.reports") |
| 8 | + |
| 9 | +local max = math.max |
| 10 | +local format_player_name = ExpUtil.format_player_name_locale |
| 11 | + |
| 12 | +--- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters |
| 13 | +--- @param player LuaPlayer |
| 14 | +--- @param by_player_name string |
| 15 | +--- @param reason string |
| 16 | +--- @return number |
| 17 | +local function reporter_playtime(player, by_player_name, reason) |
| 18 | + local by_player = game.get_player(by_player_name) |
| 19 | + return by_player and by_player.online_time or 0 |
| 20 | +end |
| 21 | + |
| 22 | +--- Check if the player has too many reports against them (based on playtime) |
| 23 | +local function on_player_reported(event) |
| 24 | + local player = assert(game.get_player(event.player_index)) |
| 25 | + local total_playtime = Reports.count_reports(player, reporter_playtime) |
| 26 | + |
| 27 | + -- Total time greater than the players own time, or 30 minutes, which ever is greater |
| 28 | + if Reports.count_reports(player) > 1 and total_playtime > max(player.online_time * 2, 108000) then |
| 29 | + Jail.jail_player(player, "<reports>", "Reported by too many players, please wait for a moderator.") |
| 30 | + game.print{ "exp_report-jail.chat-jailed", format_player_name(player) } |
| 31 | + end |
| 32 | +end |
| 33 | + |
| 34 | +return { |
| 35 | + events = { |
| 36 | + [Reports.events.on_player_reported] = on_player_reported, |
| 37 | + } |
| 38 | +} |
0 commit comments