mirror of
https://github.com/minetest-mods/areas.git
synced 2025-06-14 15:20:45 +02:00
Accept coordinates separated by commas and spaces
Co-authored-by: lumberJack <lumberjackgames@protonmail.com>
This commit is contained in:
parent
8cb684da30
commit
98d08d01d4
@ -101,10 +101,10 @@ Commands
|
|||||||
* `/area_pos {set,set1,set2,get}` -- Sets the area positions by punching
|
* `/area_pos {set,set1,set2,get}` -- Sets the area positions by punching
|
||||||
nodes or shows the current area positions.
|
nodes or shows the current area positions.
|
||||||
|
|
||||||
* `/area_pos1 [X,Y,Z|X Y Z]` -- Sets area position one to your position or
|
* `/area_pos1 [X,Y,Z|X Y Z|X, Y, Z]` -- Sets area position one to your position or
|
||||||
the one supplied.
|
the one supplied.
|
||||||
|
|
||||||
* `/area_pos2 [X,Y,Z|X Y Z]` -- Sets area position two to your position or
|
* `/area_pos2 [X,Y,Z|X Y Z|X, Y, Z]` -- Sets area position two to your position or
|
||||||
the one supplied.
|
the one supplied.
|
||||||
|
|
||||||
* `/areas_cleanup` -- Removes all ownerless areas.
|
* `/areas_cleanup` -- Removes all ownerless areas.
|
||||||
|
85
pos.lua
85
pos.lua
@ -69,68 +69,53 @@ minetest.register_chatcommand("select_area", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local function area_pos_handler(name, param, nr)
|
||||||
|
local pos
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
if player then
|
||||||
|
pos = vector.round(player:get_pos())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Input parsing
|
||||||
|
local error_msg
|
||||||
|
local found, _, x_str, y_str, z_str = param:find(
|
||||||
|
"^(~?-?%d*)[, ] *(~?-?%d*)[, ] *(~?-?%d*)$")
|
||||||
|
if found then
|
||||||
|
pos, error_msg = parse_relative_pos(x_str, y_str, z_str, pos)
|
||||||
|
elseif param ~= "" then
|
||||||
|
return false, S("Invalid usage, see /help @1.", "area_pos" .. nr)
|
||||||
|
end
|
||||||
|
if not pos then
|
||||||
|
return false, error_msg or S("Unable to get position.")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Assign the position
|
||||||
|
pos = posLimit(vector.round(pos))
|
||||||
|
if nr == 1 then
|
||||||
|
areas:setPos1(name, pos)
|
||||||
|
else
|
||||||
|
areas:setPos2(name, pos)
|
||||||
|
end
|
||||||
|
return true, S("Area position @1 set to @2", tostring(nr),
|
||||||
|
minetest.pos_to_string(pos))
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("area_pos1", {
|
minetest.register_chatcommand("area_pos1", {
|
||||||
params = "[X Y Z|X,Y,Z]",
|
params = "[X Y Z|X,Y,Z|X, Y, Z]",
|
||||||
description = S("Set area protection region position @1 to your"
|
description = S("Set area protection region position @1 to your"
|
||||||
.." location or the one specified", "1"),
|
.." location or the one specified", "1"),
|
||||||
privs = {},
|
privs = {},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local pos
|
return area_pos_handler(name, param, 1)
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
if player then
|
|
||||||
pos = vector.round(player:get_pos())
|
|
||||||
end
|
|
||||||
local found, _, x_str, y_str, z_str = param:find(
|
|
||||||
"^(~?-?%d*)[, ](~?-?%d*)[, ](~?-?%d*)$")
|
|
||||||
if found then
|
|
||||||
local get_pos, reason = parse_relative_pos(x_str, y_str, z_str, pos)
|
|
||||||
if get_pos then
|
|
||||||
pos = get_pos
|
|
||||||
elseif not get_pos and reason then
|
|
||||||
return false, reason
|
|
||||||
end
|
|
||||||
elseif param ~= "" then
|
|
||||||
return false, S("Invalid usage, see /help @1.", "area_pos1")
|
|
||||||
end
|
|
||||||
if not pos then
|
|
||||||
return false, S("Unable to get position.")
|
|
||||||
end
|
|
||||||
pos = posLimit(vector.round(pos))
|
|
||||||
areas:setPos1(name, pos)
|
|
||||||
return true, S("Area position @1 set to @2", "1",
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("area_pos2", {
|
minetest.register_chatcommand("area_pos2", {
|
||||||
params = "[X Y Z|X,Y,Z]",
|
params = "[X Y Z|X,Y,Z|X, Y, Z]",
|
||||||
description = S("Set area protection region position @1 to your"
|
description = S("Set area protection region position @1 to your"
|
||||||
.." location or the one specified", "2"),
|
.." location or the one specified", "2"),
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local pos
|
return area_pos_handler(name, param, 2)
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
if player then
|
|
||||||
pos = vector.round(player:get_pos())
|
|
||||||
end
|
|
||||||
local found, _, x_str, y_str, z_str = param:find(
|
|
||||||
"^(~?-?%d*)[, ](~?-?%d*)[, ](~?-?%d*)$")
|
|
||||||
if found then
|
|
||||||
local get_pos, reason = parse_relative_pos(x_str, y_str, z_str, pos)
|
|
||||||
if get_pos then
|
|
||||||
pos = get_pos
|
|
||||||
elseif not get_pos and reason then
|
|
||||||
return false, reason
|
|
||||||
end
|
|
||||||
elseif param ~= "" then
|
|
||||||
return false, S("Invalid usage, see /help @1.", "area_pos2")
|
|
||||||
end
|
|
||||||
if not pos then
|
|
||||||
return false, S("Unable to get position.")
|
|
||||||
end
|
|
||||||
pos = posLimit(vector.round(pos))
|
|
||||||
areas:setPos2(name, pos)
|
|
||||||
return true, S("Area position @1 set to @2", "2",
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user