Minetest-WorldEditAdditions/worldeditadditions_commands/commands/selectors/scol.lua

44 lines
1.5 KiB
Lua
Raw Normal View History

2021-03-09 19:05:03 +00:00
-- ███████ ██████ ██████ ██
-- ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██
-- ██ ██ ██ ██ ██
-- ███████ ██████ ██████ ███████
2021-03-11 04:56:38 +00:00
local wea = worldeditadditions
2021-03-09 19:05:03 +00:00
worldedit.register_command("scol", {
params = "[<axis1>] <length>",
description = "Set WorldEdit region position 2 at a set distance along 1 axis.",
privs = {worldedit=true},
require_pos = 1,
parse = function(params_text)
2021-03-11 04:56:38 +00:00
local vec, tmp = vector.new(0, 0, 0), {}
2021-03-09 19:05:03 +00:00
local find = wea.split(params_text, "%s", false)
2021-03-09 19:19:47 +00:00
local ax1, sn1, len = (tostring(find[1]):match('[xyz]') or "g"):sub(1,1), wea.getsign(find[1]), find[table.maxn(find)]
2021-03-09 19:05:03 +00:00
2021-03-09 19:19:47 +00:00
tmp.len = tonumber(len)
-- If len == nil cancel the operation
2021-03-10 21:21:33 +00:00
if not tmp.len then return false, "No length specified." end
2021-03-09 19:19:47 +00:00
-- If ax1 is bad send "get" order
if ax1 == "g" then tmp.get = true
else vec[ax1] = sn1 * tmp.len end
2021-03-09 19:05:03 +00:00
2021-03-09 19:19:47 +00:00
return true, vec, tmp
2021-03-09 19:05:03 +00:00
end,
2021-03-09 19:19:47 +00:00
func = function(name, vec, tmp)
if tmp.get then
2021-03-11 04:56:38 +00:00
local ax, dir = wea.player_axis2d(name)
2021-03-09 19:19:47 +00:00
vec[ax] = tmp.len * dir
2021-03-09 19:05:03 +00:00
end
2021-03-09 19:19:47 +00:00
local p2 = vector.add(vec,worldedit.pos1[name])
2021-03-09 19:05:03 +00:00
worldedit.pos2[name] = p2
worldedit.mark_pos2(name)
return true, "position 2 set to " .. minetest.pos_to_string(p2)
end,
})
-- Tests
-- /multi //fp set1 -63 19 -20 //scol 5
-- lua print(worldedit.player_axis(myname))
-- tonumber(('y1'):gsub('[xyz]',''):sub(1,2))