mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-21 17:04:00 +00:00
Every call site of expcore.roles now uses exp_roles, and the legacy module, its config, and the glue which refreshed guis on role events are deleted. Where a file only renamed the require and the permission strings the change is mechanical; the rest: - Jail is now "give the Jail role" and unjail "take it away". The role has a higher priority than every other so holding it suppresses them, which is what stashing and restoring the roles was for. - The command role authority derives exp_scenario.command.<name> from the command name, and the role parsers use player_outranks rather than comparing indexes with their own root check. - The admin and spectator triggers, and the gui refresh on role changes, live in exp_scenario/control/roles.lua; the system commands trigger stays with the command authority. - The player list warn button is keyed on create_warning, the permission the command behind it already required, and report on create_report. Both were keyed on names no role held, so only root ever saw them. - The warps and tasks configs say exp_roles where they said expcore.roles. - The role tables the readme and player list read are replaced by get_player_names and get_roles. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
115 lines
4.5 KiB
Lua
115 lines
4.5 KiB
Lua
--[[-- Control Module - Jail
|
|
- Adds a way to jail players.
|
|
@control Jail
|
|
@alias Jail
|
|
|
|
@usage
|
|
-- import the module from the control modules
|
|
local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail
|
|
|
|
-- This will give 'MrBiter' the jail role, which suppresses all of their other roles
|
|
-- the player name and reason are only so they can be included in the event for user feedback
|
|
Jail.jail_player('MrBiter', 'Cooldude2606', 'Likes biters too much')
|
|
|
|
-- This will remove the jail role from 'MrBiter', restoring their other roles
|
|
-- again as above the player name is only used in the event for user feedback
|
|
Jail.unjail_player('MrBiter', 'Cooldude2606')
|
|
]]
|
|
|
|
local Roles = require("modules/exp_roles")
|
|
|
|
local valid_player = function(p) return type(p) == "userdata" and p or game.get_player(p) end
|
|
|
|
--- The role which is given to jailed players, it has a higher priority than every other role
|
|
local jail_role = "Jail"
|
|
|
|
local Jail = {
|
|
events = {
|
|
--- When a player is assigned to jail
|
|
-- @event on_player_jailed
|
|
-- @tparam number player_index the index of the player who was jailed
|
|
-- @tparam string by_player_name the name of the player who jailed the other player
|
|
-- @tparam string reason the reason that the player was jailed
|
|
on_player_jailed = script.generate_event_name(),
|
|
--- When a player is unassigned from jail
|
|
-- @event on_player_unjailed
|
|
-- @tparam number player_index the index of the player who was unjailed
|
|
-- @tparam string by_player_name the name of the player who unjailed the other player
|
|
on_player_unjailed = script.generate_event_name(),
|
|
},
|
|
}
|
|
|
|
--- Used to emit the jail related events
|
|
-- @tparam number event the name of the event that will be emited
|
|
-- @tparam LuaPlayer player the player who is being acted on
|
|
-- @tparam string by_player_name the player who is doing the action
|
|
-- @tparam string reason the reason for the action (jail)
|
|
local function event_emit(event, player, by_player_name, reason)
|
|
script.raise_event(event, {
|
|
name = event,
|
|
tick = game.tick,
|
|
player_index = player.index,
|
|
by_player_name = by_player_name,
|
|
reason = reason,
|
|
})
|
|
end
|
|
|
|
--- Jail.
|
|
-- Functions related to jail
|
|
-- @section jail-functions
|
|
|
|
--- Checks if the player is currently in jail
|
|
-- @tparam LuaPlayer player the player to check if they are in jail
|
|
-- @treturn boolean whether the player is currently in jail
|
|
function Jail.is_jailed(player)
|
|
return Roles.player_has_role(valid_player(player), jail_role)
|
|
end
|
|
|
|
--- Moves a player to jail, which suppresses all of their other roles
|
|
-- @tparam LuaPlayer player the player who will be jailed
|
|
-- @tparam string by_player_name the name of the player who is doing the jailing
|
|
-- @tparam[opt='Non given.'] string reason the reason that the player is being jailed
|
|
-- @treturn boolean wheather the user was jailed successfully
|
|
function Jail.jail_player(player, by_player_name, reason)
|
|
player = valid_player(player)
|
|
if not player then return end
|
|
if not by_player_name then return end
|
|
|
|
reason = reason or "Non given."
|
|
|
|
if Roles.player_has_role(player, jail_role) then return end
|
|
|
|
player.walking_state = { walking = false, direction = player.walking_state.direction }
|
|
player.riding_state = { acceleration = defines.riding.acceleration.nothing, direction = player.riding_state.direction }
|
|
player.mining_state = { mining = false }
|
|
player.shooting_state = { state = defines.shooting.not_shooting, position = player.shooting_state.position }
|
|
player.picking_state = false
|
|
player.repair_state = { repairing = false, position = player.repair_state.position }
|
|
|
|
Roles.assign_player(player, jail_role, by_player_name, true)
|
|
|
|
event_emit(Jail.events.on_player_jailed, player, by_player_name, reason)
|
|
|
|
return true
|
|
end
|
|
|
|
--- Moves a player out of jail, which restores all of their other roles
|
|
-- @tparam LuaPlayer player the player that will be unjailed
|
|
-- @tparam string by_player_name the name of the player that is doing the unjail
|
|
-- @treturn boolean whether the player was unjailed successfully
|
|
function Jail.unjail_player(player, by_player_name)
|
|
player = valid_player(player)
|
|
if not player then return end
|
|
if not by_player_name then return end
|
|
|
|
if not Roles.player_has_role(player, jail_role) then return end
|
|
|
|
Roles.unassign_player(player, jail_role, by_player_name, true)
|
|
|
|
event_emit(Jail.events.on_player_unjailed, player, by_player_name)
|
|
|
|
return true
|
|
end
|
|
|
|
return Jail
|