Skip to content

Commit

Permalink
Add command to place map barriers without WorldEdit (#1254)
Browse files Browse the repository at this point in the history
* Add `/place_buildtime_barrier`

* Add params

* Fix formatting

* Add outer param

* Add ctf_map:ignore to if

* Oops

* Add ability to remove build-time barriers

* Add warnings
  • Loading branch information
a-blob authored Dec 15, 2023
1 parent bd5c921 commit 266bc48
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions mods/ctf/ctf_map/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,100 @@ minetest.register_chatcommand("map", {
end
})

minetest.register_chatcommand("ctf_barrier", {
description = "Place or remove map barriers\n" ..
"place_buildtime: Within the selected area, replace certain nodes with the " ..
"corresponding build-time barrier\nremove_buildtime: Remove build-time " ..
"barriers within the selected area\nplace_outer: Surrounds the selected area " ..
"with an indestructible glass/stone barrier",
privs = {ctf_map_editor = true},
params = "[place_buildtime] | [remove_buildtime] | [place_outer]",
func = function(name, params)
if not params or params == "" then
return false, "See /help ctf_barrier for usage instructions"
end

if ctf_core.settings.server_mode ~= "mapedit" then
return false, minetest.colorize("red", "You have to be in mapedit mode to run this")
end

if params ~= "place_buildtime" and params ~= "remove_buildtime" and params ~= "place_outer" then
return false
end

if params == "place_outer" then
minetest.chat_send_player(name,
minetest.colorize("yellow", "Warning: this action can't be undone"))
end

ctf_map.get_pos_from_player(name, 2, function(p, positions)
local pos1, pos2 = vector.sort(positions[1], positions[2])

if params == "place_buildtime" and pos1.x ~= pos2.x and pos1.z ~= pos2.z then
minetest.chat_send_player(name, minetest.colorize("yellow",
"Warning: your build-time barrier is more than 1 node thick, " ..
"use /ctf_barrier remove_buildtime to remove unwanted parts"))
end

for x = pos1.x, pos2.x do
for y = pos1.y, pos2.y do
for z = pos1.z, pos2.z do
if params == "place_buildtime" then
local current_pos = {x = x, y = y, z = z}
local current_node = minetest.get_node_or_nil(current_pos)
if current_node then
if current_node.name == "air" then
minetest.set_node(current_pos, {name = "ctf_map:ind_glass_red"})
elseif current_node.name == "default:stone" then
minetest.set_node(current_pos, {name = "ctf_map:ind_stone_red"})
elseif current_node.name == "default:water_source" then
minetest.set_node(current_pos, {name = "ctf_map:ind_water"})
elseif current_node.name == "default:lava_source" then
minetest.set_node(current_pos, {name = "ctf_map:ind_lava"})
end
end
elseif params == "remove_buildtime" then
local current_pos = {x = x, y = y, z = z}
local current_node = minetest.get_node_or_nil(current_pos)
if current_node then
if current_node.name == "ctf_map:ind_glass_red" then
minetest.set_node(current_pos, {name = "air"})
elseif current_node.name == "ctf_map:ind_stone_red" then
minetest.set_node(current_pos, {name = "default:stone"})
elseif current_node.name == "ctf_map:ind_water" then
minetest.set_node(current_pos, {name = "default:water_source"})
elseif current_node.name == "ctf_map:ind_lava" then
minetest.set_node(current_pos, {name = "default:lava_source"})
end
end
elseif params == "place_outer" then
local current_pos = {x = x, y = y, z = z}
if x == pos1.x or x == pos2.x or y == pos1.y
or z == pos1.z or z == pos2.z then
local current_node = minetest.get_node_or_nil(current_pos)
if current_node then
if current_node.name == "air" or
current_node.name == "ctf_map:ignore" or
current_node.name == "ignore" then
minetest.set_node(current_pos, {name = "ctf_map:ind_glass"})
else
minetest.set_node(current_pos, {name = "ctf_map:stone"})
end
end
end
end
end
end
end
local message =
(params == "place_buildtime" and "Build-time barrier placed") or
(params == "remove_buildtime" and "Build-time barrier removed") or
(params == "place_outer" and "Outer barrier placed")
minetest.chat_send_player(name, message)
end)
end
})

-- Attempt to restore user's time speed after server close
local TIME_SPEED = minetest.settings:get("time_speed")

Expand Down

0 comments on commit 266bc48

Please sign in to comment.