diff --git a/exp_commands/module/commands/authorities.lua b/exp_commands/module/commands/authorities.lua index b254fc75..57b1ce28 100644 --- a/exp_commands/module/commands/authorities.lua +++ b/exp_commands/module/commands/authorities.lua @@ -38,27 +38,37 @@ function Commands.lock_system_commands(player_name) end --- Get a list of all players who have system commands unlocked -function Commands.get_system_command_players() +function Commands.get_system_players() return table.get_keys(system_players) end +--- Check if a player is a system user +function Commands.is_system_player(player_name) + return system_players[player_name] or false +end + --- Stops a command from be used by any one --- @param command_name string The name of the command to disable -function Commands.disable(command_name) +function Commands.disable_command(command_name) disabled_commands[command_name] = true end --- Allows a command to be used again after disable was used --- @param command_name string The name of the command to enable -function Commands.enable(command_name) +function Commands.enable_command(command_name) disabled_commands[command_name] = nil end ---- Get a list of all players who have system commands unlocked +--- Get a list of all disabled commands_help function Commands.get_disabled_commands() return table.get_keys(disabled_commands) end +--- Check if a player is a system user +function Commands.is_disabled_command(command_name) + return disabled_commands[command_name] or false +end + --- If a command has the flag "character_only" then the command can only be used outside of remote view authorities.character_only = add(function(player, command) @@ -89,7 +99,7 @@ authorities.admin_only = end end) ---- If a command has the flag "system_only" then only rcon connections can use the command +--- If a command has the flag "system_only" then only rcon and system users can use the command authorities.system_only = add(function(player, command) if command.flags.system_only and not system_players[player.name] then @@ -99,10 +109,10 @@ authorities.system_only = end end) ---- If Commands.disable was called then no one can use the command +--- If Commands.disable_command was called then only rcon and system users can use the command authorities.disabled = add(function(player, command) - if disabled_commands[command.name] then + if disabled_commands[command.name] and not system_players[player.name] then return deny{ "exp-commands-authorities.disabled" } else return allow() diff --git a/exp_commands/module/commands/rcon.lua b/exp_commands/module/commands/rcon.lua index 2cdce0b4..3e7b7059 100644 --- a/exp_commands/module/commands/rcon.lua +++ b/exp_commands/module/commands/rcon.lua @@ -86,6 +86,7 @@ Commands.new("_rcon", { "exp-commands_rcon.description" }) if compile_error then return Commands.status.invalid_input(compile_error) else + --- @cast invocation -nil local success, rtn = xpcall(invocation, debug.traceback) if success == false then return Commands.status.error(rtn) diff --git a/exp_commands/module/module_exports.lua b/exp_commands/module/module_exports.lua index a7245f04..6064c3ee 100644 --- a/exp_commands/module/module_exports.lua +++ b/exp_commands/module/module_exports.lua @@ -395,7 +395,7 @@ end -- The prototype definition for command objects local function assert_command_mutable(command) - if not Commands.registered_commands[command.name] then + if Commands.registered_commands[command.name] then error("Command cannot be modified after being registered.", 3) end end diff --git a/exp_legacy/module/config/_file_loader.lua b/exp_legacy/module/config/_file_loader.lua index 452ba95a..4e8047fc 100644 --- a/exp_legacy/module/config/_file_loader.lua +++ b/exp_legacy/module/config/_file_loader.lua @@ -28,7 +28,6 @@ return { "modules.addons.nukeprotect", "modules.addons.inserter", "modules.addons.miner", - "modules.addons.lawnmower", "modules.addons.logging", -- Control diff --git a/exp_legacy/module/config/expcore/roles.lua b/exp_legacy/module/config/expcore/roles.lua index faf905b6..abd745a4 100644 --- a/exp_legacy/module/config/expcore/roles.lua +++ b/exp_legacy/module/config/expcore/roles.lua @@ -22,6 +22,7 @@ end) Roles.new_role("System", "SYS") :set_permission_group("Default", true) :set_flag("is_admin") + :set_flag("is_system") :set_flag("is_spectator") :set_flag("report-immune") :set_flag("instant-respawn") @@ -31,14 +32,15 @@ Roles.new_role("Senior Administrator", "SAdmin") :set_permission_group("Admin") :set_custom_color{ r = 233, g = 63, b = 233 } :set_flag("is_admin") + :set_flag("is_system") :set_flag("is_spectator") :set_flag("report-immune") :set_flag("instant-respawn") :set_parent("Administrator") :allow{ - "command/interface", + "command/_rcon", "command/debug", - "command/toggle-cheat-mode", + "command/set-cheat-mode", "command/research-all", } @@ -54,7 +56,6 @@ Roles.new_role("Administrator", "Admin") "gui/warp-list/bypass-proximity", "gui/warp-list/bypass-cooldown", "command/connect-all", - "command/collectdata", } Roles.new_role("Moderator", "Mod") @@ -71,21 +72,29 @@ Roles.new_role("Moderator", "Mod") "command/repair", "command/kill/always", "command/clear-tag/always", - "command/go-to-spawn/always", + "command/spawn/always", "command/clear-reports", "command/clear-warnings", + "command/clear-script-warnings", + "command/clear-last-warnings", "command/clear-inventory", - -- 'command/bonus', - "gui/bonus", + "command/kill-enemies", + "command/remove-enemies", + --'command/bonus', "command/home", - "command/home-set", - "command/home-get", + "command/set-home", + "command/get-home", "command/return", "command/connect-player", + "command/set-bot-queue", + "command/set-game-speed", + "command/set-friendly-fire", + "command/set-always-day", + "command/set-pollution-enabled", + "command/clear-pollution", "gui/rocket-info/toggle-active", "gui/rocket-info/remote_launch", - "command/toggle-friendly-fire", - "command/toggle-always-day", + "gui/bonus", "fast-tree-decon", } @@ -98,15 +107,15 @@ Roles.new_role("Trainee", "TrMod") :set_parent("Veteran") :allow{ "command/admin-chat", - "command/admin-marker", "command/goto", "command/teleport", "command/bring", - "command/give-warning", + "command/create-warning", "command/get-warnings", "command/get-reports", "command/protect-entity", "command/protect-area", + "command/protect-tag", "command/jail", "command/unjail", "command/kick", @@ -114,17 +123,10 @@ Roles.new_role("Trainee", "TrMod") "command/spectate", "command/follow", "command/search", + "command/search-online", "command/search-amount", "command/search-recent", - "command/search-online", - "command/personal-battery-recharge", - "command/pollution-off", - "command/pollution-clear", - "command/bot-queue-get", - "command/bot-queue-set", - "command/game-speed", - "command/kill-biters", - "command/remove-biters", + "command/clear-blueprints", "gui/playerdata", } @@ -164,11 +166,11 @@ Roles.new_role("Sponsor", "Spon") :allow{ "gui/rocket-info/toggle-active", "gui/rocket-info/remote_launch", - -- 'command/bonus', "gui/bonus", + --"command/bonus", "command/home", - "command/home-set", - "command/home-get", + "command/set-home", + "command/get-home", "command/return", "fast-tree-decon", } @@ -182,8 +184,8 @@ Roles.new_role("Supporter", "Sup") "command/tag-color", "command/jail", "command/unjail", - "command/join-message", - "command/join-message-clear", + "command/set-join-message", + "command/remove-join-message", } Roles.new_role("Partner", "Part") @@ -203,7 +205,10 @@ Roles.new_role("Veteran", "Vet") :set_parent("Member") :allow{ "command/chat-bot", - "command/last-location", + "command/clear-ground-items", + "command/clear-blueprints-radius", + "command/set-trains-to-automatic", + "command/set-auto-research", } :set_auto_assign_condition(function(player) if player.online_time >= hours10 then @@ -226,18 +231,14 @@ Roles.new_role("Member", "Mem") "gui/task-list/edit", "gui/warp-list/add", "gui/warp-list/edit", - "command/save-quickbar", + "gui/surveillance", "gui/vlayer-edit", + "command/save-quickbar", "command/vlayer-info", "command/personal-logistic", - "command/auto-research", - "command/set-trains-to-automatic", "command/lawnmower", "command/waterfill", - "command/artillery-target-remote", - "command/clear-item-on-ground", - "command/clear-blueprint", - "gui/surveillance", + "command/artillery", } local hours3, hours15 = 3 * 216000, 15 * 60 @@ -248,7 +249,7 @@ Roles.new_role("Regular", "Reg") :allow{ "command/kill", "command/rainbow", - "command/go-to-spawn", + "command/spawn", "command/me", "standard-decon", "bypass-entity-protection", @@ -271,15 +272,14 @@ local default = Roles.new_role("Guest", "") :allow{ "command/tag", "command/tag-clear", - "command/search-help", - "command/list-roles", - "command/find-on-map", - "command/report", + "command/commands", + "command/get-role", + "command/locate", + "command/create-report", "command/ratio", "command/server-ups", "command/save-data", - "command/preference", - "command/set-preference", + "command/data-preference", "command/connect", "gui/player-list", "gui/rocket-info", diff --git a/exp_legacy/module/config/gui/player_list_actions.lua b/exp_legacy/module/config/gui/player_list_actions.lua index 520971a1..962907a5 100644 --- a/exp_legacy/module/config/gui/player_list_actions.lua +++ b/exp_legacy/module/config/gui/player_list_actions.lua @@ -12,7 +12,7 @@ local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep m local Warnings = require("modules.exp_legacy.modules.control.warnings") --- @dep modules.control.warnings local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail local Colors = require("modules/exp_util/include/color") -local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common +local format_player_name = ExpUtil.format_player_name_locale local SelectedPlayer, SelectedAction local function set_datastores(player, action) @@ -91,7 +91,7 @@ local report_player = new_button("utility/spawn_flag", { "player-list.report-pla :on_click(function(player) local selected_player_name = get_action_player_name(player) if Reports.is_reported(selected_player_name, player.name) then - player.print({ "expcom-report.already-reported" }, Colors.orange_red) + player.print({ "exp-commands_report.already-reported" }, Colors.orange_red) else SelectedAction:set(player, "command/report") end @@ -100,8 +100,8 @@ local report_player = new_button("utility/spawn_flag", { "player-list.report-pla local function report_player_callback(player, reason) local selected_player_name, selected_player_color = get_action_player_name(player) local by_player_name_color = format_player_name(player) - game.print{ "expcom-report.non-admin", selected_player_color, reason } - Roles.print_to_roles_higher("Trainee", { "expcom-report.admin", selected_player_color, by_player_name_color, reason }) + game.print{ "exp-commands_reports.response", selected_player_color, reason } + Roles.print_to_roles_higher("Trainee", { "exp-commands_reports.response-admin", selected_player_color, by_player_name_color, reason }) Reports.report_player(selected_player_name, player.name, reason) end @@ -115,7 +115,7 @@ local warn_player = new_button("utility/spawn_flag", { "player-list.warn-player" local function warn_player_callback(player, reason) local selected_player_name, selected_player_color = get_action_player_name(player) local by_player_name_color = format_player_name(player) - game.print{ "expcom-warnings.received", selected_player_color, by_player_name_color, reason } + game.print{ "exp-commands_warnings.create", selected_player_color, by_player_name_color, reason } Warnings.add_warning(selected_player_name, player.name, reason) end @@ -125,7 +125,7 @@ local jail_player = new_button("utility/multiplayer_waiting_icon", { "player-lis :on_click(function(player) local selected_player_name, selected_player_color = get_action_player_name(player) if Jail.is_jailed(selected_player_name) then - player.print({ "expcom-jail.already-jailed", selected_player_color }, Colors.orange_red) + player.print({ "exp-commands_jail.already-jailed", selected_player_color }, Colors.orange_red) else SelectedAction:set(player, "command/jail") end @@ -134,7 +134,7 @@ local jail_player = new_button("utility/multiplayer_waiting_icon", { "player-lis local function jail_player_callback(player, reason) local selected_player_name, selected_player_color = get_action_player_name(player) local by_player_name_color = format_player_name(player) - game.print{ "expcom-jail.give", selected_player_color, by_player_name_color, reason } + game.print{ "exp-commands_jail.jailed", selected_player_color, by_player_name_color, reason } Jail.jail_player(selected_player_name, player.name, reason) end diff --git a/exp_legacy/module/control.lua b/exp_legacy/module/control.lua index 8cbda5b0..b1c46a23 100644 --- a/exp_legacy/module/control.lua +++ b/exp_legacy/module/control.lua @@ -3,15 +3,6 @@ -- all files which are loaded (including the config files) are present in ./config/file_loader.lua -- this file is the landing point for all scenarios please DO NOT edit directly, further comments are to aid development -local _xpcall = xpcall ---- @diagnostic disable -xpcall = function(func, error_handler, ...) - local rtn = { _xpcall(func, error_handler, ...) } - if not rtn[1] then error(rtn[2]) end - return table.unpack(rtn) -end ---- @diagnostic enable - log("[START] -----| Explosive Gaming Scenario Loader |-----") log("[INFO] Setting up lua environment") diff --git a/exp_legacy/module/locale/en/expcore.cfg b/exp_legacy/module/locale/en/expcore.cfg index 0f9f18c3..69ec22ea 100644 --- a/exp_legacy/module/locale/en/expcore.cfg +++ b/exp_legacy/module/locale/en/expcore.cfg @@ -15,6 +15,7 @@ left-button-tooltip=Hide all open windows. [expcore-data] description-preference=Allows you to set/get your data saving preference. description-data=Writes all your player data to a file on your computer. +arg-option=One of "All", "Statistics", "Settings", "Required" set-preference=You data saving preference has been set to __1__. Existing data will not be effected until you rejoin. get-preference=You data saving preference is __1__. Use /set-preference to change this. Use /save-data to get a local copy of your data. get-data=Your player data has been writen to file, location: factorio/script_output/expgaming_player_data.json diff --git a/exp_legacy/module/modules/addons/compilatron.lua b/exp_legacy/module/modules/addons/compilatron.lua index 5aab162e..706b8c92 100644 --- a/exp_legacy/module/modules/addons/compilatron.lua +++ b/exp_legacy/module/modules/addons/compilatron.lua @@ -23,6 +23,9 @@ end) local speech_bubble_async = Async.register(function(data) + --- @cast data { ent: LuaEntity, name: string, msg_number: number } + if not data.ent.valid then return end + local message = data.ent.surface.create_entity{ name = "compi-speech-bubble", diff --git a/exp_legacy/module/modules/addons/protection-jail.lua b/exp_legacy/module/modules/addons/protection-jail.lua index 7af19afe..079fd239 100644 --- a/exp_legacy/module/modules/addons/protection-jail.lua +++ b/exp_legacy/module/modules/addons/protection-jail.lua @@ -6,7 +6,7 @@ local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Storage = require("modules/exp_util/storage") --- @dep utils.global local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail local Protection = require("modules.exp_legacy.modules.control.protection") --- @dep modules.control.protection -local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common +local format_player_name = ExpUtil.format_player_name_locale --- Stores how many times the repeat violation was triggered local repeat_count = {} diff --git a/exp_legacy/module/modules/addons/report-jail.lua b/exp_legacy/module/modules/addons/report-jail.lua index 91312264..c86f6838 100644 --- a/exp_legacy/module/modules/addons/report-jail.lua +++ b/exp_legacy/module/modules/addons/report-jail.lua @@ -5,7 +5,7 @@ local ExpUtil = require("modules/exp_util") local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports -local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common +local format_player_name = ExpUtil.format_player_name_locale --- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters local function reporter_playtime(_, by_player_name, _) diff --git a/exp_legacy/module/modules/gui/readme.lua b/exp_legacy/module/modules/gui/readme.lua index 77139ba8..7159977a 100644 --- a/exp_legacy/module/modules/gui/readme.lua +++ b/exp_legacy/module/modules/gui/readme.lua @@ -8,7 +8,7 @@ local ExpUtil = require("modules/exp_util") local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles -local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands +local Commands = require("modules/exp_commands") --- @dep expcore.commands local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external local format_number = require("util").format_number --- @dep util @@ -193,9 +193,9 @@ define_tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, commands.style.cell_padding = 0 -- Add the rules to the table - for name, command in pairs(Commands.get(player)) do + for name, command in pairs(Commands.list_for_player(player)) do Gui.centered_label(commands, 120, name) - Gui.centered_label(commands, 450, command.help) + Gui.centered_label(commands, 450, command.description) end return container diff --git a/exp_legacy/module/modules/gui/vlayer.lua b/exp_legacy/module/modules/gui/vlayer.lua index 926af2b6..6389947a 100644 --- a/exp_legacy/module/modules/gui/vlayer.lua +++ b/exp_legacy/module/modules/gui/vlayer.lua @@ -395,7 +395,7 @@ local vlayer_gui_control_build = Selection.stop(player) else Selection.start(player, SelectionConvertArea) - player.print{ "expcom-waterfill.entered-area-selection" } + player.print{ "exp-commands_waterfill.entered-area-selection" } end vlayer_gui_list_refresh(player) diff --git a/exp_scenario/module/commands/_authorities.lua b/exp_scenario/module/commands/_authorities.lua index 8c0dfa47..dc6f9383 100644 --- a/exp_scenario/module/commands/_authorities.lua +++ b/exp_scenario/module/commands/_authorities.lua @@ -13,11 +13,19 @@ local authorities = {} --- If a command has the flag "character_only" then the command can only be used outside of remote view authorities.exp_permission = add(function(player, command) - if not player_allowed(player, command.flags.exp_permission or ("command/" .. command)) then + if not player_allowed(player, command.flags.exp_permission or ("command/" .. command.name)) then return deny{ "exp-commands-authorities_role.deny" } else return allow() end end) +Roles.define_flag_trigger("is_system", function(player, state) + if state then + Commands.unlock_system_commands(player.name) + else + Commands.lock_system_commands(player.name) + end +end) + return authorities diff --git a/exp_scenario/module/commands/bot_queue.lua b/exp_scenario/module/commands/bot_queue.lua index 44977d96..fc7775dc 100644 --- a/exp_scenario/module/commands/bot_queue.lua +++ b/exp_scenario/module/commands/bot_queue.lua @@ -5,8 +5,9 @@ Adds a command that allows viewing and changing the construction queue limits local Commands = require("modules/exp_commands") --- Get / Set the current values for the bot queue -Commands.new("bot-queue", { "exp-commands_bot-queue.description" }) +Commands.new("set-bot-queue", { "exp-commands_bot-queue.description" }) :optional("amount", { "exp-commands_bot-queue.arg-amount" }, Commands.types.integer_range(1, 20)) + :add_aliases{ "bot-queue" } :add_flags{ "admin_only" } :register(function(player, amount) if amount then diff --git a/exp_scenario/module/commands/connect.lua b/exp_scenario/module/commands/connect.lua index fc97ac8c..5cb4b4f0 100644 --- a/exp_scenario/module/commands/connect.lua +++ b/exp_scenario/module/commands/connect.lua @@ -52,7 +52,7 @@ end --- Connect to a different server Commands.new("connect", { "exp-commands_connect.description" }) :argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string) - :optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean) + :optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean) :add_aliases{ "join" } :register(function(player, server, is_address) --- @cast server string @@ -72,7 +72,7 @@ Commands.new("connect", { "exp-commands_connect.description" }) Commands.new("connect-player", { "exp-commands_connect.description-player" }) :argument("player", { "exp-commands_connect.arg-player" }, Commands.types.player_online) :argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string) - :optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean) + :optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean) :add_flags{ "admin_only" } :register(function(player, other_player, server, is_address) --- @cast other_player LuaPlayer @@ -92,7 +92,7 @@ Commands.new("connect-player", { "exp-commands_connect.description-player" }) --- Connect all players to a different server Commands.new("connect-all", { "exp-commands_connect.description-all" }) :argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string) - :optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean) + :optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean) :add_flags{ "admin_only" } :register(function(player, server, is_address) --- @cast server string diff --git a/exp_scenario/module/commands/protected_entities.lua b/exp_scenario/module/commands/protected_entities.lua index 59626dd6..fab57839 100644 --- a/exp_scenario/module/commands/protected_entities.lua +++ b/exp_scenario/module/commands/protected_entities.lua @@ -92,28 +92,28 @@ local function remove_render(player, key) end --- Toggles entity protection selection -Commands.new("protect-entity", { "exp-commands_protection.description-entity" }) +Commands.new("protect-entity", { "exp-commands_entity-protection.description-entity" }) :add_aliases{ "pe" } :register(function(player) if Selection.is_selecting(player, SelectionNameEntity) then Selection.stop(player) - return Commands.status.success{ "exp-commands_protection.exit-entity" } + return Commands.status.success{ "exp-commands_entity-protection.exit-entity" } else Selection.start(player, SelectionNameEntity) - return Commands.status.success{ "exp-commands_protection.enter-entity" } + return Commands.status.success{ "exp-commands_entity-protection.enter-entity" } end end) --- Toggles area protection selection -Commands.new("protect-area", { "exp-commands_protection.description-area" }) +Commands.new("protect-area", { "exp-commands_entity-protection.description-area" }) :add_aliases{ "pa" } :register(function(player) if Selection.is_selecting(player, SelectionNameEntity) then Selection.stop(player) - return Commands.status.success{ "exp-commands_protection.exit-area" } + return Commands.status.success{ "exp-commands_entity-protection.exit-area" } else Selection.start(player, SelectionNameEntity) - return Commands.status.success{ "exp-commands_protection.enter-area" } + return Commands.status.success{ "exp-commands_entity-protection.enter-area" } end end) @@ -126,7 +126,7 @@ Selection.on_selection(SelectionNameEntity, function(event) show_protected_entity(player, entity) end - player.print({ "exp-commands_protection.protected-entities", #event.entities }, Commands.print_settings.default) + player.print({ "exp-commands_entity-protection.protected-entities", #event.entities }, Commands.print_settings.default) end) --- When an area is selected to remove protection from entities @@ -138,7 +138,7 @@ Selection.on_alt_selection(SelectionNameEntity, function(event) remove_render(player, get_entity_key(entity)) end - player.print({ "exp-commands_protection.unprotected-entities", #event.entities }, Commands.print_settings.default) + player.print({ "exp-commands_entity-protection.unprotected-entities", #event.entities }, Commands.print_settings.default) end) --- When an area is selected to add protection to the area @@ -150,13 +150,13 @@ Selection.on_selection(SelectionNameArea, function(event) local player = game.players[event.player_index] for _, next_area in pairs(areas) do if contains_area(next_area, area) then - return player.print({ "exp-commands_protection.already-protected" }, Commands.print_settings.error) + return player.print({ "exp-commands_entity-protection.already-protected" }, Commands.print_settings.error) end end EntityProtection.add_area(surface, area) show_protected_area(player, surface, area) - player.print({ "exp-commands_protection.protected-area" }, Commands.print_settings.default) + player.print({ "exp-commands_entity-protection.protected-area" }, Commands.print_settings.default) end) --- When an area is selected to remove protection from the area @@ -169,7 +169,7 @@ Selection.on_alt_selection(SelectionNameArea, function(event) for _, next_area in pairs(areas) do if contains_area(area, next_area) then EntityProtection.remove_area(surface, next_area) - player.print({ "exp-commands_protection.unprotected-area" }, Commands.print_settings.default) + player.print({ "exp-commands_entity-protection.unprotected-area" }, Commands.print_settings.default) remove_render(player, get_area_key(next_area)) end end @@ -222,7 +222,7 @@ end --- When there is a repeat offence print it in chat local function on_repeat_violation(event) Roles.print_to_roles_higher("Regular", { - "exp-commands_protection.repeat-offence", + "exp-commands_entity-protection.repeat-offence", format_player_name(event.player_index), event.entity.localised_name, event.entity.position.x, diff --git a/exp_scenario/module/commands/protected_tags.lua b/exp_scenario/module/commands/protected_tags.lua index 51be3610..1667b008 100644 --- a/exp_scenario/module/commands/protected_tags.lua +++ b/exp_scenario/module/commands/protected_tags.lua @@ -18,17 +18,17 @@ Storage.register({ end) --- Toggle admin marker mode, can only be applied to yourself -local cmd_protected_tag = - Commands.new("protected-tag", { "exp-commands_protected-tags.description" }) +local cmd_protect_tag = + Commands.new("protect-tag", { "exp-commands_tag-protection.description" }) :add_aliases{ "ptag" } :add_flags{ "admin_only" } :register(function(player) if active_players[player.index] then active_players[player.index] = nil - return Commands.status.success{ "exp-commands_protected-tags.exit" } + return Commands.status.success{ "exp-commands_tag-protection.exit" } else active_players[player.index] = true - return Commands.status.success{ "exp-commands_protected-tags.enter" } + return Commands.status.success{ "exp-commands_tag-protection.enter" } end end) @@ -47,7 +47,7 @@ local function on_chart_tag_added(event) local tag = event.tag local player = game.players[event.player_index] map_tags[tag.force.name .. tag.tag_number] = true - player.print{ "exp-commands_protected-tags.create" } + player.print{ "exp-commands_tag-protection.create" } end --- Stop a tag from being edited or removed @@ -60,7 +60,7 @@ local function on_chart_tag_removed_or_modified(event) -- Check if the player is in protected mode, and inform them that it was protected if active_players[event.player_index] then - player.print{ "exp-commands_protected-tags.edit" } + player.print{ "exp-commands_tag-protection.edit" } return end @@ -92,12 +92,12 @@ local function on_chart_tag_removed_or_modified(event) map_tags[new_tag.force.name .. new_tag.tag_number] = true end - if Commands.player_has_permission(player, cmd_protected_tag) then + if Commands.player_has_permission(player, cmd_protect_tag) then -- Player is not in protected mode, but has access to the command - player.print({ "exp-commands_protected-tags.revert-has-access", cmd_protected_tag.name }, Commands.print_settings.error) + player.print({ "exp-commands_tag-protection.revert-has-access", cmd_protect_tag.name }, Commands.print_settings.error) else --- Player does not have access to protected mode - player.print({ "exp-commands_protected-tags.revert-no-access" }, Commands.print_settings.error) + player.print({ "exp-commands_tag-protection.revert-no-access" }, Commands.print_settings.error) end end diff --git a/exp_scenario/module/commands/rainbow.lua b/exp_scenario/module/commands/rainbow.lua index 48580da0..1084f84c 100644 --- a/exp_scenario/module/commands/rainbow.lua +++ b/exp_scenario/module/commands/rainbow.lua @@ -52,7 +52,7 @@ local function next_color(color, step) end --- Sends an rainbow message in the chat -Commands.new("rainbow", { "exp-commands_rainbow" }) +Commands.new("rainbow", { "exp-commands_rainbow.description" }) :argument("message", { "exp-commands_rainbow.arg-message" }, Commands.types.string) :enable_auto_concatenation() :register(function(player, message) diff --git a/exp_scenario/module/commands/ratio.lua b/exp_scenario/module/commands/ratio.lua index fffaefd1..2e12e444 100644 --- a/exp_scenario/module/commands/ratio.lua +++ b/exp_scenario/module/commands/ratio.lua @@ -4,23 +4,23 @@ Adds a command to calculate the number of machines needed to fulfil a desired pr local Commands = require("modules/exp_commands") -Commands.new("ratio", { "exp-command_ratio.description" }) - :optional("items-per-second", { "exp-command_ratio.arg-items-per-second" }, Commands.types.number) +Commands.new("ratio", { "exp-commands_ratio.description" }) + :optional("items-per-second", { "exp-commands_ratio.arg-items-per-second" }, Commands.types.number) :register(function(player, items_per_second) --- @cast items_per_second number? local machine = player.selected if not machine then - return Commands.status.error{ "exp-command_ratio.not-selecting" } + return Commands.status.error{ "exp-commands_ratio.not-selecting" } end if machine.type ~= "assembling-machine" and machine.type ~= "furnace" then - return Commands.status.error{ "exp-command_ratio.not-selecting" } + return Commands.status.error{ "exp-commands_ratio.not-selecting" } end local recipe = machine.get_recipe() if not recipe then - return Commands.status.error{ "exp-command_ratio.not-selecting" } + return Commands.status.error{ "exp-commands_ratio.not-selecting" } end local products = recipe.products @@ -34,7 +34,7 @@ Commands.new("ratio", { "exp-command_ratio.description" }) for _, ingredient in ipairs(ingredients) do Commands.print{ - ingredient.type == "item" and "exp-command_ratio.item-out" or "exp-command_ratio.fluid-out", + ingredient.type == "item" and "exp-commands_ratio.item-out" or "exp-commands_ratio.fluid-out", math.round(ingredient.amount * crafts_per_second, 3), ingredient.name } @@ -42,13 +42,13 @@ Commands.new("ratio", { "exp-command_ratio.description" }) for i, product in ipairs(products) do Commands.print{ - product.type == "item" and "exp-command_ratio.item-out" or "exp-command_ratio.fluid-out", + product.type == "item" and "exp-commands_ratio.item-out" or "exp-commands_ratio.fluid-out", math.round(product.amount * crafts_per_second, 3), product.name } end if amount_of_machines ~= 1 then - Commands.print{ "exp-command_ratio.machine-count", amount_of_machines } + Commands.print{ "exp-commands_ratio.machine-count", amount_of_machines } end end) diff --git a/exp_scenario/module/commands/search.lua b/exp_scenario/module/commands/search.lua index e0869067..13bc03b8 100644 --- a/exp_scenario/module/commands/search.lua +++ b/exp_scenario/module/commands/search.lua @@ -125,7 +125,7 @@ end Commands.new("search", { "exp-commands_search.description-search" }) :argument("item", { "exp-commands_search.arg-item" }, parse_item) :enable_auto_concatenation() - :add_aliases{ "s" } + :add_aliases{ "si" } -- cant use /s :register(function(player, item) --- @cast item LuaItemPrototype local results = search_players(game.players, item) @@ -172,7 +172,7 @@ end Commands.new("search-recent", { "exp-commands_search.description-recent" }) :argument("item", { "exp-commands_search.arg-item" }, parse_item) :enable_auto_concatenation() - :add_aliases{ "sr" } -- cant use /sc + :add_aliases{ "sr" } :register(function(player, item) --- @cast item LuaItemPrototype local results = search_players(game.players, item) diff --git a/exp_scenario/module/commands/spectate.lua b/exp_scenario/module/commands/spectate.lua index 48733940..13907289 100644 --- a/exp_scenario/module/commands/spectate.lua +++ b/exp_scenario/module/commands/spectate.lua @@ -17,12 +17,12 @@ Commands.new("spectate", { "exp-commands_spectate.description-spectate" }) --- Enters follow mode for the caller, following the given player. Commands.new("follow", { "exp-commands_spectate.description-follow" }) - :argument("player", { "exp-command_spectate.arg-player" }, Commands.types.player_online) + :argument("player", { "exp-commands_spectate.arg-player" }, Commands.types.player_online) :add_aliases{ "f" } :register(function(player, other_player) --- @cast other_player LuaPlayer if player == other_player then - return Commands.status.invalid_input{ "exp-command_spectate.follow-self" } + return Commands.status.invalid_input{ "exp-commands_spectate.follow-self" } else Spectate.start_follow(player, other_player) end diff --git a/exp_scenario/module/commands/surface.lua b/exp_scenario/module/commands/surface.lua index 95392d57..5bcdeab9 100644 --- a/exp_scenario/module/commands/surface.lua +++ b/exp_scenario/module/commands/surface.lua @@ -71,7 +71,7 @@ Commands.new("clear-blueprints", { "exp-commands_surface.description-blueprints" --- Clear all blueprints in a radius around you Commands.new("clear-blueprints-radius", { "exp-commands_surface.description-radius" }) - :argument("radius", { "exp-commands_surface.arg-radius" }, Commands.types.number_range(1, 1000)) + :argument("radius", { "exp-commands_surface.arg-radius" }, Commands.types.number_range(1, 100)) :register(function(player, radius) --- @cast radius number local player_name = format_player_name(player) diff --git a/exp_scenario/module/commands/teleport.lua b/exp_scenario/module/commands/teleport.lua index e22443e8..f7c4fd91 100644 --- a/exp_scenario/module/commands/teleport.lua +++ b/exp_scenario/module/commands/teleport.lua @@ -59,7 +59,7 @@ Commands.new("goto", { "exp-commands_teleport.description-goto" }) --- Teleport to spawn Commands.new("spawn", { "exp-commands_teleport.description-spawn" }) - :optional("player", { "exp-commands_teleport.arg-player-spawn" }, Commands.types.player_alive) + :optional("player", { "exp-commands_teleport.arg-player-from" }, Commands.types.player_alive) :defaults{ player = function(player) if player.character and player.character.health > 0 then diff --git a/exp_scenario/module/control.lua b/exp_scenario/module/control.lua index 797908a6..c9efa4bd 100644 --- a/exp_scenario/module/control.lua +++ b/exp_scenario/module/control.lua @@ -4,9 +4,9 @@ local event_handler = require("event_handler") local add = event_handler.add_lib --- Command Extensions -require("modules.exp_scenario/commands/_authorities") -require("modules.exp_scenario/commands/_rcon") -require("modules.exp_scenario/commands/_types") +require("modules/exp_scenario/commands/_authorities") +require("modules/exp_scenario/commands/_rcon") +require("modules/exp_scenario/commands/_types") --- Commands with events add(require("modules/exp_scenario/commands/protected_entities")) @@ -16,7 +16,7 @@ add(require("modules/exp_scenario/commands/research")) --- Commands require("modules/exp_scenario/commands/admin_chat") require("modules/exp_scenario/commands/artillery") -require("modules/exp_scenario/commands/bot_queues") +require("modules/exp_scenario/commands/bot_queue") require("modules/exp_scenario/commands/cheat") require("modules/exp_scenario/commands/clear_inventory") require("modules/exp_scenario/commands/connect") diff --git a/exp_scenario/module/locale/en.cfg b/exp_scenario/module/locale/en.cfg index ce8b8d50..52edc056 100644 --- a/exp_scenario/module/locale/en.cfg +++ b/exp_scenario/module/locale/en.cfg @@ -17,7 +17,7 @@ enter=Entered artillery selection mode. exit=Existed artillery selection mode. [exp-commands_bot-queue] -description-get=Get / Set the construction bot queue limits. +description=Get / Set the construction bot queue limits. arg-amount=Multiple of default value to set the queues to. get=Bot queue is __1__ successful attempts and __2__ failed attempts. set=__1__ set the bot queue to __2__ successful attempts and __3__ failed attempts. @@ -29,7 +29,7 @@ description-friendly-fire=Set friendly fire for your force, or another force. description-research-all=Research all technology for your force, or another force. description-clear-pollution=Clear pollution from your current surface, or another surface. description-pollution-enabled=Set polution enabled state for this game. -description=game-speed=Set or get the current game speed. +description-game-speed=Set or get the current game speed. arg-state=State to set, default is to toggle the current value. arg-player=Player to toggle cheat mode for. arg-force-friendly-fire=Force to research all technology for. @@ -62,7 +62,7 @@ same-server=You are already connected to the server: __1__ offline=You cannot connect as the server is currently offline: __1__ none-matching=No servers were found with that name, if you used an address please append true to the end of your command. -[expcom-debug] +[exp-commands_debug] description=Opens the debug gui. [exp-commands_enemy] @@ -115,7 +115,7 @@ description=Sends an action message in the chat. arg-action=Action you want to perform. response=* __1__ __2__ * -[expcom-protection] +[exp-commands_entity-protection] description-entity=Toggles entity protection selection, hold shift to remove protection description-area=Toggles area protection selection, hold shift to remove protection enter-entity-selection=Entered entity selection, select entites to protect, hold shift to remove protection. @@ -129,7 +129,7 @@ protected-area=This area is now protected. unprotected-area=This area is now unprotected. repeat-offence=__1__ has removed __2__ at [gps=__3__,__4__] -[exp-commands_protected-tags] +[exp-commands_tag-protection] description=Toggles protected tag mode, edit and create protected map tags. exit=You have left protected tag mode, any new tags will not be protected. enter=You have entered protected tag mode, any new tags will be protected. @@ -183,14 +183,14 @@ removed-all=__1__ has has all of their reports removed by __2__. removed=__1__ has a report removed by __2__. [exp-commands_research] -description-ares=Sets research to be automatically queued. +description=Sets research to be automatically queued. arg-state=State to set, default is to toggle. auto-research=__1__ set auto research to __2__ queue=[color=255, 255, 255] Research added to queue - [technology=__1__] - __2__[/color] [exp-commands_roles] -description-assign-role=Assigns a role to a player. -description-unassign-role=Unassigns a role from a player. +description-assign=Assigns a role to a player. +description-unassign=Unassigns a role from a player. description-get=Get all roles that a player has, if no player provided it lists all roles. arg-player-assign=Player to assign the role to. arg-player-unassign=Player to unassign the role from. @@ -207,6 +207,7 @@ description-online=Display online players sorted by the quantity of an item held description-amount=Display players sorted by the quantity of an item held. description-recent=Display players who hold an item sorted by join time. invalid-item=No item was found with internal name __1__; try using rich text selection. +arg-item=Item to search for. no-results=No players have [item=__1__] title=Players found with [item=__1__]: result=\n__1__) __2__ has __3__ items. (__4__) @@ -222,7 +223,7 @@ description-items=Clear all items on the ground. description-blueprints=Clear all blueprints. description-radius=Clear all blueprints in an radius around you. arg-surface=Surface to clear on, default all. -arg-radis=Radius to clear. +arg-radius=Radius to clear. items-surface=__1__ cleared all items on the ground of __2__. items-all=__1__ cleared all items on the ground for all surfaces. blueprints-surface=__1__ cleared all blueprints on __2__. @@ -241,7 +242,7 @@ description-bring=Teleports a player to you. description-goto=Teleports you to a player. description-spawn=Teleport to spawn arg-player-teleport=Player to teleport, if target is not given then you are teleported to this player. -arg-player-from=Player to teleported. +arg-player-from=Player to teleport. arg-player-to=Player who is the target. unavailable=They was a problem teleporting you, likely no position found, please try again later. same-player=Player can not be teleported to themselves. @@ -259,7 +260,7 @@ description-clear-script=Clears all script warnings from a player. description-clear-last=Clears the last warning from a player. arg-player-create=Player to give the warning to. arg-player-get=Player to get the warning of, if not given all players are returned. -arg-player=clear=Player to clear the warnings of. +arg-player-clear=Player to clear the warnings of. arg-reason=Reason the user is receiving a warning. create=__1__ received a warning from __2__ for __3__. player-title=__1__ has __2__ warnings and __3__/__4__ script warnings. diff --git a/exp_util/module/include/require.lua b/exp_util/module/include/require.lua index d1de99de..20ffca0b 100644 --- a/exp_util/module/include/require.lua +++ b/exp_util/module/include/require.lua @@ -8,8 +8,18 @@ local _require = require -- This replace function is used to avoid additional lines in stack traces during control stage local function replace() require = function(path) + --- @cast path string if package.lifecycle == package.lifecycle_stage.runtime then - return loaded[path] or loaded[path:gsub(".", "/")] or error("Can only require files at runtime that have been required in the control stage.", 2) + local replaced = path:gsub("%.", "/") + if not replaced:match("^__(.-)__") then + replaced = "__level__/" .. replaced + end + if not replaced:match(".lua$") then + replaced = replaced .. ".lua" + end + return loaded[path] + or loaded[replaced] + or error("Can only require files at runtime that have been required in the control stage.", 2) else return _require(path) end diff --git a/exp_util/module/module_exports.lua b/exp_util/module/module_exports.lua index 8bed524c..f3881a5c 100644 --- a/exp_util/module/module_exports.lua +++ b/exp_util/module/module_exports.lua @@ -2,6 +2,10 @@ Adds some commonly used functions used in many modules ]] +-- Make sure these are loaded first so locals below work +require("modules/exp_util/include/math") +require("modules/exp_util/include/table") + local type = type local assert = assert local getmetatable = getmetatable @@ -158,7 +162,7 @@ end function ExpUtil.get_function_name(func, raw) local debug_info = getinfo(func, "Sn") local safe_source = debug_info.source:find("@__level__") - local file_name = safe_source == 1 and debug_info.short_src:sub(10, -5) or debug_info.source + local file_name = safe_source == 1 and debug_info.source:sub(12, -5) or debug_info.source local func_name = debug_info.name or debug_info.linedefined if raw then return file_name .. ":" .. func_name end return "<" .. file_name .. ":" .. func_name .. ">" @@ -192,21 +196,25 @@ end --- @return LocalisedString # The formatted version of the value --- @return boolean # True if value is a locale string, nil otherwise function ExpUtil.safe_value(value) - if type(value) == "table" then + local _type = type(value) + if _type == "table" then local v1 = value[1] local str = tostring(value) if type(v1) == "string" and not v1:find("%s") - and (v1 == "" or v1 == "?" or v1:find(".+[.].+")) then + and (v1 == "" or v1 == "?" or v1:find(".+[.].+")) + and #value <= 20 then return value, true -- locale string elseif str ~= "table" then return str, false -- has __tostring metamethod else -- plain table return value, false end - elseif type(value) == "function" then -- function + elseif _type == "function" then -- function return "", false - else -- not: table or function + elseif _type == "thread" or _type == "userdata" then -- unsafe value return tostring(value), false + else -- already safe value + return value, false end end diff --git a/exp_util/module/storage.lua b/exp_util/module/storage.lua index 15d0776d..f064040c 100644 --- a/exp_util/module/storage.lua +++ b/exp_util/module/storage.lua @@ -45,7 +45,7 @@ local my_metatable = Storage.register_metatable("MyMetaTable", { ]] -local ExpUtil = require("modules/exp_util/common") +local ExpUtil = require("modules/exp_util") --- @class ExpUtil_Storage local Storage = {