Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow relative coordinates in /area_pos[12] #77

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions pos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,28 @@ minetest.register_chatcommand("area_pos1", {
privs = {},
func = function(name, param)
local pos
local found, _, x, y, z = param:find(
"^(-?%d+)[, ](-?%d+)[, ](-?%d+)$")
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
pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
elseif param == "" then
local player = minetest.get_player_by_name(name)
if player then
pos = player:get_pos()
else
return false, S("Unable to get position.")
local x = pos and minetest.parse_relative_number(x_str, pos.x)
Emojigit marked this conversation as resolved.
Show resolved Hide resolved
or tonumber(x_str)
local y = pos and minetest.parse_relative_number(y_str, pos.y)
or tonumber(y_str)
local z = pos and minetest.parse_relative_number(z_str, pos.z)
or tonumber(z_str)
if x and y and z then
pos = { x = x, y = y, z = z }
end
else
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",
Expand All @@ -74,20 +82,28 @@ minetest.register_chatcommand("area_pos2", {
.." location or the one specified", "2"),
func = function(name, param)
local pos
local found, _, x, y, z = param:find(
"^(-?%d+)[, ](-?%d+)[, ](-?%d+)$")
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
pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
elseif param == "" then
local player = minetest.get_player_by_name(name)
if player then
pos = player:get_pos()
else
return false, S("Unable to get position.")
local x = pos and minetest.parse_relative_number(x_str, pos.x)
or tonumber(x_str)
local y = pos and minetest.parse_relative_number(y_str, pos.y)
or tonumber(y_str)
local z = pos and minetest.parse_relative_number(z_str, pos.z)
or tonumber(z_str)
if x and y and z then
pos = { x = x, y = y, z = z }
end
else
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",
Expand Down
Loading