You've already forked ComfyFactorio
mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-11-25 22:32:18 +02:00
Small commands refactor
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
---@diagnostic disable: deprecated
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local Modifiers = require 'utils.player_modifiers'
|
||||
local Server = require 'utils.server'
|
||||
@@ -8,6 +9,7 @@ local BottomFrame = require 'utils.gui.bottom_frame'
|
||||
local Gui = require 'utils.gui'
|
||||
local SpamProtection = require 'utils.spam_protection'
|
||||
local Discord = require 'utils.discord_handler'
|
||||
local Commands = require 'utils.commands'
|
||||
|
||||
local this = {
|
||||
players = {},
|
||||
@@ -16,7 +18,7 @@ local this = {
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(t)
|
||||
function (t)
|
||||
this = t
|
||||
end
|
||||
)
|
||||
@@ -25,352 +27,254 @@ local Public = {}
|
||||
|
||||
local clear_corpse_button_name = Gui.uid_name()
|
||||
|
||||
commands.add_command(
|
||||
'spaghetti',
|
||||
'Does spaghett.',
|
||||
function(cmd)
|
||||
local player = game.player
|
||||
local param = tostring(cmd.parameter)
|
||||
local force = game.forces['player']
|
||||
Commands.new('playtime', 'Fetches a player total playtime or nil.')
|
||||
:require_backend()
|
||||
:add_parameter('target', false, 'string')
|
||||
:callback(
|
||||
function (player, target)
|
||||
Session.get_and_print_to_player(player, target)
|
||||
end
|
||||
)
|
||||
|
||||
if not (player and player.valid) then
|
||||
return
|
||||
end
|
||||
local p = player.print
|
||||
if not player.admin then
|
||||
p("[ERROR] You're not admin!", Color.fail)
|
||||
return
|
||||
end
|
||||
|
||||
if param == nil then
|
||||
player.print('[ERROR] Arguments are true/false', Color.yellow)
|
||||
return
|
||||
Commands.new('refresh', 'Reloads game script')
|
||||
:require_admin()
|
||||
:callback(
|
||||
function ()
|
||||
game.print('Reloading game script...', Color.warning)
|
||||
Server.to_discord_bold('Reloading game script...')
|
||||
game.reload_script()
|
||||
end
|
||||
if param == 'true' then
|
||||
if not this.spaghetti_are_you_sure then
|
||||
this.spaghetti_are_you_sure = true
|
||||
player.print('Spaghetti is not enabled, run this command again to enable spaghett', Color.yellow)
|
||||
return
|
||||
end
|
||||
if this.spaghetti_enabled then
|
||||
player.print('Spaghetti is already enabled.', Color.yellow)
|
||||
return
|
||||
end
|
||||
game.print('The world has been spaghettified!', Color.success)
|
||||
force.technologies['logistic-system'].enabled = false
|
||||
force.technologies['construction-robotics'].enabled = false
|
||||
force.technologies['logistic-robotics'].enabled = false
|
||||
force.technologies['robotics'].enabled = false
|
||||
force.technologies['personal-roboport-equipment'].enabled = false
|
||||
force.technologies['personal-roboport-mk2-equipment'].enabled = false
|
||||
force.technologies['character-logistic-trash-slots-1'].enabled = false
|
||||
force.technologies['character-logistic-trash-slots-2'].enabled = false
|
||||
force.technologies['auto-character-logistic-trash-slots'].enabled = false
|
||||
force.technologies['worker-robots-storage-1'].enabled = false
|
||||
force.technologies['worker-robots-storage-2'].enabled = false
|
||||
force.technologies['worker-robots-storage-3'].enabled = false
|
||||
force.technologies['character-logistic-slots-1'].enabled = false
|
||||
force.technologies['character-logistic-slots-2'].enabled = false
|
||||
force.technologies['character-logistic-slots-3'].enabled = false
|
||||
force.technologies['character-logistic-slots-4'].enabled = false
|
||||
force.technologies['character-logistic-slots-5'].enabled = false
|
||||
force.technologies['character-logistic-slots-6'].enabled = false
|
||||
force.technologies['worker-robots-speed-1'].enabled = false
|
||||
force.technologies['worker-robots-speed-2'].enabled = false
|
||||
force.technologies['worker-robots-speed-3'].enabled = false
|
||||
force.technologies['worker-robots-speed-4'].enabled = false
|
||||
force.technologies['worker-robots-speed-5'].enabled = false
|
||||
force.technologies['worker-robots-speed-6'].enabled = false
|
||||
this.spaghetti_enabled = true
|
||||
elseif param == 'false' then
|
||||
if this.spaghetti_enabled == false or this.spaghetti_enabled == nil then
|
||||
player.print('Spaghetti is already disabled.', Color.yellow)
|
||||
return
|
||||
end
|
||||
game.print('The world is no longer spaghett!', Color.yellow)
|
||||
force.technologies['logistic-system'].enabled = true
|
||||
force.technologies['construction-robotics'].enabled = true
|
||||
force.technologies['logistic-robotics'].enabled = true
|
||||
force.technologies['robotics'].enabled = true
|
||||
force.technologies['personal-roboport-equipment'].enabled = true
|
||||
force.technologies['personal-roboport-mk2-equipment'].enabled = true
|
||||
force.technologies['character-logistic-trash-slots-1'].enabled = true
|
||||
force.technologies['character-logistic-trash-slots-2'].enabled = true
|
||||
force.technologies['auto-character-logistic-trash-slots'].enabled = true
|
||||
force.technologies['worker-robots-storage-1'].enabled = true
|
||||
force.technologies['worker-robots-storage-2'].enabled = true
|
||||
force.technologies['worker-robots-storage-3'].enabled = true
|
||||
force.technologies['character-logistic-slots-1'].enabled = true
|
||||
force.technologies['character-logistic-slots-2'].enabled = true
|
||||
force.technologies['character-logistic-slots-3'].enabled = true
|
||||
force.technologies['character-logistic-slots-4'].enabled = true
|
||||
force.technologies['character-logistic-slots-5'].enabled = true
|
||||
force.technologies['character-logistic-slots-6'].enabled = true
|
||||
force.technologies['worker-robots-speed-1'].enabled = true
|
||||
force.technologies['worker-robots-speed-2'].enabled = true
|
||||
force.technologies['worker-robots-speed-3'].enabled = true
|
||||
force.technologies['worker-robots-speed-4'].enabled = true
|
||||
force.technologies['worker-robots-speed-5'].enabled = true
|
||||
force.technologies['worker-robots-speed-6'].enabled = true
|
||||
this.spaghetti_enabled = false
|
||||
end
|
||||
end
|
||||
)
|
||||
)
|
||||
|
||||
commands.add_command(
|
||||
'generate_map',
|
||||
'Pregenerates map.',
|
||||
function(cmd)
|
||||
local player = game.player
|
||||
local param = tonumber(cmd.parameter)
|
||||
|
||||
if not (player and player.valid) then
|
||||
return
|
||||
end
|
||||
|
||||
local p = player.print
|
||||
if not player.admin then
|
||||
p("[ERROR] You're not admin!", Color.fail)
|
||||
return
|
||||
end
|
||||
if param == nil then
|
||||
player.print('[ERROR] Must specify radius!', Color.fail)
|
||||
return
|
||||
end
|
||||
if param > 50 then
|
||||
player.print('[ERROR] Value is too big.', Color.fail)
|
||||
return
|
||||
end
|
||||
|
||||
if not this.generate_map then
|
||||
this.generate_map = true
|
||||
player.print('[WARNING] This command will make the server LAG, run this command again if you really want to do this!', Color.yellow)
|
||||
return
|
||||
end
|
||||
local radius = param
|
||||
local surface = game.players[1].surface
|
||||
if surface.is_chunk_generated({radius, radius}) then
|
||||
game.print('Map generation done!', Color.success)
|
||||
this.generate_map = nil
|
||||
return
|
||||
end
|
||||
surface.request_to_generate_chunks({0, 0}, radius)
|
||||
surface.force_generate_chunk_requests()
|
||||
for _, pl in pairs(game.connected_players) do
|
||||
pl.play_sound {path = 'utility/new_objective', volume_modifier = 1}
|
||||
end
|
||||
game.print('Map generation done!', Color.success)
|
||||
this.generate_map = nil
|
||||
end
|
||||
)
|
||||
|
||||
commands.add_command(
|
||||
'repair',
|
||||
'Revives all ghost entities.',
|
||||
function(cmd)
|
||||
local player = game.player
|
||||
local param = tonumber(cmd.parameter)
|
||||
|
||||
if not (player and player.valid) then
|
||||
return
|
||||
end
|
||||
|
||||
local p = player.print
|
||||
if not player.admin then
|
||||
p("[ERROR] You're not admin!", Color.fail)
|
||||
return
|
||||
end
|
||||
|
||||
if param == nil then
|
||||
player.print('[ERROR] Must specify radius!', Color.fail)
|
||||
return
|
||||
end
|
||||
if param > 50 then
|
||||
player.print('[ERROR] Value is too big.', Color.fail)
|
||||
return
|
||||
end
|
||||
|
||||
if not this.revive_warning then
|
||||
this.revive_warning = true
|
||||
player.print('[WARNING] This command will revive all the ghost entities in the given radius, run this command again if you really want to do this!', Color.yellow)
|
||||
return
|
||||
end
|
||||
|
||||
local radius = {{x = (player.position.x + -param), y = (player.position.y + -param)}, {x = (player.position.x + param), y = (player.position.y + param)}}
|
||||
|
||||
local c = 0
|
||||
for _, v in pairs(player.surface.find_entities_filtered {type = 'entity-ghost', area = radius}) do
|
||||
if v and v.valid then
|
||||
c = c + 1
|
||||
v.silent_revive()
|
||||
Commands.new('spaghetti', 'Toggle between disabling bots.')
|
||||
:require_admin()
|
||||
:require_validation()
|
||||
:is_activated()
|
||||
:add_parameter('true/false', true, 'boolean')
|
||||
:callback(
|
||||
function (player, args)
|
||||
local force = player.force
|
||||
if args == 'true' then
|
||||
game.print('The world has been spaghettified!', Color.success)
|
||||
force.technologies['logistic-system'].enabled = false
|
||||
force.technologies['construction-robotics'].enabled = false
|
||||
force.technologies['logistic-robotics'].enabled = false
|
||||
force.technologies['robotics'].enabled = false
|
||||
force.technologies['personal-roboport-equipment'].enabled = false
|
||||
force.technologies['personal-roboport-mk2-equipment'].enabled = false
|
||||
force.technologies['worker-robots-storage-1'].enabled = false
|
||||
force.technologies['worker-robots-storage-2'].enabled = false
|
||||
force.technologies['worker-robots-storage-3'].enabled = false
|
||||
force.technologies['worker-robots-speed-1'].enabled = false
|
||||
force.technologies['worker-robots-speed-2'].enabled = false
|
||||
force.technologies['worker-robots-speed-3'].enabled = false
|
||||
force.technologies['worker-robots-speed-4'].enabled = false
|
||||
force.technologies['worker-robots-speed-5'].enabled = false
|
||||
force.technologies['worker-robots-speed-6'].enabled = false
|
||||
this.spaghetti_enabled = true
|
||||
elseif args == 'false' then
|
||||
game.print('The world is no longer spaghett!', Color.yellow)
|
||||
force.technologies['logistic-system'].enabled = true
|
||||
force.technologies['construction-robotics'].enabled = true
|
||||
force.technologies['logistic-robotics'].enabled = true
|
||||
force.technologies['robotics'].enabled = true
|
||||
force.technologies['personal-roboport-equipment'].enabled = true
|
||||
force.technologies['personal-roboport-mk2-equipment'].enabled = true
|
||||
force.technologies['worker-robots-storage-1'].enabled = true
|
||||
force.technologies['worker-robots-storage-2'].enabled = true
|
||||
force.technologies['worker-robots-storage-3'].enabled = true
|
||||
force.technologies['worker-robots-speed-1'].enabled = true
|
||||
force.technologies['worker-robots-speed-2'].enabled = true
|
||||
force.technologies['worker-robots-speed-3'].enabled = true
|
||||
force.technologies['worker-robots-speed-4'].enabled = true
|
||||
force.technologies['worker-robots-speed-5'].enabled = true
|
||||
force.technologies['worker-robots-speed-6'].enabled = true
|
||||
this.spaghetti_enabled = false
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
if c == 0 then
|
||||
player.print('No entities to repair were found!', Color.warning)
|
||||
this.revive_warning = nil
|
||||
return
|
||||
Commands.new('generate_map', 'Pregenerates map.')
|
||||
:require_admin()
|
||||
:require_validation()
|
||||
:add_parameter('radius', false, 'number')
|
||||
:callback(
|
||||
function (player, args)
|
||||
local radius = args
|
||||
local surface = player.surface
|
||||
if surface.is_chunk_generated({ radius, radius }) then
|
||||
player.print('Map generation done')
|
||||
return true
|
||||
end
|
||||
surface.request_to_generate_chunks({ 0, 0 }, radius)
|
||||
surface.force_generate_chunk_requests()
|
||||
for _, pl in pairs(game.connected_players) do
|
||||
pl.play_sound { path = 'utility/new_objective', volume_modifier = 1 }
|
||||
end
|
||||
player.print('Map generation done')
|
||||
end
|
||||
)
|
||||
|
||||
Discord.send_notification_raw(nil, player.name .. ' repaired ' .. c .. ' entities!')
|
||||
Commands.new('repair', 'Revives all ghost entities.')
|
||||
:require_admin()
|
||||
:require_validation()
|
||||
:add_parameter('1-50', true, 'number')
|
||||
:callback(
|
||||
function (player, args)
|
||||
if args < 1 then
|
||||
player.print('[ERROR] Value is too low.')
|
||||
return false
|
||||
end
|
||||
|
||||
player.play_sound {path = 'utility/new_objective', volume_modifier = 1}
|
||||
player.print('Repaired ' .. c .. ' entities!', Color.success)
|
||||
this.revive_warning = nil
|
||||
end
|
||||
)
|
||||
if args > 50 then
|
||||
player.print('[ERROR] Value is too big.')
|
||||
return false
|
||||
end
|
||||
|
||||
commands.add_command(
|
||||
'dump_layout',
|
||||
'Dump the current map-layout.',
|
||||
function()
|
||||
local player = game.player
|
||||
local radius = { { x = (player.position.x + -args), y = (player.position.y + -args) }, { x = (player.position.x + args), y = (player.position.y + args) } }
|
||||
|
||||
if not (player and player.valid) then
|
||||
return
|
||||
local c = 0
|
||||
for _, v in pairs(player.surface.find_entities_filtered { type = 'entity-ghost', area = radius }) do
|
||||
if v and v.valid then
|
||||
c = c + 1
|
||||
v.silent_revive()
|
||||
end
|
||||
end
|
||||
|
||||
if c == 0 then
|
||||
player.print('No entities to repair were found!')
|
||||
return false
|
||||
end
|
||||
|
||||
Discord.send_notification_raw(nil, player.name .. ' repaired ' .. c .. ' entities!')
|
||||
return 'Repaired ' .. c .. ' entities!'
|
||||
end
|
||||
)
|
||||
|
||||
local p = player.print
|
||||
if not player.admin then
|
||||
p("[ERROR] You're not admin!", Color.warning)
|
||||
return
|
||||
end
|
||||
if not this.dump_layout then
|
||||
this.dump_layout = true
|
||||
player.print('[WARNING] This command will make the server LAG, run this command again if you really want to do this!', Color.yellow)
|
||||
return
|
||||
end
|
||||
local surface = game.players[1].surface
|
||||
game.write_file('layout.lua', '', false)
|
||||
Commands.new('dump_layout', 'Dump the current map-layout.')
|
||||
:require_admin()
|
||||
:require_validation('This will lag the server if ran')
|
||||
:callback(
|
||||
function (player, _)
|
||||
local surface = player.surface
|
||||
game.write_file('layout.lua', '', false)
|
||||
|
||||
local area = {
|
||||
left_top = {x = 0, y = 0},
|
||||
right_bottom = {x = 32, y = 32}
|
||||
}
|
||||
local area = {
|
||||
left_top = { x = 0, y = 0 },
|
||||
right_bottom = { x = 32, y = 32 }
|
||||
}
|
||||
|
||||
local entities = surface.find_entities_filtered {area = area}
|
||||
local tiles = surface.find_tiles_filtered {area = area}
|
||||
local entities = surface.find_entities_filtered { area = area }
|
||||
local tiles = surface.find_tiles_filtered { area = area }
|
||||
|
||||
for _, e in pairs(entities) do
|
||||
local str = '{position = {x = ' .. e.position.x
|
||||
str = str .. ', y = '
|
||||
str = str .. e.position.y
|
||||
str = str .. '}, name = "'
|
||||
str = str .. e.name
|
||||
str = str .. '", direction = '
|
||||
str = str .. tostring(e.direction)
|
||||
str = str .. ', force = "'
|
||||
str = str .. e.force.name
|
||||
str = str .. '"},'
|
||||
if e.name ~= 'character' then
|
||||
for _, e in pairs(entities) do
|
||||
local str = '{position = {x = ' .. e.position.x
|
||||
str = str .. ', y = '
|
||||
str = str .. e.position.y
|
||||
str = str .. '}, name = "'
|
||||
str = str .. e.name
|
||||
str = str .. '", direction = '
|
||||
str = str .. tostring(e.direction)
|
||||
str = str .. ', force = "'
|
||||
str = str .. e.force.name
|
||||
str = str .. '"},'
|
||||
if e.name ~= 'character' then
|
||||
game.write_file('layout.lua', str .. '\n', true)
|
||||
end
|
||||
end
|
||||
|
||||
game.write_file('layout.lua', '\n', true)
|
||||
game.write_file('layout.lua', '\n', true)
|
||||
game.write_file('layout.lua', 'Tiles: \n', true)
|
||||
|
||||
for _, t in pairs(tiles) do
|
||||
local str = '{position = {x = ' .. t.position.x
|
||||
str = str .. ', y = '
|
||||
str = str .. t.position.y
|
||||
str = str .. '}, name = "'
|
||||
str = str .. t.name
|
||||
str = str .. '"},'
|
||||
game.write_file('layout.lua', str .. '\n', true)
|
||||
end
|
||||
return 'Dumped layout as file: layout.lua'
|
||||
end
|
||||
)
|
||||
|
||||
game.write_file('layout.lua', '\n', true)
|
||||
game.write_file('layout.lua', '\n', true)
|
||||
game.write_file('layout.lua', 'Tiles: \n', true)
|
||||
Commands.new('creative', 'Enables creative_mode.')
|
||||
:require_admin()
|
||||
:add_parameter('true/false', false, 'boolean')
|
||||
:require_validation()
|
||||
:is_activated()
|
||||
:callback(
|
||||
function (player, args)
|
||||
local force = player.force
|
||||
if args == 'true' then
|
||||
game.print('[CREATIVE] ' .. player.name .. ' has activated creative-mode!', Color.warning)
|
||||
Server.to_discord_bold(table.concat { '[Creative] ' .. player.name .. ' has activated creative-mode!' })
|
||||
|
||||
for _, t in pairs(tiles) do
|
||||
local str = '{position = {x = ' .. t.position.x
|
||||
str = str .. ', y = '
|
||||
str = str .. t.position.y
|
||||
str = str .. '}, name = "'
|
||||
str = str .. t.name
|
||||
str = str .. '"},'
|
||||
game.write_file('layout.lua', str .. '\n', true)
|
||||
player.print('Dumped layout as file: layout.lua', Color.success)
|
||||
end
|
||||
this.dump_layout = false
|
||||
end
|
||||
)
|
||||
Modifiers.set('creative_enabled', true)
|
||||
|
||||
commands.add_command(
|
||||
'creative',
|
||||
'Enables creative_mode.',
|
||||
function()
|
||||
local player = game.player
|
||||
if not (player and player.valid) then
|
||||
return
|
||||
end
|
||||
this.creative_enabled = true
|
||||
|
||||
local p = player.print
|
||||
if not player.admin then
|
||||
p("[ERROR] You're not admin!", Color.fail)
|
||||
return
|
||||
end
|
||||
if not this.creative_are_you_sure then
|
||||
this.creative_are_you_sure = true
|
||||
player.print('[WARNING] This command will enable creative/cheat-mode for all connected players, run this command again if you really want to do this!', Color.yellow)
|
||||
return
|
||||
end
|
||||
if this.creative_enabled then
|
||||
player.print('[ERROR] Creative/cheat-mode is already active!', Color.fail)
|
||||
return
|
||||
end
|
||||
|
||||
game.print('[CREATIVE] ' .. player.name .. ' has activated creative-mode!', Color.warning)
|
||||
Server.to_discord_bold(table.concat {'[Creative] ' .. player.name .. ' has activated creative-mode!'})
|
||||
|
||||
Modifiers.set('creative_enabled', true)
|
||||
|
||||
player.force.enable_all_prototypes()
|
||||
this.creative_enabled = true
|
||||
this.creative_are_you_sure = false
|
||||
|
||||
for _, _player in pairs(game.connected_players) do
|
||||
if _player.character ~= nil then
|
||||
Public.insert_all_items(_player)
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
commands.add_command(
|
||||
'delete-uncharted-chunks',
|
||||
'Deletes all chunks that are not charted. Can reduce filesize of the savegame. May be unsafe to use in certain custom maps.',
|
||||
function()
|
||||
local player = game.player
|
||||
if not (player and player.valid) then
|
||||
return
|
||||
end
|
||||
|
||||
local p = player.print
|
||||
if not player.admin then
|
||||
p("[ERROR] You're not admin!", Color.fail)
|
||||
return
|
||||
end
|
||||
|
||||
local forces = {}
|
||||
for _, force in pairs(game.forces) do
|
||||
if force.index == 1 or force.index > 3 then
|
||||
table.insert(forces, force)
|
||||
end
|
||||
end
|
||||
|
||||
local is_charted
|
||||
local count = 0
|
||||
for _, surface in pairs(game.surfaces) do
|
||||
for chunk in surface.get_chunks() do
|
||||
is_charted = false
|
||||
for _, force in pairs(forces) do
|
||||
if force.is_chunk_charted(surface, {chunk.x, chunk.y}) then
|
||||
is_charted = true
|
||||
break
|
||||
force.enable_all_prototypes()
|
||||
for _, _player in pairs(game.connected_players) do
|
||||
player.cheat_mode = true
|
||||
if _player.character ~= nil then
|
||||
Public.insert_all_items(_player)
|
||||
end
|
||||
end
|
||||
if not is_charted then
|
||||
surface.delete_chunk({chunk.x, chunk.y})
|
||||
count = count + 1
|
||||
elseif args == 'false' then
|
||||
game.print('[CREATIVE] ' .. player.name .. ' has deactivated creative-mode!', Color.warning)
|
||||
Server.to_discord_bold(table.concat { '[Creative] ' .. player.name .. ' has deactivated creative-mode!' })
|
||||
|
||||
Modifiers.set('creative_enabled', false)
|
||||
|
||||
this.creative_enabled = false
|
||||
|
||||
for _, _player in pairs(game.connected_players) do
|
||||
Public.remove_all_items(player)
|
||||
_player.cheat_mode = false
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
local message = player.name .. ' deleted ' .. count .. ' uncharted chunks!'
|
||||
game.print(message, Color.warning)
|
||||
Server.to_discord_bold(table.concat {message})
|
||||
end
|
||||
)
|
||||
Commands.new('delete_uncharted_chunks', 'Deletes all chunks that are not charted. Can reduce filesize of the savegame. May be unsafe to use in certain custom maps.')
|
||||
:require_admin()
|
||||
:require_validation()
|
||||
:callback(
|
||||
function (player, _)
|
||||
local forces = {}
|
||||
for _, force in pairs(game.forces) do
|
||||
if force.index == 1 or force.index > 3 then
|
||||
table.insert(forces, force)
|
||||
end
|
||||
end
|
||||
|
||||
local is_charted
|
||||
local count = 0
|
||||
for _, surface in pairs(game.surfaces) do
|
||||
for chunk in surface.get_chunks() do
|
||||
is_charted = false
|
||||
for _, force in pairs(forces) do
|
||||
if force.is_chunk_charted(surface, { chunk.x, chunk.y }) then
|
||||
is_charted = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not is_charted then
|
||||
surface.delete_chunk({ chunk.x, chunk.y })
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local message = player.name .. ' deleted ' .. count .. ' uncharted chunks!'
|
||||
game.print(message, Color.warning)
|
||||
Server.to_discord_bold(table.concat { message })
|
||||
end
|
||||
)
|
||||
|
||||
local function clear_corpses(cmd)
|
||||
local player
|
||||
@@ -410,9 +314,9 @@ local function clear_corpses(cmd)
|
||||
|
||||
local i = 0
|
||||
|
||||
local radius = {{x = (pos.x + -param), y = (pos.y + -param)}, {x = (pos.x + param), y = (pos.y + param)}}
|
||||
local radius = { { x = (pos.x + -param), y = (pos.y + -param) }, { x = (pos.x + param), y = (pos.y + param) } }
|
||||
|
||||
for _, entity in pairs(player.surface.find_entities_filtered {area = radius, type = 'corpse'}) do
|
||||
for _, entity in pairs(player.surface.find_entities_filtered { area = radius, type = 'corpse' }) do
|
||||
if entity.corpse_expires then
|
||||
entity.destroy()
|
||||
i = i + 1
|
||||
@@ -433,12 +337,12 @@ end
|
||||
commands.add_command(
|
||||
'clear-corpses',
|
||||
'Clears all the biter corpses..',
|
||||
function(cmd)
|
||||
function (cmd)
|
||||
clear_corpses(cmd)
|
||||
end
|
||||
)
|
||||
|
||||
local on_player_joined_game = function(player)
|
||||
local on_player_joined_game = function (player)
|
||||
Public.insert_all_items(player)
|
||||
end
|
||||
|
||||
@@ -448,7 +352,7 @@ function Public.insert_all_items(player)
|
||||
if player.get_inventory(defines.inventory.character_armor) then
|
||||
player.get_inventory(defines.inventory.character_armor).clear()
|
||||
end
|
||||
player.insert {name = 'power-armor-mk2', count = 1}
|
||||
player.insert { name = 'power-armor-mk2', count = 1 }
|
||||
Modifiers.update_single_modifier(player, 'character_inventory_slots_bonus', 'creative', #game.item_prototypes)
|
||||
Modifiers.update_single_modifier(player, 'character_mining_speed_modifier', 'creative', 150)
|
||||
Modifiers.update_single_modifier(player, 'character_health_bonus', 'creative', 2000)
|
||||
@@ -461,20 +365,20 @@ function Public.insert_all_items(player)
|
||||
|
||||
local p_armor = player.get_inventory(5)[1].grid
|
||||
if p_armor and p_armor.valid then
|
||||
p_armor.put({name = 'fusion-reactor-equipment'})
|
||||
p_armor.put({name = 'fusion-reactor-equipment'})
|
||||
p_armor.put({name = 'fusion-reactor-equipment'})
|
||||
p_armor.put({name = 'exoskeleton-equipment'})
|
||||
p_armor.put({name = 'exoskeleton-equipment'})
|
||||
p_armor.put({name = 'exoskeleton-equipment'})
|
||||
p_armor.put({name = 'energy-shield-mk2-equipment'})
|
||||
p_armor.put({name = 'energy-shield-mk2-equipment'})
|
||||
p_armor.put({name = 'energy-shield-mk2-equipment'})
|
||||
p_armor.put({name = 'energy-shield-mk2-equipment'})
|
||||
p_armor.put({name = 'personal-roboport-mk2-equipment'})
|
||||
p_armor.put({name = 'night-vision-equipment'})
|
||||
p_armor.put({name = 'battery-mk2-equipment'})
|
||||
p_armor.put({name = 'battery-mk2-equipment'})
|
||||
p_armor.put({ name = 'fusion-reactor-equipment' })
|
||||
p_armor.put({ name = 'fusion-reactor-equipment' })
|
||||
p_armor.put({ name = 'fusion-reactor-equipment' })
|
||||
p_armor.put({ name = 'exoskeleton-equipment' })
|
||||
p_armor.put({ name = 'exoskeleton-equipment' })
|
||||
p_armor.put({ name = 'exoskeleton-equipment' })
|
||||
p_armor.put({ name = 'energy-shield-mk2-equipment' })
|
||||
p_armor.put({ name = 'energy-shield-mk2-equipment' })
|
||||
p_armor.put({ name = 'energy-shield-mk2-equipment' })
|
||||
p_armor.put({ name = 'energy-shield-mk2-equipment' })
|
||||
p_armor.put({ name = 'personal-roboport-mk2-equipment' })
|
||||
p_armor.put({ name = 'night-vision-equipment' })
|
||||
p_armor.put({ name = 'battery-mk2-equipment' })
|
||||
p_armor.put({ name = 'battery-mk2-equipment' })
|
||||
end
|
||||
local item = game.item_prototypes
|
||||
local i = 0
|
||||
@@ -482,7 +386,7 @@ function Public.insert_all_items(player)
|
||||
i = i + 1
|
||||
if _k and _v.type ~= 'mining-tool' then
|
||||
player.character_inventory_slots_bonus = Modifiers.get_single_modifier(player, 'character_inventory_slots_bonus', 'creative')
|
||||
player.insert {name = _k, count = _v.stack_size}
|
||||
player.insert { name = _k, count = _v.stack_size }
|
||||
player.print('[CREATIVE] Inserted all base items.', Color.success)
|
||||
end
|
||||
end
|
||||
@@ -490,6 +394,17 @@ function Public.insert_all_items(player)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.remove_all_items(player)
|
||||
if player.character ~= nil then
|
||||
if player.get_inventory(defines.inventory.character_armor) then
|
||||
player.get_inventory(defines.inventory.character_armor).clear()
|
||||
end
|
||||
player.clear_items_inside()
|
||||
Modifiers.reset_player_modifiers(player)
|
||||
this.players[player.index] = nil
|
||||
end
|
||||
end
|
||||
|
||||
local function create_clear_corpse_frame(player, bottom_frame_data)
|
||||
local button
|
||||
|
||||
@@ -498,17 +413,17 @@ local function create_clear_corpse_frame(player, bottom_frame_data)
|
||||
if Gui.get_mod_gui_top_frame() then
|
||||
button =
|
||||
Gui.add_mod_button(
|
||||
player,
|
||||
{
|
||||
type = 'sprite-button',
|
||||
name = clear_corpse_button_name,
|
||||
sprite = 'entity/behemoth-biter',
|
||||
tooltip = {'commands.clear_corpse'},
|
||||
style = Gui.button_style
|
||||
}
|
||||
)
|
||||
player,
|
||||
{
|
||||
type = 'sprite-button',
|
||||
name = clear_corpse_button_name,
|
||||
sprite = 'entity/behemoth-biter',
|
||||
tooltip = { 'commands.clear_corpse' },
|
||||
style = Gui.button_style
|
||||
}
|
||||
)
|
||||
if button then
|
||||
button.style.font_color = {165, 165, 165}
|
||||
button.style.font_color = { 165, 165, 165 }
|
||||
button.style.font = 'heading-3'
|
||||
button.style.minimal_height = 36
|
||||
button.style.maximal_height = 36
|
||||
@@ -523,11 +438,11 @@ local function create_clear_corpse_frame(player, bottom_frame_data)
|
||||
type = 'sprite-button',
|
||||
sprite = 'entity/behemoth-biter',
|
||||
name = clear_corpse_button_name,
|
||||
tooltip = {'commands.clear_corpse'},
|
||||
tooltip = { 'commands.clear_corpse' },
|
||||
style = Gui.button_style
|
||||
}
|
||||
)
|
||||
button.style.font_color = {r = 0.11, g = 0.8, b = 0.44}
|
||||
button.style.font_color = { r = 0.11, g = 0.8, b = 0.44 }
|
||||
button.style.font = 'heading-1'
|
||||
button.style.minimal_height = 40
|
||||
button.style.maximal_width = 40
|
||||
@@ -564,7 +479,7 @@ function Public.set(key, value)
|
||||
end
|
||||
|
||||
Event.on_init(
|
||||
function()
|
||||
function ()
|
||||
Modifiers.set('creative_enabled', false)
|
||||
this.creative_are_you_sure = false
|
||||
this.creative_enabled = false
|
||||
@@ -588,20 +503,20 @@ end
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
function (event)
|
||||
local player = game.players[event.player_index]
|
||||
on_player_joined_game(player)
|
||||
create_clear_corpse_frame(player)
|
||||
|
||||
if this.bottom_button then
|
||||
BottomFrame.add_inner_frame({player = player, element_name = clear_corpse_button_name, tooltip = {'commands.clear_corpse'}, sprite = 'entity/behemoth-biter'})
|
||||
BottomFrame.add_inner_frame({ player = player, element_name = clear_corpse_button_name, tooltip = { 'commands.clear_corpse' }, sprite = 'entity/behemoth-biter' })
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_click(
|
||||
clear_corpse_button_name,
|
||||
function(event)
|
||||
function (event)
|
||||
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Clear Corpse')
|
||||
if is_spamming then
|
||||
return
|
||||
@@ -612,7 +527,7 @@ Gui.on_click(
|
||||
|
||||
Event.add(
|
||||
BottomFrame.events.bottom_quickbar_location_changed,
|
||||
function(event)
|
||||
function (event)
|
||||
local player_index = event.player_index
|
||||
if not player_index then
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user