mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Move files to exp_legacy
This commit is contained in:
27
exp_legacy/module/modules/commands/admin-chat.lua
Normal file
27
exp_legacy/module/modules/commands/admin-chat.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
--[[-- Commands Module - Admin Chat
|
||||
- Adds a command that allows admins to talk in a private chat
|
||||
@commands Admin-Chat
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
--- Sends a message in chat that only admins can see
|
||||
-- @command admin-chat
|
||||
-- @tparam string message the message to send in the admin chat
|
||||
Commands.new_command('admin-chat', {'expcom-admin-chat.description'}, 'Sends a message in chat that only admins can see.')
|
||||
:add_param('message', false)
|
||||
:enable_auto_concat()
|
||||
:set_flag('admin_only')
|
||||
:add_alias('ac')
|
||||
:register(function(player, message)
|
||||
local player_name_colour = format_chat_player_name(player)
|
||||
|
||||
for _, return_player in pairs(game.connected_players) do
|
||||
if return_player.admin then
|
||||
return_player.print{'expcom-admin-chat.format', player_name_colour, message}
|
||||
end
|
||||
end
|
||||
return Commands.success -- prevents command complete message from showing
|
||||
end)
|
||||
88
exp_legacy/module/modules/commands/admin-markers.lua
Normal file
88
exp_legacy/module/modules/commands/admin-markers.lua
Normal file
@@ -0,0 +1,88 @@
|
||||
--[[-- Commands Module - Admin Markers
|
||||
- Adds a command that creates map markers which can only be edited by admins
|
||||
@commands Admin-Markers
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
|
||||
local admins = {} -- Stores all players in admin marker mode
|
||||
local markers = {} -- Stores all admin markers
|
||||
|
||||
--- Global variables
|
||||
Global.register({
|
||||
admins = admins,
|
||||
markers = markers
|
||||
}, function(tbl)
|
||||
admins = tbl.admins
|
||||
markers = tbl.markers
|
||||
end)
|
||||
|
||||
--- Toggle admin marker mode, can only be applied to yourself
|
||||
-- @command admin-marker
|
||||
Commands.new_command('admin-marker', {'expcom-admin-marker.description'}, 'Toggles admin marker mode, new markers can only be edited by admins')
|
||||
:set_flag('admin_only')
|
||||
:add_alias('am', 'admin-markers')
|
||||
:register(function(player)
|
||||
if admins[player.name] then
|
||||
-- Exit admin mode
|
||||
admins[player.name] = nil
|
||||
return Commands.success{'expcom-admin-marker.exit'}
|
||||
else
|
||||
-- Enter admin mode
|
||||
admins[player.name] = true
|
||||
return Commands.success{'expcom-admin-marker.enter'}
|
||||
end
|
||||
end)
|
||||
|
||||
--- Listen for new map markers being added, add admin marker if done by player in admin mode
|
||||
Event.add(defines.events.on_chart_tag_added, function(event)
|
||||
if not event.player_index then return end
|
||||
local player = game.get_player(event.player_index)
|
||||
if not admins[player.name] then return end
|
||||
local tag = event.tag
|
||||
markers[tag.force.name..tag.tag_number] = true
|
||||
Commands.print({'expcom-admin-marker.place'}, nil, player)
|
||||
end)
|
||||
|
||||
--- Listen for players leaving the game, leave admin mode to avoid unexpected admin markers
|
||||
Event.add(defines.events.on_player_left_game, function(event)
|
||||
if not event.player_index then return end
|
||||
local player = game.get_player(event.player_index)
|
||||
admins[player.name] = nil
|
||||
end)
|
||||
|
||||
--- Listen for tags being removed or edited, maintain tags edited by non admins
|
||||
local function maintain_tag(event)
|
||||
local tag = event.tag
|
||||
if not event.player_index then return end
|
||||
if not markers[tag.force.name..tag.tag_number] then return end
|
||||
local player = game.get_player(event.player_index)
|
||||
if player.admin then
|
||||
-- Player is admin, tell them it was an admin marker
|
||||
Commands.print({'expcom-admin-marker.edit'}, nil, player)
|
||||
elseif event.name == defines.events.on_chart_tag_modified then
|
||||
-- Tag was modified, revert the changes
|
||||
tag.text = event.old_text
|
||||
tag.last_user = event.old_player
|
||||
if event.old_icon then tag.icon = event.old_icon end
|
||||
player.play_sound{path='utility/wire_pickup'}
|
||||
Commands.print({'expcom-admin-marker.revert'}, nil, player)
|
||||
else
|
||||
-- Tag was removed, remake the tag
|
||||
player.play_sound{path='utility/wire_pickup'}
|
||||
Commands.print({'expcom-admin-marker.revert'}, 'orange_red', player)
|
||||
local new_tag = tag.force.add_chart_tag(tag.surface, {
|
||||
last_user = tag.last_user,
|
||||
position = tag.position,
|
||||
icon = tag.icon,
|
||||
text = tag.text,
|
||||
})
|
||||
markers[tag.force.name..tag.tag_number] = nil
|
||||
markers[new_tag.force.name..new_tag.tag_number] = true
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_chart_tag_modified, maintain_tag)
|
||||
Event.add(defines.events.on_chart_tag_removed, maintain_tag)
|
||||
84
exp_legacy/module/modules/commands/artillery.lua
Normal file
84
exp_legacy/module/modules/commands/artillery.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
--[[-- Commands Module - Artillery
|
||||
- Adds a command that help shot artillery
|
||||
@commands Artillery
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
local Selection = require 'modules.control.selection' --- @dep modules.control.selection
|
||||
local SelectionArtyArea = 'ArtyArea'
|
||||
|
||||
local function location_break(player, pos)
|
||||
if player.force.is_chunk_charted(player.surface, {x=math.floor(pos.left_top.x / 32), y=math.floor(pos.left_top.y / 32)}) then
|
||||
return true
|
||||
|
||||
elseif player.force.is_chunk_charted(player.surface, {x=math.floor(pos.left_top.x / 32), y=math.floor(pos.right_bottom.y / 32)}) then
|
||||
return true
|
||||
|
||||
elseif player.force.is_chunk_charted(player.surface, {x=math.floor(pos.right_bottom.x / 32), y=math.floor(pos.left_top.y / 32)}) then
|
||||
return true
|
||||
|
||||
elseif player.force.is_chunk_charted(player.surface, {x=math.floor(pos.right_bottom.x / 32), y=math.floor(pos.right_bottom.y / 32)}) then
|
||||
return true
|
||||
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- align an aabb to the grid by expanding it
|
||||
local function aabb_align_expand(aabb)
|
||||
return {
|
||||
left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)},
|
||||
right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)}
|
||||
}
|
||||
end
|
||||
|
||||
--- when an area is selected to add protection to the area
|
||||
Selection.on_selection(SelectionArtyArea, function(event)
|
||||
local area = aabb_align_expand(event.area)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if player == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if not (game.players[event.player_index].cheat_mode or location_break(player, event.area)) then
|
||||
return Commands.error
|
||||
end
|
||||
|
||||
local count = 0
|
||||
local hit = {}
|
||||
|
||||
for _, e in pairs(player.surface.find_entities_filtered({area=area, type={'unit-spawner', 'turret'}, force='enemy'})) do
|
||||
local skip = false
|
||||
|
||||
for _, pos in ipairs(hit) do
|
||||
if math.sqrt(math.abs(e.position.x - pos.x) ^ 2 + math.abs(e.position.y - pos.y) ^ 2) < 6 then
|
||||
skip = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not skip then
|
||||
player.surface.create_entity{name='artillery-flare', position=e.position, force=player.force, life_time=240, movement={0, 0}, height=0, vertical_speed=0, frame_speed=0}
|
||||
table.insert(hit, e.position)
|
||||
count = count + 1
|
||||
|
||||
if count > 400 then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.new_command('artillery-target-remote', {'expcom-artillery.description'}, 'Artillery Target Remote')
|
||||
:register(function(player)
|
||||
if Selection.is_selecting(player, SelectionArtyArea) then
|
||||
Selection.stop(player)
|
||||
else
|
||||
Selection.start(player, SelectionArtyArea)
|
||||
end
|
||||
|
||||
return Commands.success
|
||||
end)
|
||||
25
exp_legacy/module/modules/commands/bot-queue.lua
Normal file
25
exp_legacy/module/modules/commands/bot-queue.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
--[[-- Commands Module - Bot queue
|
||||
- Adds a command that allows changing bot queue
|
||||
@commands Bot Queue
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('bot-queue-get', {'expcom-bot-queue.description-get'}, 'Get bot queue')
|
||||
:set_flag('admin_only')
|
||||
:register(function(player)
|
||||
local s = player.force.max_successful_attempts_per_tick_per_construction_queue
|
||||
local f = player.force.max_failed_attempts_per_tick_per_construction_queue
|
||||
return Commands.success{'expcom-bot-queue.result', player.name, s, f}
|
||||
end)
|
||||
|
||||
Commands.new_command('bot-queue-set', {'expcom-bot-queue.description-set'}, 'Set bot queue')
|
||||
:add_param('amount', 'integer-range', 1, 20)
|
||||
:set_flag('admin_only')
|
||||
:register(function(player, amount)
|
||||
player.force.max_successful_attempts_per_tick_per_construction_queue = 3 * amount
|
||||
player.force.max_failed_attempts_per_tick_per_construction_queue = 1 * amount
|
||||
game.print{'expcom-bot-queue.result', player.name, 3 * amount, 1 * amount}
|
||||
return Commands.success
|
||||
end)
|
||||
45
exp_legacy/module/modules/commands/cheat-mode.lua
Normal file
45
exp_legacy/module/modules/commands/cheat-mode.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
--[[-- Commands Module - Cheat Mode
|
||||
- Adds a command that allows players to enter cheat mode
|
||||
@commands Cheat-Mode
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
--- Toggles cheat mode for your player, or another player.
|
||||
-- @command toggle-cheat-mode
|
||||
-- @tparam[opt=self] LuaPlayer player player to toggle chest mode of, can be nil for self
|
||||
Commands.new_command('toggle-cheat-mode', {'expcom-cheat.description-cheat'}, 'Toggles cheat mode for your player, or another player.')
|
||||
:add_param('player', true, 'player')
|
||||
:set_defaults{player=function(player)
|
||||
return player -- default is the user using the command
|
||||
end}
|
||||
:set_flag('admin_only')
|
||||
:register(function(_, player)
|
||||
player.cheat_mode = not player.cheat_mode
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Commands.new_command('research-all', {'expcom-cheat.description-res'}, 'Set all research for your force.')
|
||||
:set_flag('admin_only')
|
||||
:add_param('force', true, 'force')
|
||||
:set_defaults{force=function(player)
|
||||
return player.force
|
||||
end}
|
||||
:register(function(player, force)
|
||||
force.research_all_technologies()
|
||||
game.print{'expcom-cheat.res', player.name}
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Commands.new_command('toggle-always-day', {'expcom-cheat.description-day'}, 'Toggles always day in surface.')
|
||||
:set_flag('admin_only')
|
||||
:add_param('surface', true, 'surface')
|
||||
:set_defaults{surface=function(player)
|
||||
return player.surface
|
||||
end}
|
||||
:register(function(player, surface)
|
||||
surface.always_day = not surface.always_day
|
||||
game.print{'expcom-cheat.day', player.name, surface.always_day}
|
||||
return Commands.success
|
||||
end)
|
||||
23
exp_legacy/module/modules/commands/clear-inventory.lua
Normal file
23
exp_legacy/module/modules/commands/clear-inventory.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
--[[-- Commands Module - Clear Inventory
|
||||
- Adds a command that allows admins to clear people's inventorys
|
||||
@commands Clear-Inventory
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local move_items_stack = _C.move_items_stack --- @dep expcore.common
|
||||
require 'config.expcore.command_role_parse'
|
||||
|
||||
--- Clears a players inventory
|
||||
-- @command clear-inventory
|
||||
-- @tparam LuaPlayer player the player to clear the inventory of
|
||||
Commands.new_command('clear-inventory', {'expcom-clr-inv.description'}, 'Clears a players inventory')
|
||||
:add_param('player', false, 'player-role')
|
||||
:add_alias('clear-inv', 'move-inventory', 'move-inv')
|
||||
:register(function(_, player)
|
||||
local inv = player.get_main_inventory()
|
||||
if not inv then
|
||||
return Commands.error{'expcore-commands.reject-player-alive'}
|
||||
end
|
||||
move_items_stack(inv)
|
||||
inv.clear()
|
||||
end)
|
||||
107
exp_legacy/module/modules/commands/connect.lua
Normal file
107
exp_legacy/module/modules/commands/connect.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
--[[-- Commands Module - Connect
|
||||
- Adds a commands that allows you to request a player move to another server
|
||||
@commands Connect
|
||||
]]
|
||||
|
||||
local Async = require 'expcore.async' --- @dep expcore.async
|
||||
local External = require 'expcore.external' --- @dep expcore.external
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_role_parse'
|
||||
local concat = table.concat
|
||||
|
||||
local request_connection = Async.register(External.request_connection)
|
||||
|
||||
local function get_server_id(server)
|
||||
local current_server = External.get_current_server()
|
||||
local current_version = current_server.version
|
||||
local servers = External.get_servers_filtered(server)
|
||||
|
||||
local server_names_before, server_names = {}, {}
|
||||
local server_count_before, server_count = 0, 0
|
||||
for next_server_id, server_details in pairs(servers) do
|
||||
server_count_before = server_count_before + 1
|
||||
server_names_before[server_count_before] = server_details.name
|
||||
if server_details.version == current_version then
|
||||
server_count = server_count + 1
|
||||
server_names[server_count] = server_details.name
|
||||
else
|
||||
servers[next_server_id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
if server_count > 1 then
|
||||
return false, Commands.error{'expcom-connect.too-many-matching', concat(server_names, ', ')}
|
||||
elseif server_count == 1 then
|
||||
local server_id, server_details = next(servers)
|
||||
local status = External.get_server_status(server_id)
|
||||
if server_id == current_server.id then
|
||||
return false, Commands.error{'expcom-connect.same-server', server_details.name}
|
||||
elseif status == 'Offline' then
|
||||
return false, Commands.error{'expcom-connect.offline', server_details.name}
|
||||
end
|
||||
return true, server_id
|
||||
elseif server_count_before > 0 then
|
||||
return false, Commands.error{'expcom-connect.wrong-version', concat(server_names_before, ', ')}
|
||||
else
|
||||
return false, Commands.error{'expcom-connect.none-matching'}
|
||||
end
|
||||
end
|
||||
|
||||
--- Connect to a different server
|
||||
-- @command connect
|
||||
-- @tparam string server The address or name of the server to connect to
|
||||
-- @tparam[opt=false] boolean is_address If an address was given for the server param
|
||||
Commands.new_command('connect', {'expcom-connect.description'}, 'Connect to another server')
|
||||
:add_param('server')
|
||||
:add_param('is_address', true, 'boolean')
|
||||
:add_alias('join', 'server')
|
||||
:register(function(player, server, is_address)
|
||||
local server_id = server
|
||||
if not is_address and External.valid() then
|
||||
local success, new_server_id = get_server_id(server)
|
||||
if not success then return new_server_id end
|
||||
server_id = new_server_id
|
||||
end
|
||||
|
||||
Async(request_connection, player, server_id, true)
|
||||
end)
|
||||
|
||||
--- Connect a player to a different server
|
||||
-- @command connect-player
|
||||
-- @tparam string address The address or name of the server to connect to
|
||||
-- @tparam LuaPlayer player The player to connect to a different server
|
||||
-- @tparam[opt=false] boolean is_address If an address was given for the server param
|
||||
Commands.new_command('connect-player', {'expcom-connect.description-player'}, 'Send a player to a different server')
|
||||
:add_param('player', 'player-role')
|
||||
:add_param('server')
|
||||
:add_param('is_address', true, 'boolean')
|
||||
:register(function(_, player, server, is_address)
|
||||
local server_id = server
|
||||
if not is_address and External.valid() then
|
||||
local success, new_server_id = get_server_id(server)
|
||||
if not success then return new_server_id end
|
||||
server_id = new_server_id
|
||||
end
|
||||
|
||||
External.request_connection(player, server_id)
|
||||
end)
|
||||
|
||||
--- Connect all players to a different server
|
||||
-- @command connect-all
|
||||
-- @tparam string address The address or name of the server to connect to
|
||||
-- @tparam[opt=false] boolean is_address If an address was given for the server param
|
||||
Commands.new_command('connect-all', {'expcom-connect.description-all'}, 'Connect all players to another server')
|
||||
:add_param('server')
|
||||
:add_param('is_address', true, 'boolean')
|
||||
:register(function(_, server, is_address)
|
||||
local server_id = server
|
||||
if not is_address and External.valid() then
|
||||
local success, new_server_id = get_server_id(server)
|
||||
if not success then return new_server_id end
|
||||
server_id = new_server_id
|
||||
end
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
External.request_connection(player, server_id)
|
||||
end
|
||||
end)
|
||||
14
exp_legacy/module/modules/commands/debug.lua
Normal file
14
exp_legacy/module/modules/commands/debug.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
--[[-- Commands Module - Debug
|
||||
- Adds a command that opens the debug frame
|
||||
@commands Debug
|
||||
]]
|
||||
|
||||
local DebugView = require 'modules.gui.debug.main_view' --- @dep modules.gui.debug.main_view
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
|
||||
--- Opens the debug pannel for viewing tables.
|
||||
-- @command debug
|
||||
Commands.new_command('debug', {'expcom-debug.description'}, 'Opens the debug pannel for viewing tables.')
|
||||
:register(function(player)
|
||||
DebugView.open_dubug(player)
|
||||
end)
|
||||
29
exp_legacy/module/modules/commands/enemy.lua
Normal file
29
exp_legacy/module/modules/commands/enemy.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
--[[-- Commands Module - Enemy
|
||||
- Adds a command of handling enemy
|
||||
@commands Enemy
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('kill-biters', {'expcom-enemy.description-kill'}, 'Kill all biters only')
|
||||
:set_flag('admin_only')
|
||||
:register(function(_, _)
|
||||
game.forces['enemy'].kill_all_units()
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Commands.new_command('remove-biters', {'expcom-enemy.description-remove'}, 'Remove biters and prevent generation')
|
||||
:set_flag('admin_only')
|
||||
:add_param('surface', true, 'surface')
|
||||
:set_defaults{surface=function(player)
|
||||
return player.surface
|
||||
end}
|
||||
:register(function(_, surface)
|
||||
for _, entity in pairs(surface.find_entities_filtered({force='enemy'})) do
|
||||
entity.destroy()
|
||||
end
|
||||
|
||||
surface.map_gen_settings.autoplace_controls['enemy-base'].size = 'none'
|
||||
return Commands.success
|
||||
end)
|
||||
19
exp_legacy/module/modules/commands/find.lua
Normal file
19
exp_legacy/module/modules/commands/find.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
--[[-- Commands Module - Find
|
||||
- Adds a command that zooms in on the given player
|
||||
@commands Find
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
--- Find a player on your map.
|
||||
-- @command find-on-map
|
||||
-- @tparam LuaPlayer the player to find on the map
|
||||
Commands.new_command('find-on-map', {'expcom-find.description'}, 'Find a player on your map.')
|
||||
:add_param('player', false, 'player-online')
|
||||
:add_alias('find', 'zoom-to')
|
||||
:register(function(player, action_player)
|
||||
local position = action_player.position
|
||||
player.zoom_to_world(position, 1.75)
|
||||
return Commands.success -- prevents command complete message from showing
|
||||
end)
|
||||
19
exp_legacy/module/modules/commands/friendly-fire.lua
Normal file
19
exp_legacy/module/modules/commands/friendly-fire.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
--[[-- Commands Module - Toggle Friendly Fire
|
||||
- Adds a command that toggle all friendly fire
|
||||
@commands Toggle Friendly Fire
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
-- For Modded Server Use
|
||||
Commands.new_command('toggle-friendly-fire', {'expcom-ff.description'}, 'Toggle friendly fire')
|
||||
:add_param('force', true, 'force')
|
||||
:set_defaults{force=function(player)
|
||||
return player.force
|
||||
end}
|
||||
:register(function(player, force)
|
||||
force.friendly_fire = not force.friendly_fire
|
||||
game.print{'expcom-ff.ff', player.name, force.friendly_fire}
|
||||
return Commands.success
|
||||
end)
|
||||
100
exp_legacy/module/modules/commands/help.lua
Normal file
100
exp_legacy/module/modules/commands/help.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
--[[-- Commands Module - Help
|
||||
- Adds a better help command that allows searching of descriotions and names
|
||||
@commands Help
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
local results_per_page = 5
|
||||
|
||||
local search_cache = {}
|
||||
Global.register(search_cache, function(tbl)
|
||||
search_cache = tbl
|
||||
end)
|
||||
|
||||
--- Searches for a keyword in all commands you are allowed to use.
|
||||
-- @command chelp
|
||||
-- @tparam string keyword the keyword that will be looked for
|
||||
-- @tparam number page the page of help to view, must be in range of pages
|
||||
Commands.new_command('search-help', {'expcom-chelp.description'}, 'Searches for a keyword in all commands you are allowed to use.')
|
||||
:add_alias('chelp', 'shelp', 'commands')
|
||||
:add_param('keyword', true)
|
||||
:add_param('page', true, 'integer')
|
||||
:set_defaults{keyword='', page=1}
|
||||
:register(function(player, keyword, page)
|
||||
local player_index = player and player.index or 0
|
||||
|
||||
-- if keyword is a number then treat it as page number
|
||||
if tonumber(keyword) then
|
||||
page = math.floor(tonumber(keyword))
|
||||
keyword = ''
|
||||
end
|
||||
|
||||
-- gets a value for pages, might have result in cache
|
||||
local pages
|
||||
local found = 0
|
||||
|
||||
if search_cache[player_index] and search_cache[player_index].keyword == keyword:lower() then
|
||||
pages = search_cache[player_index].pages
|
||||
found = search_cache[player_index].found
|
||||
|
||||
else
|
||||
pages = {{}}
|
||||
local current_page = 1
|
||||
local page_count = 0
|
||||
local commands = Commands.search(keyword, player)
|
||||
|
||||
-- loops other all commands returned by search, includes game commands
|
||||
for _, command_data in pairs(commands) do
|
||||
-- if the number of results if greater than the number already added then it moves onto a new page
|
||||
if page_count >= results_per_page then
|
||||
page_count = 0
|
||||
current_page = current_page + 1
|
||||
table.insert(pages, {})
|
||||
end
|
||||
|
||||
-- adds the new command to the page
|
||||
page_count = page_count + 1
|
||||
found = found + 1
|
||||
local alias_format = #command_data.aliases > 0 and {'expcom-chelp.alias', table.concat(command_data.aliases, ', ')} or ''
|
||||
table.insert(pages[current_page], {
|
||||
'expcom-chelp.format',
|
||||
command_data.name,
|
||||
command_data.description,
|
||||
command_data.help,
|
||||
alias_format
|
||||
})
|
||||
end
|
||||
|
||||
-- adds the result to the cache
|
||||
search_cache[player_index] = {
|
||||
keyword=keyword:lower(),
|
||||
pages=pages,
|
||||
found=found
|
||||
}
|
||||
end
|
||||
|
||||
-- print the requested page
|
||||
keyword = keyword == '' and '<all>' or keyword
|
||||
Commands.print({'expcom-chelp.title', keyword}, 'cyan')
|
||||
|
||||
if pages[page] then
|
||||
for _, command in pairs(pages[page]) do
|
||||
Commands.print(command)
|
||||
end
|
||||
|
||||
Commands.print({'expcom-chelp.footer', found, page, #pages}, 'cyan')
|
||||
|
||||
else
|
||||
Commands.print({'expcom-chelp.footer', found, page, #pages}, 'cyan')
|
||||
return Commands.error{'expcom-chelp.out-of-range', page}
|
||||
end
|
||||
|
||||
-- blocks command complete message
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
-- way to access global
|
||||
return search_cache
|
||||
83
exp_legacy/module/modules/commands/home.lua
Normal file
83
exp_legacy/module/modules/commands/home.lua
Normal file
@@ -0,0 +1,83 @@
|
||||
--[[-- Commands Module - Home
|
||||
- Adds a command that allows setting and teleporting to your home position
|
||||
@commands Home
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
local homes = {}
|
||||
Global.register(homes, function(tbl)
|
||||
homes = tbl
|
||||
end)
|
||||
|
||||
local function teleport(player, position)
|
||||
local surface = player.surface
|
||||
local pos = surface.find_non_colliding_position('character', position, 32, 1)
|
||||
if not position then return false end
|
||||
if player.driving then player.driving = false end -- kicks a player out a vehicle if in one
|
||||
player.teleport(pos, surface)
|
||||
return true
|
||||
end
|
||||
|
||||
local function floor_pos(position)
|
||||
return {
|
||||
x=math.floor(position.x),
|
||||
y=math.floor(position.y)
|
||||
}
|
||||
end
|
||||
|
||||
--- Teleports you to your home location
|
||||
-- @command home
|
||||
Commands.new_command('home', {'expcom-home.description-home'}, 'Teleports you to your home location')
|
||||
:register(function(player)
|
||||
local home = homes[player.index]
|
||||
if not home or not home[1] then
|
||||
return Commands.error{'expcom-home.no-home'}
|
||||
end
|
||||
local rtn = floor_pos(player.position)
|
||||
teleport(player, home[1])
|
||||
home[2] = rtn
|
||||
Commands.print{'expcom-home.return-set', rtn.x, rtn.y}
|
||||
end)
|
||||
|
||||
--- Sets your home location to your current position
|
||||
-- @command home-set
|
||||
Commands.new_command('home-set', {'expcom-home.description-home-set'}, 'Sets your home location to your current position')
|
||||
:register(function(player)
|
||||
local home = homes[player.index]
|
||||
if not home then
|
||||
home = {}
|
||||
homes[player.index] = home
|
||||
end
|
||||
local pos = floor_pos(player.position)
|
||||
home[1] = pos
|
||||
Commands.print{'expcom-home.home-set', pos.x, pos.y}
|
||||
end)
|
||||
|
||||
--- Returns your current home location
|
||||
-- @command home-get
|
||||
Commands.new_command('home-get', {'expcom-home.description-home-get'}, 'Returns your current home location')
|
||||
:register(function(player)
|
||||
local home = homes[player.index]
|
||||
if not home or not home[1] then
|
||||
return Commands.error{'expcom-home.no-home'}
|
||||
end
|
||||
local pos = home[1]
|
||||
Commands.print{'expcom-home.home-get', pos.x, pos.y}
|
||||
end)
|
||||
|
||||
--- Teleports you to previous location
|
||||
-- @command return
|
||||
Commands.new_command('return', {'expcom-home.description-return'}, 'Teleports you to previous location')
|
||||
:register(function(player)
|
||||
local home = homes[player.index]
|
||||
if not home or not home[2] then
|
||||
return Commands.error{'expcom-home.no-return'}
|
||||
end
|
||||
local rtn = floor_pos(player.position)
|
||||
teleport(player, home[2])
|
||||
home[2] = rtn
|
||||
Commands.print{'expcom-home.return-set', rtn.x, rtn.y}
|
||||
end)
|
||||
116
exp_legacy/module/modules/commands/interface.lua
Normal file
116
exp_legacy/module/modules/commands/interface.lua
Normal file
@@ -0,0 +1,116 @@
|
||||
--[[-- Commands Module - Interface
|
||||
- Adds a command that acts as a direct link to the the active softmod, for debug use
|
||||
@commands Interface
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
|
||||
-- modules that are loaded into the interface env to be accessed
|
||||
local interface_modules = {
|
||||
['Commands'] = Commands,
|
||||
['output'] = _C.player_return,
|
||||
['Group'] = 'expcore.permission_groups',
|
||||
['Roles'] = 'expcore.roles',
|
||||
['Gui'] = 'expcore.gui',
|
||||
['Async'] = 'expcore.async',
|
||||
['Datastore'] = 'expcore.datastore',
|
||||
['External'] = 'expcore.external'
|
||||
}
|
||||
|
||||
-- loads all the modules given in the above table
|
||||
for key, value in pairs(interface_modules) do
|
||||
if type(value) == 'string' then
|
||||
interface_modules[key] = _C.opt_require(value)
|
||||
end
|
||||
end
|
||||
|
||||
local interface_env = {} -- used as a persistent sandbox for interface commands
|
||||
local interface_callbacks = {} -- saves callbacks which can load new values per use
|
||||
Global.register(interface_env, function(tbl)
|
||||
interface_env = tbl
|
||||
end)
|
||||
|
||||
--- Adds a static module that can be accessed with the interface
|
||||
-- @tparam string name The name that the value is assigned to
|
||||
-- @tparam any value The value that will be accessible in the interface env
|
||||
-- callback param - player: LuaPlayer - the player who used the command
|
||||
local function add_interface_module(name, value)
|
||||
interface_modules[name] = value
|
||||
end
|
||||
|
||||
--- Adds a dynamic value that is calculated when the interface is used
|
||||
-- @tparam string name The name that the value is assigned to
|
||||
-- @tparam function callback The function that will be called to get the value
|
||||
local function add_interface_callback(name, callback)
|
||||
if type(callback) == 'function' then
|
||||
interface_callbacks[name] = callback
|
||||
end
|
||||
end
|
||||
|
||||
--- Internal, this is a meta function for __index when self[key] is nil
|
||||
local function get_index(_, key)
|
||||
if interface_env[key] then
|
||||
return interface_env[key]
|
||||
elseif interface_modules[key] then
|
||||
return interface_modules[key]
|
||||
elseif _G[key] then
|
||||
return _G[key]
|
||||
end
|
||||
end
|
||||
|
||||
--- Sends an invocation to be ran and returns the result.
|
||||
-- @command interface
|
||||
-- @tparam string invocation the command that will be run
|
||||
Commands.new_command('interface', {'expcom-interface.description'}, 'Sends an invocation to be ran and returns the result.')
|
||||
:add_param('invocation', false)
|
||||
:enable_auto_concat()
|
||||
:set_flag('admin_only')
|
||||
:register(function(player, invocation)
|
||||
-- If the invocation has no white space then prepend return to it
|
||||
if not invocation:find('%s') and not invocation:find('return') then
|
||||
invocation = 'return '..invocation
|
||||
end
|
||||
|
||||
-- _env will be the new _ENV that the invocation will run inside of
|
||||
local _env = setmetatable({}, {
|
||||
__index = get_index,
|
||||
__newindex = interface_env
|
||||
})
|
||||
|
||||
-- If the command is ran by a player then load the dynamic values
|
||||
if player then
|
||||
for name, callback in pairs(interface_callbacks) do
|
||||
local _, rtn = pcall(callback, player)
|
||||
rawset(_env, name, rtn)
|
||||
end
|
||||
end
|
||||
|
||||
-- Compile the invocation with the custom _env value
|
||||
local invocation_func, compile_error = load(invocation, 'interface', nil, _env)
|
||||
if compile_error then return Commands.error(compile_error) end
|
||||
|
||||
-- Run the invocation
|
||||
local success, rtn = pcall(invocation_func)
|
||||
if not success then
|
||||
local err = rtn:gsub('%.%.%..-/temp/currently%-playing', '')
|
||||
return Commands.error(err)
|
||||
end
|
||||
return Commands.success(rtn)
|
||||
end)
|
||||
|
||||
-- Adds some basic callbacks for the interface
|
||||
add_interface_callback('player', function(player) return player end)
|
||||
add_interface_callback('surface', function(player) return player.surface end)
|
||||
add_interface_callback('force', function(player) return player.force end)
|
||||
add_interface_callback('position', function(player) return player.position end)
|
||||
add_interface_callback('entity', function(player) return player.selected end)
|
||||
add_interface_callback('tile', function(player) return player.surface.get_tile(player.position) end)
|
||||
|
||||
-- Module Return
|
||||
return {
|
||||
add_interface_module = add_interface_module,
|
||||
add_interface_callback = add_interface_callback,
|
||||
interface_env = interface_env,
|
||||
clean_stack_trace = function(str) return str:gsub('%.%.%..-/temp/currently%-playing', '') end
|
||||
}
|
||||
47
exp_legacy/module/modules/commands/jail.lua
Normal file
47
exp_legacy/module/modules/commands/jail.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
--[[-- Commands Module - Jail
|
||||
- Adds a commands that allow admins to jail and unjail
|
||||
@commands Jail
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Jail = require 'modules.control.jail' --- @dep modules.control.jail
|
||||
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common
|
||||
require 'config.expcore.command_role_parse'
|
||||
|
||||
--- Puts a player into jail and removes all other roles.
|
||||
-- @command jail
|
||||
-- @tparam LuaPlayer player the player that will be jailed
|
||||
-- @tparam[opt] string reason the reason why the player is being jailed
|
||||
Commands.new_command('jail', {'expcom-jail.description-jail'}, 'Puts a player into jail and removes all other roles.')
|
||||
:add_param('player', false, 'player-role')
|
||||
:add_param('reason', true)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, action_player, reason)
|
||||
reason = reason or 'Non Given.'
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
local by_player_name_color = format_chat_player_name(player)
|
||||
local player_name = player and player.name or '<server>'
|
||||
if Jail.jail_player(action_player, player_name, reason) then
|
||||
game.print{'expcom-jail.give', action_player_name_color, by_player_name_color, reason}
|
||||
else
|
||||
return Commands.error{'expcom-jail.already-jailed', action_player_name_color}
|
||||
end
|
||||
end)
|
||||
|
||||
--- Removes a player from jail.
|
||||
-- @command unjail
|
||||
-- @tparam LuaPlayer the player that will be unjailed
|
||||
Commands.new_command('unjail', {'expcom-jail.description-unjail'}, 'Removes a player from jail.')
|
||||
:add_param('player', false, 'player-role')
|
||||
:add_alias('clear-jail', 'remove-jail')
|
||||
:enable_auto_concat()
|
||||
:register(function(player, action_player)
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
local by_player_name_color = format_chat_player_name(player)
|
||||
local player_name = player and player.name or '<server>'
|
||||
if Jail.unjail_player(action_player, player_name) then
|
||||
game.print{'expcom-jail.remove', action_player_name_color, by_player_name_color}
|
||||
else
|
||||
return Commands.error{'expcom-jail.not-jailed', action_player_name_color}
|
||||
end
|
||||
end)
|
||||
36
exp_legacy/module/modules/commands/kill.lua
Normal file
36
exp_legacy/module/modules/commands/kill.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
--[[-- Commands Module - Kill
|
||||
- Adds a command that allows players to kill them selfs and others
|
||||
@commands Kill
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
require 'config.expcore.command_general_parse'
|
||||
require 'config.expcore.command_role_parse'
|
||||
|
||||
--- Kills yourself or another player.
|
||||
-- @command kill
|
||||
-- @tparam[opt=self] LuaPlayer player the player to kill, must be alive to be valid
|
||||
Commands.new_command('kill', {'expcom-kill.description'}, 'Kills yourself or another player.')
|
||||
:add_param('player', true, 'player-role-alive')
|
||||
:set_defaults{player=function(player)
|
||||
-- default is the player unless they are dead
|
||||
if player.character and player.character.health > 0 then
|
||||
return player
|
||||
end
|
||||
end}
|
||||
:register(function(player, action_player)
|
||||
if not action_player then
|
||||
-- can only be nil if no player given and the user is dead
|
||||
return Commands.error{'expcom-kill.already-dead'}
|
||||
end
|
||||
if player == action_player then
|
||||
action_player.character.die()
|
||||
|
||||
elseif Roles.player_allowed(player, 'command/kill/always') then
|
||||
action_player.character.die()
|
||||
|
||||
else
|
||||
return Commands.error{'expcore-commands.unauthorized'}
|
||||
end
|
||||
end)
|
||||
19
exp_legacy/module/modules/commands/last-location.lua
Normal file
19
exp_legacy/module/modules/commands/last-location.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
--[[-- Commands Module - Last location
|
||||
- Adds a command that will return the last location of a player
|
||||
@commands LastLocation
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
--- Get the last location of a player.
|
||||
-- @command last-location
|
||||
-- @tparam LuaPlayer player the player that you want a location of
|
||||
Commands.new_command('last-location', {'expcom-lastlocation.description'}, 'Sends you the last location of a player')
|
||||
:add_alias('location')
|
||||
:add_param('player', false, 'player')
|
||||
:register(function(_, action_player)
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
return Commands.success{'expcom-lastlocation.response', action_player_name_color, string.format('%.1f', action_player.position.x), string.format('%.1f', action_player.position.y)}
|
||||
end)
|
||||
17
exp_legacy/module/modules/commands/me.lua
Normal file
17
exp_legacy/module/modules/commands/me.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
--[[-- Commands Module - Me
|
||||
- Adds a command that adds * around your message in the chat
|
||||
@commands Me
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
|
||||
--- Sends an action message in the chat
|
||||
-- @command me
|
||||
-- @tparam string action the action that follows your name in chat
|
||||
Commands.new_command('me', {'expcom-me.description'}, 'Sends an action message in the chat')
|
||||
:add_param('action', false)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, action)
|
||||
local player_name = player and player.name or '<Server>'
|
||||
game.print(string.format('* %s %s *', player_name, action), player.chat_color)
|
||||
end)
|
||||
34
exp_legacy/module/modules/commands/pollution.lua
Normal file
34
exp_legacy/module/modules/commands/pollution.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
--[[-- Commands Module - Pollution Handle
|
||||
- Adds a command that allows modifying pollution
|
||||
@commands Pollution Handle
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('pollution-clear', {'expcom-pol.description-clr'}, 'Clear pollution')
|
||||
:set_flag('admin_only')
|
||||
:add_alias('pol-clr')
|
||||
:add_param('surface', true, 'surface')
|
||||
:set_defaults{surface=function(player)
|
||||
return player.surface
|
||||
end}
|
||||
:register(function(player, surface)
|
||||
surface.clear_pollution()
|
||||
game.print{'expcom-pol.clr', player.name}
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Commands.new_command('pollution-off', {'expcom-pol.description-off'}, 'Disable pollution')
|
||||
:set_flag('admin_only')
|
||||
:add_alias('pol-off')
|
||||
:register(function(player)
|
||||
game.map_settings.pollution.enabled = false
|
||||
|
||||
for _, v in pairs(game.surfaces) do
|
||||
v.clear_pollution()
|
||||
end
|
||||
|
||||
game.print{'expcom-pol.off', player.name}
|
||||
return Commands.success
|
||||
end)
|
||||
215
exp_legacy/module/modules/commands/protection.lua
Normal file
215
exp_legacy/module/modules/commands/protection.lua
Normal file
@@ -0,0 +1,215 @@
|
||||
--[[-- Commands Module - Protection
|
||||
- Adds commands that can add and remove protection
|
||||
@commands Protection
|
||||
]]
|
||||
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common
|
||||
local EntityProtection = require 'modules.control.protection' --- @dep modules.control.protection
|
||||
local Selection = require 'modules.control.selection' --- @dep modules.control.selection
|
||||
|
||||
local SelectionProtectEntity = 'ProtectEntity'
|
||||
local SelectionProtectArea = 'ProtectArea'
|
||||
|
||||
local renders = {} -- Stores all renders for a player
|
||||
Global.register({
|
||||
renders = renders
|
||||
}, function(tbl)
|
||||
renders = tbl.renders
|
||||
end)
|
||||
|
||||
--- Test if a point is inside an aabb
|
||||
local function aabb_point_enclosed(point, aabb)
|
||||
return point.x >= aabb.left_top.x and point.y >= aabb.left_top.y
|
||||
and point.x <= aabb.right_bottom.x and point.y <= aabb.right_bottom.y
|
||||
end
|
||||
|
||||
--- Test if an aabb is inside another aabb
|
||||
local function aabb_area_enclosed(aabbOne, aabbTwo)
|
||||
return aabb_point_enclosed(aabbOne.left_top, aabbTwo)
|
||||
and aabb_point_enclosed(aabbOne.right_bottom, aabbTwo)
|
||||
end
|
||||
|
||||
--- Align an aabb to the grid by expanding it
|
||||
local function aabb_align_expand(aabb)
|
||||
return {
|
||||
left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)},
|
||||
right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)}
|
||||
}
|
||||
end
|
||||
|
||||
--- Get the key used in protected_entities
|
||||
local function get_entity_key(entity)
|
||||
return string.format('%i,%i', math.floor(entity.position.x), math.floor(entity.position.y))
|
||||
end
|
||||
|
||||
--- Get the key used in protected_areas
|
||||
local function get_area_key(area)
|
||||
return string.format('%i,%i', math.floor(area.left_top.x), math.floor(area.left_top.y))
|
||||
end
|
||||
|
||||
--- Show a protected entity to a player
|
||||
local function show_protected_entity(player, entity)
|
||||
local key = get_entity_key(entity)
|
||||
if renders[player.index][key] then return end
|
||||
local rb = entity.selection_box.right_bottom
|
||||
local render_id = rendering.draw_sprite{
|
||||
sprite = 'utility/notification',
|
||||
target = entity,
|
||||
target_offset = {
|
||||
(rb.x-entity.position.x)*0.75,
|
||||
(rb.y-entity.position.y)*0.75
|
||||
},
|
||||
x_scale = 2,
|
||||
y_scale = 2,
|
||||
surface = entity.surface,
|
||||
players = { player }
|
||||
}
|
||||
renders[player.index][key] = render_id
|
||||
end
|
||||
|
||||
--- Show a protected area to a player
|
||||
local function show_protected_area(player, surface, area)
|
||||
local key = get_area_key(area)
|
||||
if renders[player.index][key] then return end
|
||||
local render_id = rendering.draw_rectangle{
|
||||
color = {1, 1, 0, 0.5},
|
||||
filled = false,
|
||||
width = 3,
|
||||
left_top = area.left_top,
|
||||
right_bottom = area.right_bottom,
|
||||
surface = surface,
|
||||
players = { player }
|
||||
}
|
||||
renders[player.index][key] = render_id
|
||||
end
|
||||
|
||||
--- Remove a render object for a player
|
||||
local function remove_render(player, key)
|
||||
local render = renders[player.index][key]
|
||||
if render and rendering.is_valid(render) then rendering.destroy(render) end
|
||||
renders[player.index][key] = nil
|
||||
end
|
||||
|
||||
--- Toggles entity protection selection
|
||||
-- @command protect-entity
|
||||
Commands.new_command('protect-entity', {'expcom-protection.description-pe'}, 'Toggles entity protection selection, hold shift to remove protection')
|
||||
:add_alias('pe')
|
||||
:register(function(player)
|
||||
if Selection.is_selecting(player, SelectionProtectEntity) then
|
||||
Selection.stop(player)
|
||||
else
|
||||
Selection.start(player, SelectionProtectEntity)
|
||||
return Commands.success{'expcom-protection.entered-entity-selection'}
|
||||
end
|
||||
end)
|
||||
|
||||
--- Toggles area protection selection
|
||||
-- @command protect-area
|
||||
Commands.new_command('protect-area', {'expcom-protection.description-pa'}, 'Toggles area protection selection, hold shift to remove protection')
|
||||
:add_alias('pa')
|
||||
:register(function(player)
|
||||
if Selection.is_selecting(player, SelectionProtectArea) then
|
||||
Selection.stop(player)
|
||||
else
|
||||
Selection.start(player, SelectionProtectArea)
|
||||
return Commands.success{'expcom-protection.entered-area-selection'}
|
||||
end
|
||||
end)
|
||||
|
||||
--- When an area is selected to add protection to entities
|
||||
Selection.on_selection(SelectionProtectEntity, function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
for _, entity in ipairs(event.entities) do
|
||||
EntityProtection.add_entity(entity)
|
||||
show_protected_entity(player, entity)
|
||||
end
|
||||
player.print{'expcom-protection.protected-entities', #event.entities}
|
||||
end)
|
||||
|
||||
--- When an area is selected to remove protection from entities
|
||||
Selection.on_alt_selection(SelectionProtectEntity, function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
for _, entity in ipairs(event.entities) do
|
||||
EntityProtection.remove_entity(entity)
|
||||
remove_render(player, get_entity_key(entity))
|
||||
end
|
||||
player.print{'expcom-protection.unprotected-entities', #event.entities}
|
||||
end)
|
||||
|
||||
--- When an area is selected to add protection to the area
|
||||
Selection.on_selection(SelectionProtectArea, function(event)
|
||||
local area = aabb_align_expand(event.area)
|
||||
local areas = EntityProtection.get_areas(event.surface)
|
||||
local player = game.get_player(event.player_index)
|
||||
for _, next_area in pairs(areas) do
|
||||
if aabb_area_enclosed(area, next_area) then
|
||||
return player.print{'expcom-protection.already-protected'}
|
||||
end
|
||||
end
|
||||
EntityProtection.add_area(event.surface, area)
|
||||
show_protected_area(player, event.surface, area)
|
||||
player.print{'expcom-protection.protected-area'}
|
||||
end)
|
||||
|
||||
--- When an area is selected to remove protection from the area
|
||||
Selection.on_alt_selection(SelectionProtectArea, function(event)
|
||||
local area = aabb_align_expand(event.area)
|
||||
local areas = EntityProtection.get_areas(event.surface)
|
||||
local player = game.get_player(event.player_index)
|
||||
for _, next_area in pairs(areas) do
|
||||
if aabb_area_enclosed(next_area, area) then
|
||||
EntityProtection.remove_area(event.surface, next_area)
|
||||
player.print{'expcom-protection.unprotected-area'}
|
||||
remove_render(player, get_area_key(next_area))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- When selection starts show all protected entities and protected areas
|
||||
Event.add(Selection.events.on_player_selection_start, function(event)
|
||||
if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end
|
||||
local player = game.get_player(event.player_index)
|
||||
local surface = player.surface
|
||||
renders[player.index] = {}
|
||||
-- Show protected entities
|
||||
local entities = EntityProtection.get_entities(surface)
|
||||
for _, entity in pairs(entities) do
|
||||
show_protected_entity(player, entity)
|
||||
end
|
||||
-- Show always protected entities by name
|
||||
if #EntityProtection.protected_entity_names > 0 then
|
||||
for _, entity in pairs(surface.find_entities_filtered{ name = EntityProtection.protected_entity_names, force = player.force }) do
|
||||
show_protected_entity(player, entity)
|
||||
end
|
||||
end
|
||||
-- Show always protected entities by type
|
||||
if #EntityProtection.protected_entity_types > 0 then
|
||||
for _, entity in pairs(surface.find_entities_filtered{ type = EntityProtection.protected_entity_types, force = player.force }) do
|
||||
show_protected_entity(player, entity)
|
||||
end
|
||||
end
|
||||
-- Show protected areas
|
||||
local areas = EntityProtection.get_areas(surface)
|
||||
for _, area in pairs(areas) do
|
||||
show_protected_area(player, surface, area)
|
||||
end
|
||||
end)
|
||||
|
||||
--- When selection ends hide protected entities and protected areas
|
||||
Event.add(Selection.events.on_player_selection_end, function(event)
|
||||
if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end
|
||||
for _, id in pairs(renders[event.player_index]) do
|
||||
if rendering.is_valid(id) then rendering.destroy(id) end
|
||||
end
|
||||
renders[event.player_index] = nil
|
||||
end)
|
||||
|
||||
--- When there is a repeat offence print it in chat
|
||||
Event.add(EntityProtection.events.on_repeat_violation, function(event)
|
||||
local player_name = format_chat_player_name(event.player_index)
|
||||
Roles.print_to_roles_higher('Regular', {'expcom-protection.repeat-offence', player_name, event.entity.localised_name, event.entity.position.x, event.entity.position.y})
|
||||
end)
|
||||
62
exp_legacy/module/modules/commands/rainbow.lua
Normal file
62
exp_legacy/module/modules/commands/rainbow.lua
Normal file
@@ -0,0 +1,62 @@
|
||||
--[[-- Commands Module - Rainbow
|
||||
- Adds a command that prints your message in rainbow font
|
||||
@commands Rainbow
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local format_chat_colour = _C.format_chat_colour --- @dep expcore.common
|
||||
|
||||
local function step_component(c1, c2)
|
||||
if c1 < 0 then
|
||||
return 0, c2+c1
|
||||
elseif c1 > 1 then
|
||||
return 1, c2-c1+1
|
||||
else
|
||||
return c1, c2
|
||||
end
|
||||
end
|
||||
|
||||
local function step_color(color)
|
||||
color.r, color.g = step_component(color.r, color.g)
|
||||
color.g, color.b = step_component(color.g, color.b)
|
||||
color.b, color.r = step_component(color.b, color.r)
|
||||
color.r = step_component(color.r, 0)
|
||||
return color
|
||||
end
|
||||
|
||||
local function next_color(color, step)
|
||||
step = step or 0.1
|
||||
local new_color = {r=0, g=0, b=0}
|
||||
if color.b == 0 and color.r ~= 0 then
|
||||
new_color.r = color.r-step
|
||||
new_color.g = color.g+step
|
||||
elseif color.r == 0 and color.g ~= 0 then
|
||||
new_color.g = color.g-step
|
||||
new_color.b = color.b+step
|
||||
elseif color.g == 0 and color.b ~= 0 then
|
||||
new_color.b = color.b-step
|
||||
new_color.r = color.r+step
|
||||
end
|
||||
return step_color(new_color)
|
||||
end
|
||||
|
||||
--- Sends an rainbow message in the chat
|
||||
-- @command rainbow
|
||||
-- @tparam string message the message that will be printed in chat
|
||||
Commands.new_command('rainbow', {'expcom-rainbow.description'}, 'Sends an rainbow message in the chat')
|
||||
:add_param('message', false)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, message)
|
||||
local player_name = player and player.name or '<Server>'
|
||||
local player_color = player and player.color or nil
|
||||
local color_step = 3/message:len()
|
||||
if color_step > 1 then color_step = 1 end
|
||||
local current_color = {r=1, g=0, b=0}
|
||||
local output = format_chat_colour(player_name..': ', player_color)
|
||||
output = output..message:gsub('%S', function(letter)
|
||||
local rtn = format_chat_colour(letter, current_color)
|
||||
current_color = next_color(current_color, color_step)
|
||||
return rtn
|
||||
end)
|
||||
game.print(output)
|
||||
end)
|
||||
86
exp_legacy/module/modules/commands/ratio.lua
Normal file
86
exp_legacy/module/modules/commands/ratio.lua
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
|
||||
local Commands = require 'expcore.commands'
|
||||
|
||||
local function Modules(moduleInventory) -- returns the multiplier of the modules
|
||||
local effect1 = moduleInventory.get_item_count("productivity-module") -- type 1
|
||||
local effect2 = moduleInventory.get_item_count("productivity-module-2")-- type 2
|
||||
local effect3 = moduleInventory.get_item_count("productivity-module-3") -- type 3
|
||||
|
||||
local multi = effect1*4+effect2*6+effect3*10
|
||||
return multi/100+1
|
||||
end
|
||||
|
||||
local function AmountOfMachines(itemsPerSecond, output)
|
||||
if(itemsPerSecond) then
|
||||
return itemsPerSecond/output
|
||||
end
|
||||
end
|
||||
|
||||
Commands.new_command('ratio', {'expcom-ratio.description'}, 'This command will give the input and output ratios of the selected machine. Use the parameter for calculating the machines needed for that amount of items per second.')
|
||||
:add_param('itemsPerSecond', true, 'number')
|
||||
:register(function(player, itemsPerSecond)
|
||||
local machine = player.selected -- selected machine
|
||||
|
||||
if not machine then --nil check
|
||||
return Commands.error{'expcom-ratio.notSelecting'}
|
||||
end
|
||||
|
||||
if machine.type ~= "assembling-machine" and machine.type ~= "furnace" then
|
||||
return Commands.error{'expcom-ratio.notSelecting'}
|
||||
end
|
||||
|
||||
local recipe = machine.get_recipe() -- recipe
|
||||
|
||||
if not recipe then --nil check
|
||||
return Commands.error{'expcom-ratio.notSelecting'}
|
||||
end
|
||||
|
||||
local items = recipe.ingredients -- items in that recipe
|
||||
local products = recipe.products -- output items
|
||||
local amountOfMachines
|
||||
local moduleInventory = machine.get_module_inventory()--the module Inventory of the machine
|
||||
local multi = Modules(moduleInventory) --function for the productively modals
|
||||
|
||||
if itemsPerSecond then
|
||||
amountOfMachines = math.ceil( AmountOfMachines(itemsPerSecond, 1/recipe.energy*machine.crafting_speed*products[1].amount*multi)) -- amount of machines
|
||||
end
|
||||
|
||||
if not amountOfMachines then
|
||||
amountOfMachines = 1 --set to 1 to make it not nil
|
||||
end
|
||||
|
||||
----------------------------items----------------------------
|
||||
for i, item in ipairs(items) do
|
||||
local sprite -- string to make the icon work either fluid ore item
|
||||
|
||||
if item.type == "item" then
|
||||
sprite = 'expcom-ratio.item-in'
|
||||
|
||||
else
|
||||
sprite = 'expcom-ratio.fluid-in'
|
||||
end
|
||||
|
||||
local ips = item.amount/recipe.energy*machine.crafting_speed*amountOfMachines --math on the items/fluids per second
|
||||
Commands.print{sprite, math.round(ips, 3), item.name} -- full string
|
||||
end
|
||||
|
||||
----------------------------products----------------------------
|
||||
for i, product in ipairs(products) do
|
||||
local sprite -- string to make the icon work either fluid ore item
|
||||
|
||||
if product.type == "item" then
|
||||
sprite = 'expcom-ratio.item-out'
|
||||
else
|
||||
sprite = 'expcom-ratio.fluid-out'
|
||||
end
|
||||
|
||||
local output = 1/recipe.energy*machine.crafting_speed*product.amount*multi --math on the outputs per second
|
||||
Commands.print {sprite, math.round(output*amountOfMachines, 3), product.name} -- full string
|
||||
|
||||
end
|
||||
|
||||
if amountOfMachines ~= 1 then
|
||||
Commands.print{'expcom-ratio.machines', amountOfMachines}
|
||||
end
|
||||
end)
|
||||
52
exp_legacy/module/modules/commands/repair.lua
Normal file
52
exp_legacy/module/modules/commands/repair.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
--[[-- Commands Module - Repair
|
||||
- Adds a command that allows an admin to repair and revive a large area
|
||||
@commands Repair
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local config = require 'config.repair' --- @dep config.repair
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
local max_time_to_live = 4294967295 -- unit32 max
|
||||
--- Repairs entities on your force around you
|
||||
-- @command repair
|
||||
-- @tparam number range the range to repair stuff in, there is a max limit to this
|
||||
Commands.new_command('repair', {'expcom-repair.description'}, 'Repairs entities on your force around you')
|
||||
:add_param('range', false, 'integer-range', 1, config.max_range)
|
||||
:register(function(player, range)
|
||||
local revive_count = 0
|
||||
local heal_count = 0
|
||||
local range2 = range^2
|
||||
local surface = player.surface
|
||||
local center = player.position
|
||||
local area = {{x=center.x-range, y=center.y-range}, {x=center.x+range, y=center.y+range}}
|
||||
if config.allow_ghost_revive then
|
||||
local ghosts = surface.find_entities_filtered({area=area, type='entity-ghost', force=player.force})
|
||||
for _, ghost in pairs(ghosts) do
|
||||
if ghost.valid then
|
||||
local x = ghost.position.x-center.x
|
||||
local y = ghost.position.y-center.y
|
||||
if x^2+y^2 <= range2 then
|
||||
if config.allow_blueprint_repair or ghost.time_to_live ~= max_time_to_live then
|
||||
revive_count = revive_count+1
|
||||
if not config.disallow[ghost.ghost_name] then ghost.revive() end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if config.allow_heal_entities then
|
||||
local entities = surface.find_entities_filtered({area=area, force=player.force})
|
||||
for _, entity in pairs(entities) do
|
||||
if entity.valid then
|
||||
local x = entity.position.x-center.x
|
||||
local y = entity.position.y-center.y
|
||||
if entity.health and entity.get_health_ratio() ~= 1 and x^2+y^2 <= range2 then
|
||||
heal_count = heal_count+1
|
||||
entity.health = max_time_to_live
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return Commands.success{'expcom-repair.result', revive_count, heal_count}
|
||||
end)
|
||||
97
exp_legacy/module/modules/commands/reports.lua
Normal file
97
exp_legacy/module/modules/commands/reports.lua
Normal file
@@ -0,0 +1,97 @@
|
||||
--[[-- Commands Module - Reports
|
||||
- Adds a commands that allow players to report other players
|
||||
@commands Reports
|
||||
]]
|
||||
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Reports = require 'modules.control.reports' --- @dep modules.control.reports
|
||||
local format_chat_player_name = _C.format_chat_player_name--- @dep expcore.common
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
--- Print a message to all players who match the value of admin
|
||||
local function print_to_players(admin, message)
|
||||
for _, player in ipairs(game.connected_players) do
|
||||
if player.admin == admin then
|
||||
player.print(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Reports a player and notifies moderators
|
||||
-- @command report
|
||||
-- @tparam LuaPlayer player the player to report, some players are immune
|
||||
-- @tparam string reason the reason the player is being reported
|
||||
Commands.new_command('report', {'expcom-report.description-report'}, 'Reports a player and notifies moderators')
|
||||
:add_param('player', false, function(input, player, reject)
|
||||
input = Commands.parse('player', input, player, reject)
|
||||
if not input then return end
|
||||
if Roles.player_has_flag(input, 'report-immune') then
|
||||
return reject{'expcom-report.player-immune'}
|
||||
elseif player == input then
|
||||
return reject{'expcom-report.self-report'}
|
||||
else
|
||||
return input
|
||||
end
|
||||
end)
|
||||
:add_param('reason', false)
|
||||
:add_alias('report-player')
|
||||
:enable_auto_concat()
|
||||
:register(function(player, action_player, reason)
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
local by_player_name_color = format_chat_player_name(player)
|
||||
if Reports.report_player(action_player, player.name, reason) then
|
||||
print_to_players(false, {'expcom-report.non-admin', action_player_name_color, reason})
|
||||
print_to_players(true, {'expcom-report.admin', action_player_name_color, by_player_name_color, reason})
|
||||
else
|
||||
return Commands.error{'expcom-report.already-reported'}
|
||||
end
|
||||
end)
|
||||
|
||||
--- Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them.
|
||||
-- @command get-reports
|
||||
-- @tparam LuaPlayer player the player to get the report for
|
||||
Commands.new_command('get-reports', {'expcom-report.description-get-reports'}, 'Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them.')
|
||||
:add_param('player', true, 'player')
|
||||
:add_alias('reports', 'list-reports')
|
||||
:register(function(_, player)
|
||||
if player then
|
||||
local reports = Reports.get_reports(player)
|
||||
local player_name_color = format_chat_player_name(player)
|
||||
Commands.print{'expcom-report.player-report-title', player_name_color}
|
||||
for player_name, reason in pairs(reports) do
|
||||
local by_player_name_color = format_chat_player_name(player_name)
|
||||
Commands.print{'expcom-report.list', by_player_name_color, reason}
|
||||
end
|
||||
else
|
||||
local user_reports = Reports.user_reports
|
||||
Commands.print{'expcom-report.player-count-title'}
|
||||
for player_name in pairs(user_reports) do
|
||||
local player_name_color = format_chat_player_name(player_name)
|
||||
local report_count = Reports.count_reports(player_name)
|
||||
Commands.print{'expcom-report.list', player_name_color, report_count}
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Clears all reports from a player or just the report from one player.
|
||||
-- @command clear-reports
|
||||
-- @tparam LuaPlayer player the player to clear the report(s) from
|
||||
-- @tparam[opt=all] LuaPlayer from-player remove only the report made by this player
|
||||
Commands.new_command('clear-reports', {'expcom-report.description-clear-reports'}, 'Clears all reports from a player or just the report from one player.')
|
||||
:add_param('player', false, 'player')
|
||||
:add_param('from-player', true, 'player')
|
||||
:register(function(player, action_player, from_player)
|
||||
if from_player then
|
||||
if not Reports.remove_report(action_player, from_player.name, player.name) then
|
||||
return Commands.error{'expcom-report.not-reported'}
|
||||
end
|
||||
else
|
||||
if not Reports.remove_all(action_player, player.name) then
|
||||
return Commands.error{'expcom-report.not-reported'}
|
||||
end
|
||||
end
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
local by_player_name_color = format_chat_player_name(player)
|
||||
game.print{'expcom-report.removed', action_player_name_color, by_player_name_color}
|
||||
end)
|
||||
45
exp_legacy/module/modules/commands/research.lua
Normal file
45
exp_legacy/module/modules/commands/research.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local config = require 'config.research' --- @dep config.research
|
||||
|
||||
local research = {}
|
||||
Global.register(research, function(tbl)
|
||||
research = tbl
|
||||
end)
|
||||
|
||||
local function res_queue(force, by_script)
|
||||
local res_q = force.research_queue
|
||||
local res = force.technologies['mining-productivity-4']
|
||||
|
||||
if #res_q < config.queue_amount then
|
||||
for i=1, config.queue_amount - #res_q do
|
||||
force.add_research(res)
|
||||
|
||||
if not (by_script) then
|
||||
game.print{'expcom-res.inf-q', res.name, res.level + i}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Commands.new_command('auto-research', {'expcom-res.description-ares'}, 'Automatically queue up research')
|
||||
:add_alias('ares')
|
||||
:register(function(player)
|
||||
research.res_queue_enable = not research.res_queue_enable
|
||||
|
||||
if research.res_queue_enable then
|
||||
res_queue(player.force, true)
|
||||
end
|
||||
|
||||
game.print{'expcom-res.res', player.name, research.res_queue_enable}
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_research_finished, function(event)
|
||||
if research.res_queue_enable then
|
||||
if event.research.force.rockets_launched > 0 and event.research.force.technologies['mining-productivity-4'].level > 4 then
|
||||
res_queue(event.research.force, event.by_script)
|
||||
end
|
||||
end
|
||||
end)
|
||||
83
exp_legacy/module/modules/commands/roles.lua
Normal file
83
exp_legacy/module/modules/commands/roles.lua
Normal file
@@ -0,0 +1,83 @@
|
||||
--[[-- Commands Module - Roles
|
||||
- Adds a commands that allow interaction with the role system
|
||||
@commands Roles
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local Colours = require 'utils.color_presets' --- @dep utils.color_presets
|
||||
local format_chat_player_name, format_chat_colour_localized = _C.format_chat_player_name, _C.format_chat_colour_localized
|
||||
|
||||
--- Assigns a role to a player
|
||||
-- @command assign-role
|
||||
-- @tparam LuaPlayer player the player to assign the role to
|
||||
-- @tparam string role the name of the role to assign to the player, supports auto complete after enter
|
||||
Commands.new_command('assign-role', {'expcom-roles.description-assign-role'}, 'Assigns a role to a player')
|
||||
:add_param('player', false, 'player-role')
|
||||
:add_param('role', false, 'role')
|
||||
:set_flag('admin-only')
|
||||
:add_alias('rpromote', 'assign', 'role', 'add-role')
|
||||
:register(function(player, action_player, role)
|
||||
local player_highest = Roles.get_player_highest_role(player)
|
||||
|
||||
if player_highest.index < role.index then
|
||||
Roles.assign_player(action_player, role, player.name)
|
||||
|
||||
else
|
||||
return Commands.error{'expcom-roles.higher-role'}
|
||||
end
|
||||
end)
|
||||
|
||||
--- Unassigns a role from a player
|
||||
-- @command unassign-role
|
||||
-- @tparam LuaPlayer player the player to unassign the role from
|
||||
-- @tparam string role the name of the role to unassign from the player, supports auto complete after enter
|
||||
Commands.new_command('unassign-role', {'expcom-roles.description-unassign-role'}, 'Unassigns a role from a player')
|
||||
:add_param('player', false, 'player-role')
|
||||
:add_param('role', false, 'role')
|
||||
:set_flag('admin-only')
|
||||
:add_alias('rdemote', 'unassign', 'rerole', 'remove-role')
|
||||
:register(function(player, action_player, role)
|
||||
local player_highest = Roles.get_player_highest_role(player)
|
||||
|
||||
if player_highest.index < role.index then
|
||||
Roles.unassign_player(action_player, role, player.name)
|
||||
|
||||
else
|
||||
return Commands.error{'expcom-roles.higher-role'}
|
||||
end
|
||||
end)
|
||||
|
||||
--- Lists all roles in they correct order
|
||||
-- @command list-roles
|
||||
-- @tparam[opt=all] LuaPlayer player list only the roles which this player has
|
||||
Commands.new_command('list-roles', {'expcom-roles.description-list-roles'}, 'Lists all roles in they correct order')
|
||||
:add_param('player', true, 'player')
|
||||
:add_alias('lsroles', 'roles')
|
||||
:register(function(_, player)
|
||||
local roles = Roles.config.order
|
||||
local message = {'expcom-roles.list'}
|
||||
|
||||
if player then
|
||||
roles = Roles.get_player_roles(player)
|
||||
end
|
||||
|
||||
for index, role in pairs(roles) do
|
||||
role = Roles.get_role_from_any(role)
|
||||
local colour = role.custom_color or Colours.white
|
||||
local role_name = format_chat_colour_localized(role.name, colour)
|
||||
if index == 1 then
|
||||
message = {'expcom-roles.list', role_name}
|
||||
|
||||
if player then
|
||||
local player_name_colour = format_chat_player_name(player)
|
||||
message = {'expcom-roles.list-player', player_name_colour, role_name}
|
||||
end
|
||||
|
||||
else
|
||||
message = {'expcom-roles.list-element', message, role_name}
|
||||
end
|
||||
end
|
||||
|
||||
return Commands.success(message)
|
||||
end)
|
||||
167
exp_legacy/module/modules/commands/search.lua
Normal file
167
exp_legacy/module/modules/commands/search.lua
Normal file
@@ -0,0 +1,167 @@
|
||||
--[[-- Commands Module - Inventory Search
|
||||
- Adds commands that will search all players inventories for an item
|
||||
@commands InventorySearch
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local format_number = require('util').format_number --- @dep util
|
||||
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common
|
||||
local format_time = _C.format_time
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
--- Input parse for items by name
|
||||
local function item_parse(input, _, reject)
|
||||
if input == nil then return end
|
||||
local lower_input = input:lower():gsub(' ', '-')
|
||||
|
||||
-- Simple Case - internal name is given
|
||||
local item = game.item_prototypes[lower_input]
|
||||
if item then return item end
|
||||
|
||||
-- Second Case - rich text is given
|
||||
local item_name = input:match('%[item=([0-9a-z-]+)%]')
|
||||
item = game.item_prototypes[item_name]
|
||||
if item then return item end
|
||||
|
||||
-- No item found, we do not attempt to search all prototypes as this will be expensive
|
||||
return reject{'expcom-inv-search.reject-item', lower_input}
|
||||
end
|
||||
|
||||
--- Search all players for this item
|
||||
local function search_players(players, item)
|
||||
local head = 1
|
||||
local found = {}
|
||||
|
||||
-- Check the item count of all players
|
||||
for _, player in pairs(players) do
|
||||
local item_count = player.get_item_count(item.name)
|
||||
if item_count > 0 then
|
||||
-- Add the player to the array as they have the item
|
||||
found[head] = { player=player, count=item_count, online_time=player.online_time }
|
||||
head = head + 1
|
||||
end
|
||||
end
|
||||
|
||||
return found
|
||||
end
|
||||
|
||||
--- Custom sort function which only retains 5 greatest values
|
||||
local function sort_players(players, func)
|
||||
local sorted = {}
|
||||
local values = {}
|
||||
local threshold = nil
|
||||
|
||||
-- Loop over all provided players
|
||||
for index, player in ipairs(players) do
|
||||
local value = func(player)
|
||||
-- Check if the item will make the top 5 elements
|
||||
if index <= 5 or value > threshold then
|
||||
local inserted = false
|
||||
values[player] = value
|
||||
-- Find where in the top 5 to insert the element
|
||||
for next_index, next_player in ipairs(sorted) do
|
||||
if value > values[next_player] then
|
||||
table.insert(sorted, next_index, player)
|
||||
inserted = true
|
||||
break
|
||||
end
|
||||
end
|
||||
-- Insert the element, this can only be called when index <= 5
|
||||
if not inserted then
|
||||
sorted[#sorted+1] = player
|
||||
end
|
||||
-- Update the threshold
|
||||
if sorted[6] then
|
||||
threshold = values[sorted[5]]
|
||||
values[sorted[6]] = nil
|
||||
sorted[6] = nil
|
||||
else
|
||||
threshold = values[sorted[#sorted]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return sorted
|
||||
end
|
||||
|
||||
--- Display to the player the top players which were found
|
||||
local function display_players(player, players, item)
|
||||
player.print{'expcom-inv-search.results-heading', item.name}
|
||||
for index, data in ipairs(players) do
|
||||
local player_name_color = format_chat_player_name(data.player)
|
||||
local amount = format_number(data.count)
|
||||
local time = format_time(data.online_time)
|
||||
player.print{'expcom-inv-search.results-item', index, player_name_color, amount, time}
|
||||
end
|
||||
end
|
||||
|
||||
--- Return the amount of an item a player has
|
||||
local function amount_sort(data)
|
||||
return data.count
|
||||
end
|
||||
|
||||
--- Get a list of players sorted by the quantity of an item in their inventory
|
||||
-- @command search-amount
|
||||
-- @tparam LuaItemPrototype item The item to search for in players inventories
|
||||
Commands.new_command('search-amount', {'expcom-inv-search.description-ia'}, 'Display players sorted by the quantity of an item held')
|
||||
:add_alias('ia')
|
||||
:add_param('item', false, item_parse)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, item)
|
||||
local players = search_players(game.players, item)
|
||||
if #players == 0 then return {'expcom-inv-search.results-none', item.name} end
|
||||
local top_players = sort_players(players, amount_sort)
|
||||
display_players(player, top_players, item)
|
||||
end)
|
||||
|
||||
--- Return the index of the player, higher means they joined more recently
|
||||
local function recent_sort(data)
|
||||
return data.player.index
|
||||
end
|
||||
|
||||
--- Get a list of players who have the given item, sorted by how recently they joined
|
||||
-- @command search-recent
|
||||
-- @tparam LuaItemPrototype item The item to search for in players inventories
|
||||
Commands.new_command('search-recent', {'expcom-inv-search.description-ir'}, 'Display players who hold an item sorted by join time')
|
||||
:add_alias('ir')
|
||||
:add_param('item', false, item_parse)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, item)
|
||||
local players = search_players(game.players, item)
|
||||
if #players == 0 then return {'expcom-inv-search.results-none', item.name} end
|
||||
local top_players = sort_players(players, recent_sort)
|
||||
display_players(player, top_players, item)
|
||||
end)
|
||||
|
||||
--- Return the the amount of an item a player has divided by their playtime
|
||||
local function combined_sort(data)
|
||||
return data.count/data.online_time
|
||||
end
|
||||
|
||||
--- Get a list of players sorted by quantity held and play time
|
||||
-- @command search
|
||||
-- @tparam LuaItemPrototype item The item to search for in players inventories
|
||||
Commands.new_command('search', {'expcom-inv-search.description-i'}, 'Display players sorted by the quantity of an item held and playtime')
|
||||
:add_alias('i')
|
||||
:add_param('item', false, item_parse)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, item)
|
||||
local players = search_players(game.players, item)
|
||||
if #players == 0 then return {'expcom-inv-search.results-none', item.name} end
|
||||
local top_players = sort_players(players, combined_sort)
|
||||
display_players(player, top_players, item)
|
||||
end)
|
||||
|
||||
--- Get a list of online players sorted by quantity held and play time
|
||||
-- @command search-online
|
||||
-- @tparam LuaItemPrototype item The item to search for in players inventories
|
||||
Commands.new_command('search-online', {'expcom-inv-search.description-io'}, 'Display online players sorted by the quantity of an item held and playtime')
|
||||
:add_alias('io')
|
||||
:add_param('item', false, item_parse)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, item)
|
||||
local players = search_players(game.connected_players, item)
|
||||
if #players == 0 then return {'expcom-inv-search.results-none', item.name} end
|
||||
local top_players = sort_players(players, combined_sort)
|
||||
display_players(player, top_players, item)
|
||||
end)
|
||||
69
exp_legacy/module/modules/commands/spawn.lua
Normal file
69
exp_legacy/module/modules/commands/spawn.lua
Normal file
@@ -0,0 +1,69 @@
|
||||
--[[-- Commands Module - Spawn
|
||||
- Adds a command that allows players to teleport to their spawn point
|
||||
@commands Spawn
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
|
||||
local function teleport(player)
|
||||
local surface = player.surface
|
||||
local spawn = player.force.get_spawn_position(surface)
|
||||
local position = surface.find_non_colliding_position('character', spawn, 32, 1)
|
||||
-- return false if no new position
|
||||
if not position then
|
||||
return false
|
||||
end
|
||||
if player.vehicle then
|
||||
-- Teleport the entity
|
||||
local entity = player.vehicle
|
||||
local goto_position = surface.find_non_colliding_position(entity.name, position, 32, 1)
|
||||
-- Surface teleport can only be done for players and cars at the moment. (with surface as an peramitor it gives this error)
|
||||
if entity.type == "car" then
|
||||
entity.teleport(goto_position, surface)
|
||||
elseif surface.index == entity.surface.index then
|
||||
-- Try teleport the entity
|
||||
if not entity.teleport(goto_position) then
|
||||
player.driving = false
|
||||
player.teleport(position, surface)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Teleport the player
|
||||
player.teleport(position, surface)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Teleport to spawn
|
||||
-- @command go-to-spawn
|
||||
-- @tparam[opt=self] LuaPlayer player the player to teleport to their spawn point
|
||||
Commands.new_command('go-to-spawn', {'expcom-spawn.description'}, 'Teleport to spawn')
|
||||
:add_param('player', true, 'player-role-alive')
|
||||
:set_defaults{
|
||||
player=function(player)
|
||||
if player.connected and player.character and player.character.health > 0 then
|
||||
return player
|
||||
end
|
||||
end
|
||||
}
|
||||
:add_alias('spawn', 'tp-spawn')
|
||||
:register(function(player, action_player)
|
||||
if not action_player then
|
||||
return Commands.error{'expcom-spawn.unavailable'}
|
||||
|
||||
elseif action_player == player then
|
||||
if not teleport(player) then
|
||||
return Commands.error{'expcom-spawn.unavailable'}
|
||||
end
|
||||
|
||||
elseif Roles.player_allowed(player, 'command/go-to-spawn/always') then
|
||||
if not teleport(action_player) then
|
||||
return Commands.error{'expcom-spawn.unavailable'}
|
||||
end
|
||||
|
||||
else
|
||||
return Commands.error{'expcore-commands.unauthorized'}
|
||||
end
|
||||
end)
|
||||
35
exp_legacy/module/modules/commands/spectate.lua
Normal file
35
exp_legacy/module/modules/commands/spectate.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
--[[-- Commands Module - Spectate
|
||||
- Adds commands relating to spectate and follow
|
||||
@commands Spectate
|
||||
]]
|
||||
|
||||
local Spectate = require 'modules.control.spectate' --- @dep modules.control.spectate
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
--- Toggles spectator mode for the caller
|
||||
-- @command spectate
|
||||
Commands.new_command('spectate', {'expcom-spectate.description-spectate'}, 'Toggles spectator mode')
|
||||
:register(function(player)
|
||||
if Spectate.is_spectating(player) then
|
||||
Spectate.stop_spectate(player)
|
||||
|
||||
else
|
||||
Spectate.start_spectate(player)
|
||||
end
|
||||
end)
|
||||
|
||||
--- Enters follow mode for the caller, following the given player.
|
||||
-- @command follow
|
||||
-- @tparam LuaPlayer player The player that will be followed
|
||||
Commands.new_command('follow', {'expcom-spectate.description-follow'}, 'Start following a player in spectator')
|
||||
:add_alias('f')
|
||||
:add_param('player', false, 'player-online')
|
||||
:register(function(player, action_player)
|
||||
if player == action_player then
|
||||
return Commands.error{'expcom-spectate.follow-self'}
|
||||
|
||||
else
|
||||
Spectate.start_follow(player, action_player)
|
||||
end
|
||||
end)
|
||||
16
exp_legacy/module/modules/commands/speed.lua
Normal file
16
exp_legacy/module/modules/commands/speed.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
--[[-- Commands Module - Set game speed
|
||||
- Adds a command that allows changing game speed
|
||||
@commands Set game speed
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('game-speed', {'expcom-speed.description'}, 'Set game speed')
|
||||
:add_param('amount', 'number-range', 0.2, 8)
|
||||
:set_flag('admin_only')
|
||||
:register(function(player, amount)
|
||||
game.speed = math.round(amount, 3)
|
||||
game.print{'expcom-speed.result', player.name, string.format('%.3f', amount)}
|
||||
return Commands.success
|
||||
end)
|
||||
33
exp_legacy/module/modules/commands/surface-clearing.lua
Normal file
33
exp_legacy/module/modules/commands/surface-clearing.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
--[[-- Commands Module - Clear Item On Ground
|
||||
- Adds a command that clear item on ground so blueprint can deploy safely
|
||||
@commands Clear Item On Ground
|
||||
]]
|
||||
|
||||
local copy_items_stack = _C.copy_items_stack --- @dep expcore.common
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('clear-item-on-ground', {'expcom-surface-clearing.description-ci'}, 'Clear Item On Ground')
|
||||
:add_param('range', false, 'integer-range', 1, 1000)
|
||||
:register(function(player, range)
|
||||
for _, e in pairs(player.surface.find_entities_filtered{position=player.position, radius=range, name='item-on-ground'}) do
|
||||
if e.stack then
|
||||
-- calling move_items_stack(e.stack) will crash to desktop
|
||||
-- https://forums.factorio.com/viewtopic.php?f=7&t=110322
|
||||
copy_items_stack{e.stack}
|
||||
e.stack.clear()
|
||||
end
|
||||
end
|
||||
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Commands.new_command('clear-blueprint', {'expcom-surface-clearing.description-cb'}, 'Clear Blueprint')
|
||||
:add_param('range', false, 'integer-range', 1, 1000)
|
||||
:register(function(player, range)
|
||||
for _, e in pairs(player.surface.find_entities_filtered{position=player.position, radius=range, type='entity-ghost'}) do
|
||||
e.destroy()
|
||||
end
|
||||
|
||||
return Commands.success
|
||||
end)
|
||||
93
exp_legacy/module/modules/commands/teleport.lua
Normal file
93
exp_legacy/module/modules/commands/teleport.lua
Normal file
@@ -0,0 +1,93 @@
|
||||
--[[-- Commands Module - Teleport
|
||||
- Adds a command that allows players to teleport to other players
|
||||
@commands Teleport
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
local function teleport(from_player, to_player)
|
||||
local surface = to_player.surface
|
||||
local position = surface.find_non_colliding_position('character', to_player.position, 32, 1)
|
||||
|
||||
-- return false if no new position
|
||||
if not position then
|
||||
return false
|
||||
end
|
||||
|
||||
if from_player.vehicle then
|
||||
-- Teleport the entity
|
||||
local entity = from_player.vehicle
|
||||
local goto_position = surface.find_non_colliding_position(entity.name, position, 32, 1)
|
||||
|
||||
-- Surface teleport can only be done for players and cars at the moment. (with surface as an peramitor it gives this error)
|
||||
if entity.type == "car" then
|
||||
entity.teleport(goto_position, surface)
|
||||
elseif surface.index == entity.surface.index then
|
||||
-- Try teleport the entity
|
||||
if not entity.teleport(goto_position) then
|
||||
from_player.driving = false
|
||||
from_player.teleport(position, surface)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Teleport the player
|
||||
from_player.teleport(position, surface)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Teleports a player to another player.
|
||||
-- @command teleport
|
||||
-- @tparam LuaPlayer from_player the player that will be teleported, must be alive
|
||||
-- @tparam LuaPlayer to_player the player to teleport to, must be online (if dead goes to where they died)
|
||||
Commands.new_command('teleport', {'expcom-tp.description-tp'}, 'Teleports a player to another player.')
|
||||
:add_param('from_player', false, 'player-alive')
|
||||
:add_param('to_player', false, 'player-online')
|
||||
:add_alias('tp')
|
||||
:set_flag('admin_only')
|
||||
:register(function(_, from_player, to_player)
|
||||
if from_player.index == to_player.index then
|
||||
-- return if attempting to teleport to self
|
||||
return Commands.error{'expcom-tp.to-self'}
|
||||
end
|
||||
if not teleport(from_player, to_player) then
|
||||
-- return if the teleport failed
|
||||
return Commands.error{'expcom-tp.no-position-found'}
|
||||
end
|
||||
end)
|
||||
|
||||
--- Teleports a player to you.
|
||||
-- @command bring
|
||||
-- @tparam LuaPlayer player the player that will be teleported, must be alive
|
||||
Commands.new_command('bring', {'expcom-tp.description-bring'}, 'Teleports a player to you.')
|
||||
:add_param('player', false, 'player-alive')
|
||||
:set_flag('admin_only')
|
||||
:register(function(player, from_player)
|
||||
if from_player.index == player.index then
|
||||
-- return if attempting to teleport to self
|
||||
return Commands.error{'expcom-tp.to-self'}
|
||||
end
|
||||
if not teleport(from_player, player) then
|
||||
-- return if the teleport failed
|
||||
return Commands.error{'expcom-tp.no-position-found'}
|
||||
end
|
||||
from_player.print('Come here my friend')
|
||||
end)
|
||||
|
||||
--- Teleports you to a player.
|
||||
-- @command goto
|
||||
-- @tparam LuaPlayer player the player to teleport to, must be online (if dead goes to where they died)
|
||||
Commands.new_command('goto', {'expcom-tp.description-goto'}, 'Teleports you to a player.')
|
||||
:add_param('player', false, 'player-online')
|
||||
:add_alias('tp-me', 'tpme')
|
||||
:register(function(player, to_player)
|
||||
if to_player.index == player.index then
|
||||
-- return if attempting to teleport to self
|
||||
return Commands.error{'expcom-tp.to-self'}
|
||||
end
|
||||
if not teleport(player, to_player) then
|
||||
-- return if the teleport failed
|
||||
return Commands.error{'expcom-tp.no-position-found'}
|
||||
end
|
||||
end)
|
||||
23
exp_legacy/module/modules/commands/train.lua
Normal file
23
exp_legacy/module/modules/commands/train.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
--[[-- Commands Module - Set Automatic Train
|
||||
- Adds a command that set all train back to automatic
|
||||
@commands Set Automatic Train
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
local format_number = require('util').format_number
|
||||
|
||||
Commands.new_command('set-trains-to-automatic', {'expcom-train.description'}, 'Set All Trains to Automatic')
|
||||
:register(function(player)
|
||||
local count = 0
|
||||
|
||||
for _, v in pairs(player.force.get_trains()) do
|
||||
if v.manual_mode then
|
||||
count = count + 1
|
||||
v.manual_mode = false
|
||||
end
|
||||
end
|
||||
|
||||
game.print{'expcom-train.manual-result', player.name, format_number(count)}
|
||||
return Commands.success
|
||||
end)
|
||||
15
exp_legacy/module/modules/commands/vlayer.lua
Normal file
15
exp_legacy/module/modules/commands/vlayer.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
--- Adds a virtual layer to store power to save space.
|
||||
-- @commands Vlayer
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
local vlayer = require 'modules.control.vlayer'
|
||||
|
||||
Commands.new_command('vlayer-info', {'vlayer.description-vi'}, 'Vlayer Info')
|
||||
:register(function(_)
|
||||
local c = vlayer.get_circuits()
|
||||
|
||||
for k, v in pairs(c) do
|
||||
Commands.print(v .. ' : ' .. k)
|
||||
end
|
||||
end)
|
||||
74
exp_legacy/module/modules/commands/warnings.lua
Normal file
74
exp_legacy/module/modules/commands/warnings.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
--[[-- Commands Module - Warnings
|
||||
- Adds a commands that allow admins to warn other players
|
||||
@commands Warnings
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Warnings = require 'modules.control.warnings' --- @dep modules.control.warnings
|
||||
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common
|
||||
local config = require 'config.warnings' --- @dep config.warnings
|
||||
require 'config.expcore.command_role_parse'
|
||||
|
||||
--- Gives a warning to a player; may lead to automatic script action.
|
||||
-- @command give-warning
|
||||
-- @tparam LuaPlayer player the player the will recive a warning
|
||||
-- @tparam string reason the reason the player is being given a warning
|
||||
Commands.new_command('give-warning', {'expcom-warnings.description-give'}, 'Gives a warning to a player; may lead to automatic script action.')
|
||||
:add_param('player', false, 'player-role')
|
||||
:add_param('reason', false)
|
||||
:add_alias('warn')
|
||||
:enable_auto_concat()
|
||||
:register(function(player, action_player, reason)
|
||||
Warnings.add_warning(action_player, player.name, reason)
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
local by_player_name_color = format_chat_player_name(player)
|
||||
game.print{'expcom-warnings.received', action_player_name_color, by_player_name_color, reason}
|
||||
end)
|
||||
|
||||
--- Gets the number of warnings a player has. If no player then lists all players and the number of warnings they have.
|
||||
-- @command get-warnings
|
||||
-- @tparam[opt=list] LuaPlayer player the player to get the warning for, if nil all players are listed
|
||||
Commands.new_command('get-warnings', {'expcom-warnings.description-get'}, 'Gets the number of warnings a player has. If no player then lists all players and the number of warnings they have.')
|
||||
:add_param('player', true, 'player')
|
||||
:add_alias('warnings', 'list-warnings')
|
||||
:register(function(_, player)
|
||||
if player then
|
||||
local warnings = Warnings.get_warnings(player)
|
||||
local script_warnings = Warnings.get_script_warnings(player)
|
||||
local player_name_color = format_chat_player_name(player)
|
||||
Commands.print{'expcom-warnings.player', player_name_color, #warnings, #script_warnings, config.temp_warning_limit}
|
||||
for _, warning in ipairs(warnings) do
|
||||
Commands.print{'expcom-warnings.player-detail', format_chat_player_name(warning.by_player_name), warning.reason}
|
||||
end
|
||||
else
|
||||
local rtn = {}
|
||||
local user_script_warnings = Warnings.user_script_warnings
|
||||
for player_name, warnings in pairs(Warnings.user_warnings:get_all()) do
|
||||
rtn[player_name] = {#warnings, 0}
|
||||
end
|
||||
for player_name, warnings in pairs(user_script_warnings) do
|
||||
if not rtn[player_name] then
|
||||
rtn[player_name] = {0, 0}
|
||||
end
|
||||
rtn[player_name][2] = #warnings
|
||||
end
|
||||
Commands.print{'expcom-warnings.list-title'}
|
||||
for player_name, warnings in pairs(rtn) do
|
||||
local player_name_color = format_chat_player_name(player_name)
|
||||
Commands.print{'expcom-warnings.list', player_name_color, warnings[1], warnings[2], config.temp_warning_limit}
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Clears all warnings (and script warnings) from a player
|
||||
-- @command clear-warnings
|
||||
-- @tparam LuaPlayer player the player to clear the warnings from
|
||||
Commands.new_command('clear-warnings', {'expcom-warnings.description-clear'}, 'Clears all warnings (and script warnings) from a player')
|
||||
:add_param('player', false, 'player')
|
||||
:register(function(player, action_player)
|
||||
Warnings.clear_warnings(action_player, player.name)
|
||||
Warnings.clear_script_warnings(action_player)
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
local by_player_name_color = format_chat_player_name(player)
|
||||
game.print{'expcom-warnings.cleared', action_player_name_color, by_player_name_color}
|
||||
end)
|
||||
79
exp_legacy/module/modules/commands/waterfill.lua
Normal file
79
exp_legacy/module/modules/commands/waterfill.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
--- Adds a waterfill
|
||||
-- @commands Waterfill
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
local Selection = require 'modules.control.selection' --- @dep modules.control.selection
|
||||
local SelectionConvertArea = 'WaterfillConvertArea'
|
||||
|
||||
--- Align an aabb to the grid by expanding it
|
||||
local function aabb_align_expand(aabb)
|
||||
return {
|
||||
left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)},
|
||||
right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)}
|
||||
}
|
||||
end
|
||||
|
||||
Commands.new_command('waterfill', {'expcom-waterfill.description'}, 'Change tile to water')
|
||||
:register(function(player)
|
||||
local inv = player.get_main_inventory()
|
||||
|
||||
if (inv.get_item_count('cliff-explosives')) == 0 then
|
||||
return player.print{'expcom-waterfill.waterfill-cliff'}
|
||||
end
|
||||
|
||||
if Selection.is_selecting(player, SelectionConvertArea) then
|
||||
Selection.stop(player)
|
||||
else
|
||||
Selection.start(player, SelectionConvertArea)
|
||||
return Commands.success{'expcom-waterfill.entered-area-selection'}
|
||||
end
|
||||
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
--- When an area is selected to add protection to the area
|
||||
Selection.on_selection(SelectionConvertArea, function(event)
|
||||
local area = aabb_align_expand(event.area)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
||||
local entities = player.surface.find_entities_filtered{area=area, name='steel-chest'}
|
||||
|
||||
if #entities == 0 then
|
||||
player.print('No steel chest found')
|
||||
return
|
||||
end
|
||||
|
||||
local tiles_to_make = {}
|
||||
local inv = player.get_main_inventory()
|
||||
|
||||
if not inv then
|
||||
return
|
||||
end
|
||||
|
||||
local clf_exp = inv.get_item_count('cliff-explosives')
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
if clf_exp >= 1 then
|
||||
if entity.get_inventory(defines.inventory.chest).is_empty() then
|
||||
if (math.floor(player.position.x) ~= math.floor(entity.position.x)) or (math.floor(player.position.y) ~= math.floor(entity.position.y)) then
|
||||
table.insert(tiles_to_make, {name='water-mud', position=entity.position})
|
||||
entity.destroy()
|
||||
else
|
||||
player.print{'expcom-waterfill.waterfill-distance'}
|
||||
end
|
||||
end
|
||||
|
||||
clf_exp = clf_exp - 1
|
||||
inv.remove({name='cliff-explosives', count=1})
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
event.surface.set_tiles(tiles_to_make)
|
||||
end)
|
||||
Reference in New Issue
Block a user