2018-05-24 16:16:38 +02:00
|
|
|
local Task = require 'utils.Task'
|
|
|
|
local Event = require 'utils.event'
|
|
|
|
local Token = require 'utils.global_token'
|
2018-11-11 09:20:07 +02:00
|
|
|
local UserGroups = require 'features.user_groups'
|
2018-06-04 17:35:18 +02:00
|
|
|
local Utils = require 'utils.utils'
|
2018-09-23 00:25:13 +02:00
|
|
|
local Game = require 'utils.game'
|
2018-11-11 23:18:46 +02:00
|
|
|
local Report = require 'features.report'
|
|
|
|
|
2018-11-11 09:20:07 +02:00
|
|
|
--local Antigrief = require 'features.antigrief'
|
2017-07-23 14:51:20 +02:00
|
|
|
|
2017-09-03 12:29:19 +02:00
|
|
|
local function invoke(cmd)
|
2018-05-23 19:29:35 +02:00
|
|
|
if not (game.player and game.player.admin) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2017-07-06 19:37:57 +02:00
|
|
|
return
|
|
|
|
end
|
2018-05-24 16:16:38 +02:00
|
|
|
local target = cmd['parameter']
|
2018-09-23 12:46:58 +02:00
|
|
|
if target == nil or game.players[target] == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Unknown player.')
|
2017-07-08 20:58:45 +02:00
|
|
|
return
|
2017-07-06 19:37:57 +02:00
|
|
|
end
|
2018-05-24 16:16:38 +02:00
|
|
|
local pos = game.player.surface.find_non_colliding_position('player', game.player.position, 0, 1)
|
2018-09-23 12:46:58 +02:00
|
|
|
game.players[target].teleport({pos.x, pos.y}, game.player.surface)
|
2018-05-24 16:16:38 +02:00
|
|
|
game.print(target .. ', get your ass over here!')
|
2017-07-06 19:37:57 +02:00
|
|
|
end
|
|
|
|
|
2017-09-03 12:29:19 +02:00
|
|
|
local function teleport_player(cmd)
|
2018-05-23 19:29:35 +02:00
|
|
|
if not (game.player and game.player.admin) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2017-07-06 19:37:57 +02:00
|
|
|
return
|
|
|
|
end
|
2018-05-24 16:16:38 +02:00
|
|
|
local target = cmd['parameter']
|
2018-09-23 12:46:58 +02:00
|
|
|
if target == nil or game.players[target] == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Unknown player.')
|
2017-07-08 20:58:45 +02:00
|
|
|
return
|
2017-07-06 19:37:57 +02:00
|
|
|
end
|
2018-09-23 12:46:58 +02:00
|
|
|
local surface = game.players[target].surface
|
|
|
|
local pos = surface.find_non_colliding_position('player', game.players[target].position, 0, 1)
|
2017-10-26 10:55:02 +02:00
|
|
|
game.player.teleport(pos, surface)
|
2017-07-06 19:37:57 +02:00
|
|
|
game.print(target .. "! watcha doin'?!")
|
|
|
|
end
|
|
|
|
|
2017-09-03 12:29:19 +02:00
|
|
|
local function teleport_location(cmd)
|
2018-05-23 19:29:35 +02:00
|
|
|
if not (game.player and game.player.admin) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2017-07-06 19:37:57 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if game.player.selected == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Nothing selected.')
|
2017-07-06 19:37:57 +02:00
|
|
|
return
|
|
|
|
end
|
2018-05-24 16:16:38 +02:00
|
|
|
local pos = game.player.surface.find_non_colliding_position('player', game.player.selected.position, 0, 1)
|
2017-10-26 10:55:02 +02:00
|
|
|
game.player.teleport(pos)
|
2017-07-06 19:37:57 +02:00
|
|
|
end
|
|
|
|
|
2018-07-01 15:19:19 +02:00
|
|
|
local function do_fish_kill(player, suicide)
|
2018-06-29 13:18:14 +02:00
|
|
|
local c = player.character
|
|
|
|
if not c then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local e = player.surface.create_entity {name = 'fish', position = player.position}
|
|
|
|
c.die(player.force, e)
|
|
|
|
|
2018-07-01 15:19:19 +02:00
|
|
|
-- Don't want people killing themselves for free fish.
|
|
|
|
if suicide then
|
|
|
|
e.destroy()
|
|
|
|
end
|
|
|
|
|
2018-06-29 13:18:14 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function kill(cmd)
|
|
|
|
local player = game.player
|
|
|
|
local param = cmd.parameter
|
|
|
|
local target
|
|
|
|
if param then
|
2018-09-23 12:46:58 +02:00
|
|
|
target = game.players[param]
|
2018-06-29 13:18:14 +02:00
|
|
|
if not target then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(table.concat {"Sorry, player '", param, "' was not found."})
|
2018-06-29 13:18:14 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not target and player then
|
2018-07-01 15:19:19 +02:00
|
|
|
if not do_fish_kill(player, true) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print("Sorry, you don't have a character to kill.")
|
2018-06-29 13:18:14 +02:00
|
|
|
end
|
|
|
|
elseif player then
|
|
|
|
if target == player then
|
2018-07-01 15:19:19 +02:00
|
|
|
if not do_fish_kill(player, true) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print("Sorry, you don't have a character to kill.")
|
2018-06-29 13:18:14 +02:00
|
|
|
end
|
|
|
|
elseif target and player.admin then
|
2018-07-03 18:24:05 +02:00
|
|
|
if not do_fish_kill(target) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(table.concat {"'Sorry, '", target.name, "' doesn't have a character to kill."})
|
2018-06-29 13:18:14 +02:00
|
|
|
end
|
|
|
|
else
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print("Sorry you don't have permission to use the kill command on other players.")
|
2018-06-29 13:18:14 +02:00
|
|
|
end
|
|
|
|
elseif target then
|
|
|
|
if not do_fish_kill(target) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(table.concat {"'Sorry, '", target.name, "' doesn't have a character to kill."})
|
2018-06-29 13:18:14 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if param then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(table.concat {"Sorry, player '", param, "' was not found."})
|
2018-06-29 13:18:14 +02:00
|
|
|
else
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Usage: /kill <player>')
|
2018-06-29 13:18:14 +02:00
|
|
|
end
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
2017-07-08 20:58:45 +02:00
|
|
|
end
|
2017-07-06 19:37:57 +02:00
|
|
|
|
2017-08-28 01:17:07 +02:00
|
|
|
global.walking = {}
|
2018-05-24 16:16:38 +02:00
|
|
|
|
|
|
|
local custom_commands_return_player =
|
|
|
|
Token.register(
|
|
|
|
function(args)
|
2018-06-07 22:06:48 +02:00
|
|
|
local player = args.player
|
|
|
|
if not player.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
global.walking[player.index] = false
|
2018-06-19 00:29:28 +02:00
|
|
|
|
|
|
|
local walkabout_character = player.character
|
|
|
|
if walkabout_character and walkabout_character.valid then
|
|
|
|
walkabout_character.destroy()
|
|
|
|
end
|
2018-06-07 22:06:48 +02:00
|
|
|
|
|
|
|
local character = args.character
|
2018-05-24 16:16:38 +02:00
|
|
|
if character ~= nil and character.valid then
|
2018-06-07 22:06:48 +02:00
|
|
|
player.character = character
|
2018-05-24 16:16:38 +02:00
|
|
|
else
|
2018-06-07 22:06:48 +02:00
|
|
|
player.create_character()
|
|
|
|
player.teleport(args.position)
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
2018-06-07 22:06:48 +02:00
|
|
|
|
|
|
|
player.force = args.force
|
|
|
|
|
2018-05-24 16:16:38 +02:00
|
|
|
game.print(args.player.name .. ' came back from his walkabout.')
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2017-09-03 12:29:19 +02:00
|
|
|
local function walkabout(cmd)
|
2018-06-04 17:35:18 +02:00
|
|
|
if game.player and not game.player.admin then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local params = {}
|
|
|
|
if cmd.parameter == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Walkabout failed, check /help walkabout.')
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
for param in string.gmatch(cmd.parameter, '%S+') do
|
|
|
|
table.insert(params, param)
|
|
|
|
end
|
|
|
|
local player_name = params[1]
|
|
|
|
local duration = 60
|
|
|
|
if #params > 2 then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Walkabout failed, check /help walkabout.')
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
elseif #params == 2 and tonumber(params[2]) == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(params[2] .. ' is not a number.')
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
elseif #params == 2 and tonumber(params[2]) then
|
|
|
|
duration = tonumber(params[2])
|
|
|
|
end
|
|
|
|
if duration < 15 then
|
|
|
|
duration = 15
|
|
|
|
end
|
|
|
|
|
2018-09-23 12:46:58 +02:00
|
|
|
local player = game.players[player_name]
|
2018-06-07 22:06:48 +02:00
|
|
|
if player == nil or not player.valid or global.walking[player.index] then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(player_name .. ' could not go on a walkabout.')
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local chunks = {}
|
|
|
|
for chunk in player.surface.get_chunks() do
|
|
|
|
table.insert(chunks, chunk)
|
|
|
|
end
|
2017-07-23 14:51:20 +02:00
|
|
|
|
2018-06-07 22:06:48 +02:00
|
|
|
local surface = player.surface
|
|
|
|
local chunk = surface.get_random_chunk()
|
2018-05-24 16:16:38 +02:00
|
|
|
local pos = {x = chunk.x * 32, y = chunk.y * 32}
|
2018-06-07 22:06:48 +02:00
|
|
|
local non_colliding_pos = surface.find_non_colliding_position('player', pos, 100, 1)
|
2018-05-24 16:16:38 +02:00
|
|
|
|
2018-06-18 23:45:11 +02:00
|
|
|
local character = player.character
|
|
|
|
if character and character.valid then
|
|
|
|
character.walking_state = {walking = false}
|
|
|
|
end
|
|
|
|
|
2018-05-24 16:16:38 +02:00
|
|
|
if non_colliding_pos then
|
|
|
|
game.print(player_name .. ' went on a walkabout, to find himself.')
|
|
|
|
Task.set_timeout(
|
|
|
|
duration,
|
2018-06-04 18:21:03 +02:00
|
|
|
custom_commands_return_player,
|
2018-06-07 22:06:48 +02:00
|
|
|
{
|
|
|
|
player = player,
|
|
|
|
force = player.force,
|
|
|
|
position = {x = player.position.x, y = player.position.y},
|
2018-06-18 23:45:11 +02:00
|
|
|
character = character
|
2018-06-07 22:06:48 +02:00
|
|
|
}
|
2018-05-24 16:16:38 +02:00
|
|
|
)
|
|
|
|
player.character = nil
|
|
|
|
player.create_character()
|
|
|
|
player.teleport(non_colliding_pos)
|
2018-06-07 22:06:48 +02:00
|
|
|
player.force = 'neutral'
|
|
|
|
global.walking[player.index] = true
|
2018-05-24 16:16:38 +02:00
|
|
|
else
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Walkabout failed: could not find non colliding position')
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
2017-07-08 23:06:39 +02:00
|
|
|
end
|
2017-07-06 19:37:57 +02:00
|
|
|
|
2017-07-09 15:20:01 +02:00
|
|
|
local function regular(cmd)
|
2018-06-04 17:35:18 +02:00
|
|
|
if game.player and not game.player.admin then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if cmd.parameter == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Command failed. Usage: /regular <promote, demote>, <player>')
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local params = {}
|
|
|
|
for param in string.gmatch(cmd.parameter, '%S+') do
|
|
|
|
table.insert(params, param)
|
|
|
|
end
|
|
|
|
if params[2] == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Command failed. Usage: /regular <promote, demote>, <player>')
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
elseif (params[1] == 'promote') then
|
2018-06-04 17:35:18 +02:00
|
|
|
UserGroups.add_regular(params[2])
|
2018-05-24 16:16:38 +02:00
|
|
|
elseif (params[1] == 'demote') then
|
2018-06-04 17:35:18 +02:00
|
|
|
UserGroups.remove_regular(params[2])
|
2018-05-24 16:16:38 +02:00
|
|
|
else
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Command failed. Usage: /regular <promote, demote>, <player>')
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
2017-07-09 15:20:01 +02:00
|
|
|
end
|
|
|
|
|
2017-07-18 22:53:53 +02:00
|
|
|
local function afk()
|
2018-09-23 00:25:13 +02:00
|
|
|
for _, v in pairs(game.players) do
|
2018-05-24 16:16:38 +02:00
|
|
|
if v.afk_time > 300 then
|
|
|
|
local time = ' '
|
|
|
|
if v.afk_time > 21600 then
|
|
|
|
time = time .. math.floor(v.afk_time / 216000) .. ' hours '
|
|
|
|
end
|
|
|
|
if v.afk_time > 3600 then
|
|
|
|
time = time .. math.floor(v.afk_time / 3600) % 60 .. ' minutes and '
|
|
|
|
end
|
|
|
|
time = time .. math.floor(v.afk_time / 60) % 60 .. ' seconds.'
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(v.name .. ' has been afk for' .. time)
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
|
|
|
end
|
2017-07-18 22:53:53 +02:00
|
|
|
end
|
|
|
|
|
2017-07-25 01:20:59 +02:00
|
|
|
local function follow(cmd)
|
2018-05-24 16:16:38 +02:00
|
|
|
if not game.player then
|
|
|
|
log("<Server can't do that.")
|
|
|
|
return
|
|
|
|
end
|
2018-09-23 12:46:58 +02:00
|
|
|
if cmd.parameter ~= nil and game.players[cmd.parameter] ~= nil then
|
2018-05-24 16:16:38 +02:00
|
|
|
global.follows[game.player.name] = cmd.parameter
|
|
|
|
global.follows.n_entries = global.follows.n_entries + 1
|
|
|
|
else
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Usage: /follow <player> makes you follow the player. Use /unfollow to stop following a player.')
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
2017-07-25 01:20:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function unfollow(cmd)
|
2018-05-24 16:16:38 +02:00
|
|
|
if not game.player then
|
|
|
|
log("<Server can't do that.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if global.follows[game.player.name] ~= nil then
|
|
|
|
global.follows[game.player.name] = nil
|
|
|
|
global.follows.n_entries = global.follows.n_entries - 1
|
|
|
|
end
|
2017-07-25 01:20:59 +02:00
|
|
|
end
|
2017-07-21 01:29:49 +02:00
|
|
|
|
2017-08-19 07:41:58 +02:00
|
|
|
global.tp_players = {}
|
2017-08-18 03:04:29 +02:00
|
|
|
local function built_entity(event)
|
2018-05-24 16:16:38 +02:00
|
|
|
local index = event.player_index
|
2017-08-18 03:04:29 +02:00
|
|
|
|
2018-05-24 16:16:38 +02:00
|
|
|
if global.tp_players[index] then
|
|
|
|
local entity = event.created_entity
|
2017-08-18 03:04:29 +02:00
|
|
|
|
2018-06-04 17:35:18 +02:00
|
|
|
if not entity or not entity.valid or entity.type ~= 'entity-ghost' then
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
2017-09-02 14:31:01 +02:00
|
|
|
|
2018-09-23 12:46:58 +02:00
|
|
|
Game.get_player_by_index(index).teleport(entity.position)
|
2018-05-24 16:16:38 +02:00
|
|
|
entity.destroy()
|
|
|
|
end
|
2017-08-18 03:04:29 +02:00
|
|
|
end
|
|
|
|
|
2018-04-06 21:58:50 +02:00
|
|
|
Event.add(defines.events.on_built_entity, built_entity)
|
2017-08-19 07:41:58 +02:00
|
|
|
|
2017-08-26 13:32:49 +02:00
|
|
|
local function toggle_tp_mode(cmd)
|
2018-06-04 17:35:18 +02:00
|
|
|
if not (game.player and game.player.admin) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local index = game.player.index
|
|
|
|
local toggled = global.tp_players[index]
|
|
|
|
|
|
|
|
if toggled then
|
|
|
|
global.tp_players[index] = nil
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('tp mode is now off')
|
2018-05-24 16:16:38 +02:00
|
|
|
else
|
|
|
|
global.tp_players[index] = true
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('tp mode is now on - place a ghost entity to teleport there.')
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
2017-08-18 03:04:29 +02:00
|
|
|
end
|
|
|
|
|
2018-06-04 18:21:03 +02:00
|
|
|
local function get_group()
|
|
|
|
local group = game.permissions.get_group('Banned')
|
|
|
|
if not group then
|
|
|
|
game.permissions.create_group('Banned')
|
|
|
|
group = game.permissions.get_group('Banned')
|
|
|
|
if group then
|
|
|
|
for i = 2, 174 do
|
|
|
|
group.set_allows_action(i, false)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
game.print(
|
|
|
|
'This would have nearly crashed the server, please consult the next best scenario dev (valansch or TWLtriston).'
|
|
|
|
)
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
|
|
|
end
|
2018-06-04 18:21:03 +02:00
|
|
|
return group
|
|
|
|
end
|
|
|
|
|
2018-05-24 16:16:38 +02:00
|
|
|
local custom_commands_untempban =
|
|
|
|
Token.register(
|
|
|
|
function(param)
|
|
|
|
game.print(param.name .. ' is out of timeout.')
|
|
|
|
game.permissions.get_group('Default').add_player(param.name)
|
|
|
|
end
|
|
|
|
)
|
2017-11-12 16:49:28 +02:00
|
|
|
|
2018-05-24 16:16:38 +02:00
|
|
|
local function tempban(cmd)
|
2018-06-04 18:21:03 +02:00
|
|
|
if (not game.player) or not game.player.admin then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if cmd.parameter == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.')
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local params = {}
|
|
|
|
for param in string.gmatch(cmd.parameter, '%S+') do
|
|
|
|
table.insert(params, param)
|
|
|
|
end
|
|
|
|
if #params < 2 or not tonumber(params[2]) then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.')
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
2018-09-23 12:46:58 +02:00
|
|
|
if not game.players[params[1]] then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print("Player doesn't exist.")
|
2018-05-24 16:16:38 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local group = get_group()
|
2018-06-04 18:21:03 +02:00
|
|
|
|
|
|
|
game.print(Utils.get_actor() .. ' put ' .. params[1] .. ' in timeout for ' .. params[2] .. ' minutes.')
|
2018-05-24 16:16:38 +02:00
|
|
|
if group then
|
|
|
|
group.add_player(params[1])
|
|
|
|
if not tonumber(cmd.parameter) then
|
|
|
|
Task.set_timeout(60 * tonumber(params[2]), custom_commands_untempban, {name = params[1]})
|
|
|
|
end
|
|
|
|
end
|
2017-11-12 16:49:28 +02:00
|
|
|
end
|
|
|
|
|
2018-05-24 16:16:38 +02:00
|
|
|
local custom_commands_replace_ghosts =
|
|
|
|
Token.register(
|
|
|
|
function(param)
|
|
|
|
for _, ghost in pairs(param.ghosts) do
|
|
|
|
local new_ghost =
|
|
|
|
game.surfaces[param.surface_index].create_entity {
|
|
|
|
name = 'entity-ghost',
|
|
|
|
position = ghost.position,
|
|
|
|
inner_name = ghost.ghost_name,
|
|
|
|
expires = false,
|
|
|
|
force = 'enemy',
|
|
|
|
direction = ghost.direction
|
|
|
|
}
|
|
|
|
new_ghost.last_user = ghost.last_user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2017-11-12 20:43:51 +02:00
|
|
|
local function zoom(cmd)
|
2018-05-24 16:16:38 +02:00
|
|
|
if game.player and cmd and cmd.parameter and tonumber(cmd.parameter) then
|
|
|
|
game.player.zoom = tonumber(cmd.parameter)
|
|
|
|
end
|
2017-11-12 20:43:51 +02:00
|
|
|
end
|
|
|
|
|
2018-02-26 17:57:47 +02:00
|
|
|
local function pool()
|
2018-05-24 16:16:38 +02:00
|
|
|
if game.player and game.player.admin then
|
|
|
|
local t = {}
|
2018-06-04 18:21:03 +02:00
|
|
|
local p = game.player.position
|
2018-05-24 16:16:38 +02:00
|
|
|
for x = p.x - 3, p.x + 3 do
|
|
|
|
for y = p.y + 2, p.y + 7 do
|
|
|
|
table.insert(t, {name = 'water', position = {x, y}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
game.player.surface.set_tiles(t)
|
|
|
|
game.player.surface.create_entity {name = 'fish', position = {p.x + 0.5, p.y + 5}}
|
|
|
|
end
|
2018-02-26 17:57:47 +02:00
|
|
|
end
|
|
|
|
|
2018-06-25 13:19:50 +02:00
|
|
|
--[[ global.undo_warned_players = {}
|
2018-06-04 23:26:52 +02:00
|
|
|
local function undo(cmd)
|
2018-06-07 22:06:48 +02:00
|
|
|
if (not game.player) or not game.player.admin then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2018-06-07 22:06:48 +02:00
|
|
|
return
|
|
|
|
end
|
2018-09-23 12:46:58 +02:00
|
|
|
if cmd.parameter and game.players[cmd.parameter] then
|
2018-06-07 22:06:48 +02:00
|
|
|
if
|
|
|
|
not global.undo_warned_players[game.player.index] or
|
2018-09-23 12:46:58 +02:00
|
|
|
global.undo_warned_players[game.player.index] ~= game.players[cmd.parameter].index
|
2018-06-07 22:06:48 +02:00
|
|
|
then
|
2018-09-23 12:46:58 +02:00
|
|
|
global.undo_warned_players[game.player.index] = game.players[cmd.parameter].index
|
2018-06-07 22:06:48 +02:00
|
|
|
game.player.print(
|
|
|
|
string.format(
|
|
|
|
'Warning! You are about to remove %s entities and restore %s entities.',
|
2018-09-23 12:46:58 +02:00
|
|
|
#Utils.find_entities_by_last_user(game.players[cmd.parameter], game.surfaces.nauvis),
|
|
|
|
Antigrief.count_removed_entities(game.players[cmd.parameter])
|
2018-06-07 22:06:48 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
game.player.print('To execute the command please run it again.')
|
|
|
|
return
|
|
|
|
end
|
2018-09-23 12:46:58 +02:00
|
|
|
Antigrief.undo(game.players[cmd.parameter])
|
2018-06-07 22:06:48 +02:00
|
|
|
game.print(string.format('Undoing everything %s did...', cmd.parameter))
|
|
|
|
global.undo_warned_players[game.player.index] = nil
|
|
|
|
else
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Usage: /undo <player>')
|
2018-06-07 22:06:48 +02:00
|
|
|
end
|
2018-06-04 23:26:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function antigrief_surface_tp()
|
2018-06-07 22:06:48 +02:00
|
|
|
if (not game.player) or not game.player.admin then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2018-06-07 22:06:48 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
Antigrief.antigrief_surface_tp()
|
2018-06-25 13:19:50 +02:00
|
|
|
end ]]
|
2018-06-08 00:50:45 +02:00
|
|
|
local function find_player(cmd)
|
|
|
|
local player = game.player
|
|
|
|
if not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local name = cmd.parameter
|
|
|
|
if not name then
|
|
|
|
player.print('Usage: /find-player <player>')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-09-23 12:46:58 +02:00
|
|
|
local target = game.players[name]
|
2018-06-08 00:50:45 +02:00
|
|
|
if not target then
|
|
|
|
player.print('player ' .. name .. ' not found')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
target = target.character
|
|
|
|
if not target or not target.valid then
|
|
|
|
player.print('player ' .. name .. ' does not have a character')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-08-18 18:50:30 +02:00
|
|
|
player.add_custom_alert(target, {type = 'virtual', name = 'signal-F'}, name, true)
|
2018-06-08 00:50:45 +02:00
|
|
|
end
|
|
|
|
|
2018-08-07 12:14:03 +02:00
|
|
|
local function jail_player(cmd)
|
|
|
|
|
|
|
|
local player = game.player
|
|
|
|
-- Check if the player can run the command
|
|
|
|
if player and not player.admin then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2018-08-07 12:14:03 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
-- Check if the target is valid
|
|
|
|
local target = cmd['parameter']
|
|
|
|
if target == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Usage: /jail <player>')
|
2018-08-07 12:14:03 +02:00
|
|
|
return
|
|
|
|
end
|
2018-11-12 18:59:25 +02:00
|
|
|
local target = game.players[cmd['parameter']]
|
|
|
|
Report.jail(target, player)
|
2018-08-07 12:14:03 +02:00
|
|
|
end
|
2018-08-08 23:43:37 +02:00
|
|
|
|
2018-08-07 12:14:03 +02:00
|
|
|
local function unjail_player(cmd)
|
|
|
|
local default_group = 'Default'
|
|
|
|
local player = game.player
|
|
|
|
-- Check if the player can run the command
|
|
|
|
if player and not player.admin then
|
2018-11-06 13:55:52 +02:00
|
|
|
Utils.cant_run(cmd.name)
|
2018-08-07 12:14:03 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
-- Check if the target is valid (copied from the invoke command)
|
|
|
|
local target = cmd['parameter']
|
|
|
|
if target == nil then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Usage: /unjail <player>')
|
2018-08-07 12:14:03 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-09-23 12:46:58 +02:00
|
|
|
local target_player = game.players[target]
|
2018-08-07 12:14:03 +02:00
|
|
|
if not target_player then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Unknown player.')
|
2018-08-07 12:14:03 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local permissions = game.permissions
|
|
|
|
|
|
|
|
-- Check if the permission group exists, if it doesn't, create it.
|
|
|
|
local permission_group = permissions.get_group(default_group)
|
|
|
|
if not permission_group then
|
|
|
|
permission_group = permissions.create_group(default_group)
|
|
|
|
end
|
|
|
|
|
2018-08-08 01:20:42 +02:00
|
|
|
local jail_permission_group = permissions.get_group('Jail')
|
|
|
|
if (not jail_permission_group) or target_player.permission_group ~= jail_permission_group then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('The player ' .. target .. ' is already not in Jail.')
|
2018-08-08 01:20:42 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-08-07 12:14:03 +02:00
|
|
|
-- Move player
|
|
|
|
permission_group.add_player(target)
|
2018-10-15 17:51:07 +02:00
|
|
|
-- Set player to a non-shooting state (solves a niche case where players jailed while shooting will be locked into a shooting state)
|
|
|
|
target_player.shooting_state.state = 0
|
2018-08-07 12:14:03 +02:00
|
|
|
|
|
|
|
-- Check that it worked
|
|
|
|
if target_player.permission_group == permission_group then
|
|
|
|
-- Let admin know it worked, let target know what's going on.
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(target .. ' has been returned to the default group. They have been advised of this.')
|
2018-08-07 12:14:03 +02:00
|
|
|
target_player.print('Your ability to perform actions has been restored')
|
|
|
|
else
|
|
|
|
-- Let admin know it didn't work.
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print(
|
2018-08-07 12:14:03 +02:00
|
|
|
'Something went wrong in the unjailing of ' ..
|
|
|
|
target .. '. You can still change their group via /permissions and inform them.'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-24 17:47:03 +02:00
|
|
|
local function all_tech()
|
2018-10-16 15:59:31 +02:00
|
|
|
if game.player then
|
2018-10-15 18:12:30 +02:00
|
|
|
game.player.force.research_all_technologies()
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Your force has been granted all technologies')
|
2018-08-09 20:13:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-22 02:03:04 +02:00
|
|
|
if not _DEBUG then
|
2018-05-24 16:16:38 +02:00
|
|
|
local old_add_command = commands.add_command
|
|
|
|
commands.add_command =
|
|
|
|
function(name, desc, func)
|
|
|
|
old_add_command(
|
|
|
|
name,
|
|
|
|
desc,
|
|
|
|
function(cmd)
|
|
|
|
local success, error = pcall(func, cmd)
|
|
|
|
if not success then
|
|
|
|
log(error)
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Sorry there was an error running ' .. cmd.name)
|
2018-05-24 16:16:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
2018-05-07 14:16:41 +02:00
|
|
|
end
|
|
|
|
|
2018-08-09 00:14:59 +02:00
|
|
|
local function admin_chat(cmd)
|
|
|
|
if not game.player or game.player.admin then --admins AND server
|
2018-09-23 00:25:13 +02:00
|
|
|
for _, p in pairs(game.players) do
|
2018-08-09 00:14:59 +02:00
|
|
|
if p.admin then
|
|
|
|
local tag = ''
|
|
|
|
if game.player.tag and game.player.tag ~= '' then
|
2018-08-10 14:03:18 +02:00
|
|
|
tag = ' ' .. game.player.tag
|
2018-08-09 00:14:59 +02:00
|
|
|
end
|
2018-08-18 13:38:46 +02:00
|
|
|
p.print(string.format('(Admin) %s%s: %s', game.player.name, tag, cmd.parameter), game.player.chat_color)
|
|
|
|
end
|
2018-08-10 19:10:30 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-04 14:09:14 +02:00
|
|
|
local function show_rail_block()
|
|
|
|
local player = game.player
|
|
|
|
if not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local vs = player.game_view_settings
|
|
|
|
local show = not vs.show_rail_block_visualisation
|
|
|
|
vs.show_rail_block_visualisation = show
|
|
|
|
|
|
|
|
player.print('show_rail_block_visualisation set to ' .. tostring(show))
|
|
|
|
end
|
|
|
|
|
2018-05-24 16:16:38 +02:00
|
|
|
commands.add_command('kill', 'Will kill you.', kill)
|
2018-06-04 17:35:18 +02:00
|
|
|
commands.add_command('tpplayer', '<player> - Teleports you to the player. (Admins only)', teleport_player)
|
|
|
|
commands.add_command('invoke', '<player> - Teleports the player to you. (Admins only)', invoke)
|
2018-05-24 16:16:38 +02:00
|
|
|
commands.add_command('tppos', 'Teleports you to a selected entity. (Admins only)', teleport_location)
|
2018-06-04 17:35:18 +02:00
|
|
|
commands.add_command('walkabout', '<player> <duration> - Send someone on a walk. (Admins only)', walkabout)
|
|
|
|
commands.add_command('regulars', 'Prints a list of game regulars.', UserGroups.print_regulars)
|
|
|
|
commands.add_command('regular', '<promote, demote>, <player> Change regular status of a player. (Admins only)', regular)
|
2018-05-24 16:16:38 +02:00
|
|
|
commands.add_command('afk', 'Shows how long players have been afk.', afk)
|
2018-06-07 22:06:48 +02:00
|
|
|
commands.add_command(
|
|
|
|
'follow',
|
|
|
|
'<player> makes you follow the player. Use /unfollow to stop following a player.',
|
|
|
|
follow
|
|
|
|
)
|
2018-05-24 16:16:38 +02:00
|
|
|
commands.add_command('unfollow', 'stops following a player.', unfollow)
|
2018-06-07 22:06:48 +02:00
|
|
|
commands.add_command(
|
|
|
|
'tpmode',
|
|
|
|
'Toggles tp mode. When on place a ghost entity to teleport there (Admins only)',
|
|
|
|
toggle_tp_mode
|
|
|
|
)
|
2018-07-31 12:51:02 +02:00
|
|
|
|
2018-06-04 17:35:18 +02:00
|
|
|
commands.add_command('tempban', '<player> <minutes> Temporarily bans a player (Admins only)', tempban)
|
2018-05-24 16:16:38 +02:00
|
|
|
commands.add_command('zoom', '<number> Sets your zoom.', zoom)
|
2018-10-15 18:12:30 +02:00
|
|
|
if _DEBUG then
|
|
|
|
commands.add_command('all-tech', 'researches all technologies (debug only)', all_tech)
|
|
|
|
end
|
2018-06-07 22:06:48 +02:00
|
|
|
commands.add_command(
|
|
|
|
'hax',
|
2018-08-24 17:47:03 +02:00
|
|
|
'Toggles your hax (makes recipes cost nothing)',
|
2018-06-07 22:06:48 +02:00
|
|
|
function()
|
|
|
|
if game.player and game.player.admin then
|
|
|
|
game.player.cheat_mode = not game.player.cheat_mode
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
2018-05-24 16:16:38 +02:00
|
|
|
commands.add_command('pool', 'Spawns a pool', pool)
|
2018-06-25 13:19:50 +02:00
|
|
|
--[[ commands.add_command('undo', '<player> undoes everything a player has done (Admins only)', undo)
|
2018-06-07 22:06:48 +02:00
|
|
|
commands.add_command(
|
|
|
|
'antigrief_surface',
|
|
|
|
'moves you to the antigrief surface or back (Admins only)',
|
|
|
|
antigrief_surface_tp
|
2018-06-25 13:19:50 +02:00
|
|
|
) ]]
|
2018-06-08 00:50:45 +02:00
|
|
|
commands.add_command('find-player', '<player> shows an alert on the map where the player is located', find_player)
|
2018-08-07 12:14:03 +02:00
|
|
|
commands.add_command(
|
|
|
|
'jail',
|
|
|
|
'<player> disables all actions a player can perform except chatting. (Admins only)',
|
|
|
|
jail_player
|
|
|
|
)
|
|
|
|
commands.add_command(
|
|
|
|
'unjail',
|
|
|
|
'<player> restores ability for a player to perform actions. (Admins only)',
|
|
|
|
unjail_player
|
|
|
|
)
|
2018-08-09 00:14:59 +02:00
|
|
|
commands.add_command('a', 'Admin chat. Messages all other admins (Admins only)', admin_chat)
|
2018-08-15 14:15:03 +02:00
|
|
|
|
2018-08-18 13:38:46 +02:00
|
|
|
|
|
|
|
local function report(cmd)
|
|
|
|
local reporting_player = game.player
|
|
|
|
if reporting_player then
|
|
|
|
local params = {}
|
|
|
|
for param in string.gmatch(cmd.parameter, '%S+') do
|
|
|
|
table.insert(params, param)
|
|
|
|
end
|
|
|
|
if #params < 2 then
|
|
|
|
reporting_player.print('Please enter then name of the offender and the reason for the report.')
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
local reported_player_name = params[1] or ''
|
2018-09-23 12:46:58 +02:00
|
|
|
local reported_player = game.players[reported_player_name]
|
2018-08-18 13:38:46 +02:00
|
|
|
|
|
|
|
if not reported_player then
|
|
|
|
reporting_player.print(reported_player_name .. ' does not exist.')
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
Report.report(reporting_player, reported_player, string.sub(cmd.parameter, string.len(params[1]) + 2))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
commands.add_command('report', '<griefer-name> <message> Reports a user to admins', report)
|
|
|
|
|
|
|
|
commands.add_command(
|
|
|
|
'showreports',
|
|
|
|
'Shows user reports (Admins only)',
|
|
|
|
function(event)
|
|
|
|
if game.player and game.player.admin then
|
2018-09-23 12:46:58 +02:00
|
|
|
Report.show_reports(Game.get_player_by_index(event.player_index))
|
2018-08-15 14:15:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
2018-09-04 14:09:14 +02:00
|
|
|
|
|
|
|
commands.add_command('show-rail-block', 'Toggles rail block visualisation', show_rail_block)
|