From 66526bbe800816efab14bef4f45b0ceb3089a4ce Mon Sep 17 00:00:00 2001 From: ZwerOxotnik Date: Thu, 7 Sep 2023 14:27:57 +0300 Subject: [PATCH] Update to 0.6.0 --- .editorconfig | 4 +- README.md | 8 +- changelog.txt | 6 + const-commands.lua | 41 +-- control.lua | 33 ++- defines.lua | 8 +- info.json | 25 +- models/BetterCommands/README.md | 19 -- models/BetterCommands/control.lua | 279 -------------------- models/data-consistency-example.lua | 17 +- models/empty-module.lua | 4 +- models/example-module.lua | 4 +- scenarios/example/control.lua | 16 +- scenarios/example/info.json | 1 + scenarios/example/models/example-module.lua | 4 +- settings.lua | 11 +- snippets.lua | 39 --- switchable-commands.lua | 40 +-- 18 files changed, 151 insertions(+), 408 deletions(-) delete mode 100644 models/BetterCommands/README.md delete mode 100644 models/BetterCommands/control.lua create mode 100644 scenarios/example/info.json delete mode 100644 snippets.lua diff --git a/.editorconfig b/.editorconfig index 1a20351..4da8392 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ trim_trailing_whitespace = true indent_style = tab insert_final_newline = true -[*.{txt,yml}] +[*.{txt,yml,json}] indent_style = space indent_size = 2 insert_final_newline = false @@ -24,7 +24,7 @@ indent_size = 2 insert_final_newline = true trim_trailing_whitespace = false -[*.{json,md}] +[*.md] indent_style = tab indent_size = 2 insert_final_newline = false diff --git a/README.md b/README.md index f575eae..1e2e3f9 100644 --- a/README.md +++ b/README.md @@ -58,18 +58,19 @@ What it can do -------------- * Filter parameters of commands -* Add switchable commands via map settings +* Add switchable, customizable commands via map settings * Double check of commands * Use built-in error handling of commands * Use modular structure * Remotely and safely disable your mod +* Auto adds remote access for rcon and for other mods/scenarios * Auto publishing on [mods.portal.com](https://mods.factorio.com/) and on your GitHub repository What it enables you to do ------------------------- * Handle sounds by a [script](.scripts/handle_sounds.sh) -* Make switchable, simpler and safer [commands](models/BetterCommands/README.md) +* Make switchable, simpler and safer [commands](https://github.com/ZwerOxotnik/factorio-BetterCommands) * Make "isolated" modules * Expand your modules * More possibilities to control logic @@ -120,7 +121,6 @@ How to start? * **Change or delete** .github/ISSUE_TEMPLATE/* * **Change or delete** .github/workflows/* (please read [this](https://github.com/shanemadden/factorio-mod-portal-publish)) * Handle files in [control.lua](control.lua) -* Change settings in [models/BetterCommands/control.lua](models/BetterCommands/control.lua) if you want Notes ----- @@ -159,7 +159,7 @@ sudo apt install p7zip-full jq git -y Optional Dependencies --------------------- -* zk-lib - for localization of [BetterCommands](models/BetterCommands/control.lua) and [event handler](/control.lua), currently +* zk-lib - for localization of [event handler](/control.lua), currently ‼️ Important Links (Translations, Discord Support) --------------------------------------------------------------- diff --git a/changelog.txt b/changelog.txt index 5f07fe8..29c77ad 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,10 @@ --------------------------------------------------------------------------------------------------- +Version: 0.6.0 +Date: 2023-09-07 + Changes: + - Auto adds remote access for rcon and for other mods/scenarios + - Improved commands greatly +--------------------------------------------------------------------------------------------------- Version: 0.5.1 Date: 2022-01-07 Changes: diff --git a/const-commands.lua b/const-commands.lua index 8bf8005..033b998 100644 --- a/const-commands.lua +++ b/const-commands.lua @@ -1,17 +1,28 @@ --- Recommended to know about https://lua-api.factorio.com/latest/LuaCommandProcessor.html#LuaCommandProcessor.add_command - ---[[ +--[[ Uses https://github.com/ZwerOxotnik/factorio-BetterCommands Returns tables of commands without functions as command "settings". All parameters are optional! - Contains: - name :: string: The name of your /command. (default: key of the table) - description :: string or LocalisedString: The description of your command. (default: nil) - is_allowed_empty_args :: boolean: Ignores empty parameters in commands, otherwise stops the command. (default: true) - input_type :: string: filter for parameters by type of input. (default: nil) - possible variants: - "player" - Stops execution if can't find a player by parameter - "team" - Stops execution if can't find a team (force) by parameter - allow_for_server :: boolean: Allow execution of a command from a server (default: false) - only_for_admin :: boolean: The command can be executed only by admins (default: false) + Contains: + name :: string: The name of your /command. (default: key of the table) + description :: string or LocalisedString: The description of your command. (default: nil) + is_allowed_empty_args :: boolean: Ignores empty parameters in commands, otherwise stops the command. (default: true) + input_type :: string: Filter for parameters by type of input. (default: nil) + possible variants: + "player" - Stops execution if can't find a player by parameter + "team" - Stops execution if can't find a team (force) by parameter + allow_for_server :: boolean: Allow execution of a command from a server (default: false) + only_for_admin :: boolean: The command can be executed only by admins (default: false) + allow_for_players :: string[]: Allows to use the command for players with specified names (default: nil) + max_input_length :: uint: Max amount of characters for command (default: 500) + is_logged :: boolean: Logs the command into .log file (default: false) + alternative_names :: string[]: Alternative names for the command (all commands should be added) (default: nil) + is_one_time_use :: boolean: Disables the command after using it (default: false) + is_one_time_use_for_player :: boolean: Disables for a player after using it (default: false) + is_one_time_use_for_force :: boolean: Disables for a force after using it (default: false) + global_cooldown :: uint: The command can be used each N seconds (default: nil) + player_cooldown :: uint: The command can be used each N seconds for players (default: nil) + force_cooldown :: uint: The command can be used each N seconds for forces (default: nil) + disable_cooldown_for_admins :: boolean: Disables cooldown for admins (default: false) + disable_cooldown_for_server :: boolean: Disables cooldown for server (default: true) ]]-- ----@type table -return {} +---@type table +return { +} diff --git a/control.lua b/control.lua index a4969e3..4b036ab 100644 --- a/control.lua +++ b/control.lua @@ -8,12 +8,21 @@ require("defines") ---@type table local modules = {} -modules.better_commands = require("models/BetterCommands/control") modules.example_module = require("models/example-module") modules.data_consistency_example = require("models/data-consistency-example") -- modules.empty_module = require("models.empty-module") +--- Adds https://github.com/ZwerOxotnik/factorio-BetterCommands if exists +if script.active_mods["BetterCommands"] then + local is_ok, better_commands = pcall(require, "__BetterCommands__/BetterCommands/control") + if is_ok then + better_commands.COMMAND_PREFIX = MOD_SHORT_NAME + modules.better_commands = better_commands + end +end + + -- Safe disabling of this mod remotely on init stage -- Useful for other map developers and in some rare cases for mod devs if remote.interfaces["disable-" .. script.mod_name] then @@ -29,7 +38,14 @@ if remote.interfaces["disable-" .. script.mod_name] then module.on_init = update_global_data_on_disabling end else - modules.better_commands:handle_custom_commands(modules.example_module) -- adds commands + if modules.better_commands then + if modules.better_commands.handle_custom_commands then + modules.better_commands.handle_custom_commands(modules.example_module) -- adds commands + end + if modules.better_commands.expose_global_data then + modules.better_commands.expose_global_data() + end + end end @@ -45,6 +61,19 @@ event_handler = event_handler or require("event_handler") event_handler.add_libraries(modules) +-- Auto adds remote access for rcon and for other mods/scenarios via zk-lib +if script.active_mods["zk-lib"] then + local is_ok, remote_interface_util = pcall(require, "__zk-lib__/static-libs/lualibs/control_stage/remote-interface-util") + if is_ok and remote_interface_util.expose_global_data then + remote_interface_util.expose_global_data() + end + local is_ok, rcon_util = pcall(require, "__zk-lib__/static-libs/lualibs/control_stage/rcon-util") + if is_ok and rcon_util.expose_global_data then + rcon_util.expose_global_data() + end +end + + -- This is a part of "gvv", "Lua API global Variable Viewer" mod. https://mods.factorio.com/mod/gvv -- It makes possible gvv mod to read sandboxed variables in the map or other mod if following code is inserted at the end of empty line of "control.lua" of each. if script.active_mods["gvv"] then require("__gvv__.gvv")() end diff --git a/defines.lua b/defines.lua index d050858..f9eb894 100644 --- a/defines.lua +++ b/defines.lua @@ -1,4 +1,4 @@ --- Change everything in this file in your mod! +-- Change data in this file in your mod! local _data = { MOD_NAME = "example-mod", MOD_PATH = "__example-mod__", @@ -8,8 +8,10 @@ local _data = { AUTHOR = "ZwerOxotnik" } -if not MAKE_DEFINE_GLOBAL or (not IS_DATA_STAGE and script and script.active_mods) then - return _data +if (not IS_DATA_STAGE and script and script.active_mods) then + if not MAKE_DEFINE_GLOBAL then + return _data + end end --- Make content of _data global diff --git a/info.json b/info.json index e35dacc..6522d8b 100644 --- a/info.json +++ b/info.json @@ -1,14 +1,15 @@ { - "name": "example-mod", - "version": "0.5.2", - "factorio_version": "1.1", - "title": "Example mod", - "author": "Put your nickname", - "contact": "Put your contacts", - "homepage": "Put a link", - "description": "See locale/en ", - "dependencies": [ - "? zk-lib >= 0.10.0", - "(?) gvv" - ] + "name": "example-mod", + "version": "0.6.0", + "factorio_version": "1.1", + "title": "Example mod", + "author": "Put your nickname", + "contact": "Put your contacts", + "homepage": "Put a link", + "description": "Put description here", + "dependencies": [ + "? zk-lib >= 0.10.0", + "? BetterCommands", + "(?) gvv" + ] } diff --git a/models/BetterCommands/README.md b/models/BetterCommands/README.md deleted file mode 100644 index 48b5f6a..0000000 --- a/models/BetterCommands/README.md +++ /dev/null @@ -1,19 +0,0 @@ -This modified module from [Custom commands template](mods.factorio.com/mod/cc-template) to simplify filtering of commands and gives ability to turn on/off commands via map settings. - -And this module requires "[zk-lib](https://github.com/ZwerOxotnik/zk-lib)" mod for localization only. You can remove the dependency and put your own locales. - -.\ -├── [const-commands.lua](../../const-commands.lua) <- contains data for constant commands\ -├── [switchable-commands.lua](../../switchable-commands.lua) <- contains data for switchable commands\ -└── [settings.lua](../../settings.lua) <- creates new settings to give ability to turn on/off commands via map settings.\ - -[models/command-wrapper/control.lua](/control) <- contains logic for interaction with other modules on control and data stage. (**change commands there** and adapt scripts if you want) - -What it can do --------------- - -* Filter parameters of commands -* Add switchable commands via map settings -* Use built-in error handling of commands -* Double check of commands -* Has simple integration (4+ lines) diff --git a/models/BetterCommands/control.lua b/models/BetterCommands/control.lua deleted file mode 100644 index 07748a8..0000000 --- a/models/BetterCommands/control.lua +++ /dev/null @@ -1,279 +0,0 @@ --- Source: https://github.com/ZwerOxotnik/factorio-example-mod ---TODO: fix localization, handle settings on events more accurately - - ----@class BetterCommands : module -local M = {} - ----@type table -local all_commands = {} -- commands from other modules - -local MAX_INPUT_LENGTH = 500 -- set any number -local CONST_COMMANDS = require(MOD_PATH .. "/const-commands") -local SWITCHABLE_COMMANDS = require(MOD_PATH .. "/switchable-commands") - - ----@param s string -local function trim(s) - return s:match'^%s*(.*%S)' or '' -end - ----@return boolean -local function remove_command(command_name) - if commands.remove_command(MOD_SHORT_NAME .. command_name) then - return true - else - return commands.remove_command(command_name) - end -end - ----@param message string ----@param player_index? number --- Sends message to a player or server -local function print_to_caller(message, player_index) - if not (game and player_index) then - print(message) -- this message for server - else - local player = game.get_player(player_index) - if player and player.valid then - player.print(message) - end - end -end - - ----@param error_message string ----@param player_index? number ----@param orig_command_name string -local function disable_setting(error_message, player_index, orig_command_name) - print_to_caller(error_message, player_index) - - local is_message_sended = false - if game then - for _, player in pairs(game.connected_players) do - if player.valid and player.admin then - player.print(error_message) - is_message_sended = true - end - end - end - if is_message_sended == false then - log(error_message) - end - - -- Turns off the command - if orig_command_name then - local setting_name = MOD_SHORT_NAME .. orig_command_name - if settings.global[setting_name] then - settings.global[setting_name] = { - value = false - } - end - end -end - -local player_input_type = 1 -local team_input_type = 2 -local input_types = { - player = player_input_type, - team = team_input_type -} - ----@param command_settings table ----@param original_func function ----@return boolean -local function add_custom_command(orig_command_name, command_settings, original_func) - local input_type = input_types[command_settings.input_type] - local is_allowed_empty_args = command_settings.is_allowed_empty_args - local command_name = command_settings.name - if commands.commands[command_name] then - command_name = MOD_SHORT_NAME .. command_name - if commands.commands[command_name] then - return false - end - end - - local command_description = command_settings.description or {MOD_NAME .. "-commands." .. command_settings.name} - commands.add_command(command_name, command_description, function(cmd) - if cmd.player_index == 0 then - if command_settings.allow_for_server == false then - print({"prohibited-server-command"}) - return - end - else - local caller = game.get_player(cmd.player_index) - if not (caller and caller.valid) then return end - if command_settings.only_for_admin and caller.admin == false then - caller.print({"command-output.parameters-require-admin"}) - return - end - end - - if cmd.parameter == nil then - if is_allowed_empty_args == false then - print_to_caller({"", '/' .. command_name .. ' ', command_description}, cmd.player_index) - return - end - elseif #cmd.parameter > MAX_INPUT_LENGTH then - print_to_caller({"", {"description.maximum-length", '=', MAX_INPUT_LENGTH}}, cmd.player_index) - return - end - - if cmd.parameter and input_type then - if input_type == player_input_type then - if #cmd.parameter > 32 then - print_to_caller({"gui-auth-server.username-too-long"}, cmd.player_index) - return - else - cmd.parameter = trim(cmd.parameter) - local player = game.get_player(cmd.parameter) - if not (player and player.valid) then - print_to_caller({"player-doesnt-exist", cmd.parameter}, cmd.player_index) - return - end - end - elseif input_type == team_input_type then - if #cmd.parameter > 52 then - print_to_caller({"too-long-team-name"}, cmd.player_index) - return - else - cmd.parameter = trim(cmd.parameter) - local force = game.forces[cmd.parameter] - if not (force and force.valid) then - print_to_caller({"force-doesnt-exist", cmd.parameter}, cmd.player_index) - return - end - end - end - end - - -- error handling - local is_ok, error_message = pcall(original_func, cmd) - if is_ok then - return - else - disable_setting(error_message, cmd.player_index, orig_command_name) - end - end) - - return true -end - ----Handles commands of a module ----@param module module your module with commands -function M:handle_custom_commands(module) - if module == nil then - log("Parameter is nil") - return false - end - if type(module.commands) ~= "table" then - log("Current module doesn't have proper commands") - return false - end - - for _, added_commands in pairs(all_commands) do - if added_commands == module.commands then - log("Current commands was added before") - return true - end - end - table.insert(all_commands, module.commands) - - for command_name, func in pairs(module.commands) do - local command_settings = SWITCHABLE_COMMANDS[command_name] or CONST_COMMANDS[command_name] or {} - command_settings.name = command_settings.name or command_name - local setting = nil - if SWITCHABLE_COMMANDS[command_name] then - setting = settings.global[MOD_SHORT_NAME .. command_name] - end - - if setting == nil then - local is_added = add_custom_command(command_name, command_settings, func) - if is_added == false then - log(script.mod_name .. " can't add command \"" .. command_settings.name .. "\"") - end - elseif setting.value then - local is_added = add_custom_command(command_name, command_settings, func) - if is_added == false then - local message = script.mod_name .. " can't add command \"" .. command_settings.name .. "\"" - disable_setting(message, nil, command_name) - end - else - remove_command(command_settings.name) - end - end - - return true -end - ----@param command_name string original command name ----@return function -local function find_func_by_command_name(command_name) - for _, some_commands in pairs(all_commands) do - local func = some_commands[command_name] - if func then - return func - end - end -end - ----@return boolean -local function on_runtime_mod_setting_changed(event) - if event.setting_type ~= "runtime-global" then return end - local setting_name = event.setting - if string.find(setting_name, '^' .. MOD_SHORT_NAME) ~= 1 then return end - - local command_name = string.gsub(setting_name, '^' .. MOD_SHORT_NAME, "") - local func = find_func_by_command_name(command_name) -- WARNING: check this throughly! - if func == nil then - log("Didn't find '" .. command_name .. "' among commands in modules") - end - local command_settings = SWITCHABLE_COMMANDS[command_name] or {} - local state = settings.global[setting_name].value - command_settings.name = command_settings.name or command_name - if state == true then - local is_added = add_custom_command(command_name, command_settings, func) - if is_added then - game.print("Added command: " .. command_settings.name or command_name) - else - local message = script.mod_name .. " can't add command \"" .. command_settings.name .. "\"" - disable_setting(message, nil, command_name) - end - else - remove_command(command_settings.name or command_name) - game.print("Removed command: " .. command_settings.name or command_name) - end - - return true -end - - ---- Adds settings for commands, so we can disable commands by settings ---- Use it during setting stage -function M:create_settings() - local new_settings = {} - for key, command in pairs(SWITCHABLE_COMMANDS) do - local command_name = command.name or key - local description = command.description or {MOD_NAME .. "-commands." .. command_name} - command_name = '/' .. command_name - new_settings[#new_settings + 1] = { - type = "bool-setting", - name = MOD_SHORT_NAME .. key, - setting_type = "runtime-global", - default_value = command.default_value or true, - localised_name = command_name, - localised_description = {'', command_name, ' ', description} - } - end - if #new_settings > 0 then - data:extend(new_settings) - end -end - - -M.events = { - [defines.events.on_runtime_mod_setting_changed] = on_runtime_mod_setting_changed -} - - -return M diff --git a/models/data-consistency-example.lua b/models/data-consistency-example.lua index ec990bd..ccfd972 100644 --- a/models/data-consistency-example.lua +++ b/models/data-consistency-example.lua @@ -1,5 +1,5 @@ --[[ - This is just a particular example, not a guide. You don't have to follow this example forever! + This is just a particular example, not a guide. You don't have to follow this example at all! We gonna use https://lua-api.factorio.com/latest/Global.html to store data and some local table for singleplayer in some cases. @@ -22,14 +22,15 @@ local M = {} --#region Singleplayer data -- Usually, some tables here (it's like a mirror of global data for singleplayer) -local sp_player_data = {} +local __sp_player_data = {} --#endregion --#region Global data -local players_data +local _players_data --#endregion + --#region Functions of events local function on_player_joined_game(event) @@ -39,12 +40,12 @@ local function on_player_joined_game(event) -- Trying to simulate "loaded" game without this mod (otherwise I have to tell you about other cases) if game.is_multiplayer() then - players_data[player_index] = {} + _players_data[player_index] = {} end end local function delete_player_data(event) - players_data[event.player_index] = nil + _players_data[event.player_index] = nil end local function on_cancelled_deconstruction(event) @@ -52,13 +53,13 @@ local function on_cancelled_deconstruction(event) local player = game.get_player(player_index) if not (player and player.valid) then return end - local data = players_data[player_index] or sp_player_data + local data = _players_data[player_index] or __sp_player_data -- You might get rid of second variable but, sometimes, it'll lead to more complex code or less performance data[#data] = math.random(100) -- it's safe to generate random numbers in multiplayer player.print("Data: " .. serpent.line(data)) -- Let's check the result - if players_data[player_index] == nil then + if _players_data[player_index] == nil then player.print("Nothing in global data for player, using \"singleplayer\" data") else player.print("Using global to store the data") @@ -72,7 +73,7 @@ end -- You might get rid of this, but it's convenient to have and use local function link_data() - players_data = global.players + _players_data = global.players end local function update_global_data() diff --git a/models/empty-module.lua b/models/empty-module.lua index 667f8c8..b7ac2dc 100644 --- a/models/empty-module.lua +++ b/models/empty-module.lua @@ -4,7 +4,7 @@ local M = {} --#region Global data ---local players_data +--local _players_data --#endregion @@ -25,7 +25,7 @@ end --#region Pre-game stage local function link_data() - --players_data = global.players + --_players_data = global.players end local function update_global_data() diff --git a/models/example-module.lua b/models/example-module.lua index 41aa563..7e42f7e 100644 --- a/models/example-module.lua +++ b/models/example-module.lua @@ -9,7 +9,7 @@ local custom_events = { } --#region Global data -local players_data +local _players_data --#endregion @@ -95,7 +95,7 @@ remote.add_interface("example-mod", interface) local function link_data() - players_data = global.players + _players_data = global.players end local function update_global_data() diff --git a/scenarios/example/control.lua b/scenarios/example/control.lua index b04571c..adcd5ad 100644 --- a/scenarios/example/control.lua +++ b/scenarios/example/control.lua @@ -1,14 +1,24 @@ - +MAKE_DEFINE_GLOBAL = true require("__example-mod__/defines") -- It's possible to get lua files from other mods local event_handler = require("event_handler") ---@type table local modules = {} -modules.better_commands = require(MOD_PATH .. "/models/BetterCommands/control") modules.example_module = require("models/example-module") modules.stop_example_mod = require("models/stop-example-mod") -modules.better_commands:handle_custom_commands(modules.example_module) -- adds commands +--- Adds https://github.com/ZwerOxotnik/factorio-BetterCommands if exists +if script.active_mods["BetterCommands"] then + local is_ok, better_commands = pcall(require, "__BetterCommands__/BetterCommands/control") + if is_ok then + better_commands.COMMAND_PREFIX = MOD_SHORT_NAME + modules.better_commands = better_commands + if better_commands.handle_custom_commands then + better_commands.handle_custom_commands(modules.example_module) -- adds commands + end + end +end + event_handler.add_libraries(modules) diff --git a/scenarios/example/info.json b/scenarios/example/info.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/scenarios/example/info.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/scenarios/example/models/example-module.lua b/scenarios/example/models/example-module.lua index dcb0ef2..7e77d30 100644 --- a/scenarios/example/models/example-module.lua +++ b/scenarios/example/models/example-module.lua @@ -4,7 +4,7 @@ local M = {} --#region Global data -local players_data +local _players_data --#endregion @@ -85,7 +85,7 @@ end --#region Pre-game stage local function link_data() - players_data = global.players + _players_data = global.players end local function update_global_data() diff --git a/settings.lua b/settings.lua index a8de278..c04eaab 100644 --- a/settings.lua +++ b/settings.lua @@ -1,7 +1,16 @@ -- See https://wiki.factorio.com/Tutorial:Mod_settings#Reading_settings require("defines") -require("models/BetterCommands/control"):create_settings() -- Adds switchable commands + + +--- Adds settings for commands +if mods["BetterCommands"] then + local is_ok, better_commands = pcall(require, "__BetterCommands__/BetterCommands/control") + if is_ok then + better_commands.COMMAND_PREFIX = MOD_SHORT_NAME + better_commands.create_settings(MOD_PATH, MOD_SHORT_NAME) -- Adds switchable commands + end +end -- Just an example diff --git a/snippets.lua b/snippets.lua deleted file mode 100644 index aa16d98..0000000 --- a/snippets.lua +++ /dev/null @@ -1,39 +0,0 @@ ----- Safe teleportation for players -local surface = game.get_surface(1) -local target_position = {0, 0} -for _, player in pairs(game.players) do - if player.valid then - local character = player.character - if not (character and character.valid) then - player.teleport(target_position, surface) - else - local target - local is_vehicle = false - local vehicle = player.vehicle - local target_name - if vehicle and not vehicle.train and vehicle.get_driver() == character and vehicle.get_passenger() == nil then - target = vehicle - target_name = vehicle.name - is_vehicle = true - else - target = player - target_name = character.name - end - local radius = 200 - local non_colliding_position = surface.find_non_colliding_position(target_name, target_position, radius, 1) - - if non_colliding_position then - if is_vehicle then - if vehicle.type == "spider-vehicle" then - target.stop_spider() - else - target.speed = 0 - end - end - target.teleport(non_colliding_position, surface) - else - player.print("It's not possible to teleport you because there's not enough space for your character") - end - end - end -end diff --git a/switchable-commands.lua b/switchable-commands.lua index 6ab9a21..8944789 100644 --- a/switchable-commands.lua +++ b/switchable-commands.lua @@ -1,20 +1,30 @@ --- Recommended to know about https://lua-api.factorio.com/latest/LuaCommandProcessor.html#LuaCommandProcessor.add_command - ---[[ +--[[ Uses https://github.com/ZwerOxotnik/factorio-BetterCommands Returns tables of commands without functions as command "settings". All parameters are optional! - Contains: - name :: string: The name of your /command. (default: key of the table) - description :: string or LocalisedString: The description of your command. (default: nil) - is_allowed_empty_args :: boolean: Ignores empty parameters in commands, otherwise stops the command. (default: true) - input_type :: string: filter for parameters by type of input. (default: nil) - possible variants: - "player" - Stops execution if can't find a player by parameter - "team" - Stops execution if can't find a team (force) by parameter - allow_for_server :: boolean: Allow execution of a command from a server (default: false) - only_for_admin :: boolean: The command can be executed only by admins (default: false) - default_value :: boolean: default value for settings (default: true) + Contains: + name :: string: The name of your /command. (default: key of the table) + description :: string or LocalisedString: The description of your command. (default: nil) + is_allowed_empty_args :: boolean: Ignores empty parameters in commands, otherwise stops the command. (default: true) + input_type :: string: Filter for parameters by type of input. (default: nil) + possible variants: + "player" - Stops execution if can't find a player by parameter + "team" - Stops execution if can't find a team (force) by parameter + allow_for_server :: boolean: Allow execution of a command from a server (default: false) + only_for_admin :: boolean: The command can be executed only by admins (default: false) + is_added_by_default :: boolean: Default value for switchable commands (default: true) + allow_for_players :: string[]: Allows to use the command for players with specified names (default: nil) + max_input_length :: uint: Max amount of characters for command (default: 500) + is_logged :: boolean: Logs the command into .log file (default: false) + alternative_names :: string[]: Alternative names for the command (all commands should be added) (default: nil) + is_one_time_use :: boolean: Disables the command after using it (default: false) + is_one_time_use_for_player :: boolean: Disables for a player after using it (default: false) + is_one_time_use_for_force :: boolean: Disables for a force after using it (default: false) + global_cooldown :: uint: The command can be used each N seconds (default: nil) + player_cooldown :: uint: The command can be used each N seconds for players (default: nil) + force_cooldown :: uint: The command can be used each N seconds for forces (default: nil) + disable_cooldown_for_admins :: boolean: Disables cooldown for admins (default: false) + disable_cooldown_for_server :: boolean: Disables cooldown for server (default: true) ]]-- ----@type table +---@type table return { delete_example_UI = {name = "delete-example-UI"}, -- See models/example-module.lua }