1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-30 04:30:58 +02:00

Implemented /undo and /antigrief_surface

This commit is contained in:
Valansch 2018-06-04 23:26:52 +02:00
parent ab18b08c64
commit ee70db72f6
3 changed files with 67 additions and 18 deletions

View File

@ -2,27 +2,23 @@ local Event = require "utils.event"
Event.on_init(function() Event.on_init(function()
global.ag_surface = game.create_surface("antigrief", { autoplace_controls = { coal = { frequency = "normal", richness = "normal", size = "none" }, ["copper-ore"] = { frequency = "normal", richness = "normal", size = "none" }, ["crude-oil"] = { frequency = "normal", richness = "normal", size = "none" }, desert = { frequency = "normal", richness = "normal", size = "none" }, dirt = { frequency = "normal", richness = "normal", size = "none" }, ["enemy-base"] = { frequency = "normal", richness = "normal", size = "none" }, grass = { frequency = "normal", richness = "normal", size = "very-high" }, ["iron-ore"] = { frequency = "normal", richness = "normal", size = "none" }, sand = { frequency = "normal", richness = "normal", size = "none" }, stone = { frequency = "normal", richness = "normal", size = "none" }, trees = { frequency = "normal", richness = "normal", size = "none" }, ["uranium-ore"] = { frequency = "normal", richness = "normal", size = "none" } }, cliff_settings = { cliff_elevation_0 = 1024, cliff_elevation_interval = 10, name = "cliff" }, height = 2000000, peaceful_mode = false, seed = 3461559752, starting_area = "very-low", starting_points = { { x = 0, y = 0 } }, terrain_segmentation = "normal", water = "none", width = 2000000}) global.ag_surface=game.create_surface("antigrief",{autoplace_controls={coal={frequency="normal",richness="normal",size="none"},["copper-ore"]={frequency="normal",richness="normal",size="none"},["crude-oil"]={frequency="normal",richness="normal",size="none"},desert={frequency="normal",richness="normal",size="none"},dirt={frequency="normal",richness="normal",size="none"},["enemy-base"]={frequency="normal",richness="normal",size="none"},grass={frequency="normal",richness="normal",size="very-high"},["iron-ore"]={frequency="normal",richness="normal",size="none"},sand={frequency="normal",richness="normal",size="none"},stone={frequency="normal",richness="normal",size="none"},trees={frequency="normal",richness="normal",size="none"},["uranium-ore"]={frequency="normal",richness="normal",size="none"}},cliff_settings={cliff_elevation_0=1024,cliff_elevation_interval=10,name="cliff"},height=2000000,peaceful_mode=false,seed=3461559752,starting_area="very-low",starting_points={{x=0,y=0}},terrain_segmentation="normal",water="none",width=2000000})
global.ag_surface.always_day = true global.ag_surface.always_day = true
end) end)
local function place_entity_on_surface(entity, surface, replace, player) local function place_entity_on_surface(entity, surface, replace, player)
local new_entity = nil local new_entity = nil
if replace then for _,e in pairs(surface.find_entities_filtered{position = entity.position}) do
for _,e in pairs(surface.find_entities_filtered{position = entity.position}) do if replace or e.type == "entity-ghost" then
e.destroy() e.destroy()
end end
end
if (replace or surface.count_entities_filtered{position = entity.position} == 0) then
new_entity = surface.create_entity{name = entity.name, position = entity.position, force = entity.force, direction = entity.direction} new_entity = surface.create_entity{name = entity.name, position = entity.position, force = entity.force, direction = entity.direction}
if player then if player and new_entity then
new_entity.last_user = player new_entity.last_user = player
end
else
if surface.count_entities_filtered{position = entity.position} == 0 then
new_entity = surface.create_entity{name = entity.name, position = entity.position, force = entity.force, direction = entity.direction}
if player then
new_entity.last_user = player
end
end end
end end
return new_entity return new_entity
@ -73,15 +69,43 @@ end)
local Module = {} local Module = {}
Module.undo = function(player) Module.undo = function(player)
if type(player) == "nil" or type(player) == "string" then return end --No support for strings! local player = player
if type(player) == "nil" or type(player) == "string" then return --No support for strings!
elseif type(player) == "number" then player = game.players[player] end
for _,e in pairs(global.ag_surface.find_entities_filtered{}) do for _,e in pairs(global.ag_surface.find_entities_filtered{}) do
if e.last_user == player or e.last_user.index == player then if e.last_user == player then
place_entity_on_surface(e, game.surfaces.nauvis, false) --Place removed entity IF no collision is detected
for _,f in pairs(global.ag_surface.find_entities_filtered{position = e.position}) do local new_entity = place_entity_on_surface(e, game.surfaces.nauvis, false)
f.destroy() --Transfere items
if new_entity and e.type == "container" then
local items = e.get_inventory(defines.inventory.chest).get_contents()
if items then
for item, n in pairs(items) do
new_entity.insert{name = item, count = n}
end
end
end
end
end
--Remove all items from all surfaces that player placed an entity
for _,surface in pairs(game.surfaces) do
for _,e in pairs(global.ag_surface.find_entities_filtered{force = player.force}) do
if e.last_user == player then
e.destroy()
end end
end end
end end
end end
Module.antigrief_surface_tp = function()
if game.player then
if game.player.surface == global.ag_surface then
game.player.teleport(game.player.position, game.surfaces.nauvis)
else
game.player.teleport(game.player.position, global.ag_surface)
end
end
end
return Module return Module

View File

@ -14,7 +14,6 @@ require 'fish_market'
require 'reactor_meltdown' require 'reactor_meltdown'
require 'map_layout' require 'map_layout'
require 'bot' require 'bot'
require 'antigrief'
-- GUIs the order determines the order they appear at the top. -- GUIs the order determines the order they appear at the top.
require 'info' require 'info'
require 'player_list' require 'player_list'

View File

@ -3,6 +3,7 @@ local Event = require 'utils.event'
local Token = require 'utils.global_token' local Token = require 'utils.global_token'
local UserGroups = require 'user_groups' local UserGroups = require 'user_groups'
local Utils = require 'utils.utils' local Utils = require 'utils.utils'
local Antigrief = require 'antigrief'
function player_print(str) function player_print(str)
if game.player then if game.player then
@ -472,6 +473,28 @@ local function pool()
end end
end end
local function undo(cmd)
if (not game.player) or not game.player.admin then
cant_run(cmd.name)
return
end
--warning
if cmd.parameter and game.players[cmd.parameter] then
Antigrief.undo(game.players[cmd.parameter])
game.print(string.format("Undoing everything %s did...", cmd.parameter))
else
player_print("Usage: /undo <player>")
end
end
local function antigrief_surface_tp()
if (not game.player) or not game.player.admin then
cant_run(cmd.name)
return
end
Antigrief.antigrief_surface_tp()
end
if not _DEBUG then if not _DEBUG then
local old_add_command = commands.add_command local old_add_command = commands.add_command
commands.add_command = commands.add_command =
@ -483,6 +506,7 @@ if not _DEBUG then
local success, error = pcall(func, cmd) local success, error = pcall(func, cmd)
if not success then if not success then
log(error) log(error)
player_print(error)
end end
end end
) )
@ -507,3 +531,5 @@ commands.add_command('zoom', '<number> Sets your zoom.', zoom)
commands.add_command('all-tech', 'researches all technologies', function() if game.player and game.player.admin then game.player.force.research_all_technologies() end end) commands.add_command('all-tech', 'researches all technologies', function() if game.player and game.player.admin then game.player.force.research_all_technologies() end end)
commands.add_command('hax', 'Toggles your hax', function() if game.player and game.player.admin then game.player.cheat_mode = not game.player.cheat_mode end end) commands.add_command('hax', 'Toggles your hax', function() if game.player and game.player.admin then game.player.cheat_mode = not game.player.cheat_mode end end)
commands.add_command('pool', 'Spawns a pool', pool) commands.add_command('pool', 'Spawns a pool', pool)
commands.add_command('undo', '<player> undoes everything a player has done (Admins only)', undo)
commands.add_command('antigrief_surface', 'move you to the antigrief surface or back', antigrief_surface_tp)