2017-10-18 11:21:14 -05:00
|
|
|
local marker = {}
|
2018-12-08 02:52:37 +05:30
|
|
|
|
2017-10-18 11:21:14 -05:00
|
|
|
minetest.register_chatcommand("mrkr", {
|
2018-12-08 02:52:37 +05:30
|
|
|
params = "<x> <y> <z>",
|
2017-10-18 11:21:14 -05:00
|
|
|
description = "Adds a waypoint marker at the selected position.",
|
2018-12-08 02:52:37 +05:30
|
|
|
privs = {interact = true},
|
2017-10-18 11:49:20 -05:00
|
|
|
func = function(name, param)
|
|
|
|
local x, y, z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
|
|
|
|
local player = minetest.get_player_by_name(name)
|
2018-12-08 18:04:13 -08:00
|
|
|
|
|
|
|
if (not x or not y or not z) and param ~= "" then
|
2018-12-08 02:52:37 +05:30
|
|
|
return false, "You must provide 3 coordinates!"
|
2018-12-08 18:04:13 -08:00
|
|
|
elseif param == "" then
|
|
|
|
local pos = vector.round(player:get_pos())
|
|
|
|
|
|
|
|
x = pos.x
|
|
|
|
y = pos.y
|
|
|
|
z = pos.z
|
2017-10-18 11:49:20 -05:00
|
|
|
end
|
2018-12-08 02:52:37 +05:30
|
|
|
|
2017-10-18 11:49:20 -05:00
|
|
|
if marker[name] then
|
2018-12-15 12:56:15 -06:00
|
|
|
player:hud_remove(marker[name])
|
|
|
|
marker[name] = nil
|
2017-10-18 11:49:20 -05:00
|
|
|
end
|
2018-12-08 18:04:13 -08:00
|
|
|
|
2018-12-15 12:56:15 -06:00
|
|
|
marker[name] = player:hud_add({
|
|
|
|
hud_elem_type = "waypoint",
|
|
|
|
name = x .. ", " .. y .. ", " .. z,
|
|
|
|
number = 0xFF0000,
|
|
|
|
world_pos = {x = x, y = y, z = z}
|
|
|
|
})
|
|
|
|
|
2018-12-08 18:04:13 -08:00
|
|
|
minetest.chat_send_player(name, "Marker set to: "..x..", "..y..", "..z)
|
2018-12-08 02:52:37 +05:30
|
|
|
return true
|
2017-10-18 11:49:20 -05:00
|
|
|
end
|
|
|
|
})
|
2018-12-08 02:52:37 +05:30
|
|
|
|
2017-10-18 11:21:14 -05:00
|
|
|
minetest.register_chatcommand("clrmrkr", {
|
|
|
|
params = "",
|
|
|
|
description = "Removes the marker waypoint.",
|
|
|
|
privs = {},
|
|
|
|
func = function(name)
|
|
|
|
local player = minetest.get_player_by_name(name)
|
2018-12-08 18:04:13 -08:00
|
|
|
|
2018-12-08 02:52:37 +05:30
|
|
|
if player and marker[name] then
|
2018-12-08 18:04:13 -08:00
|
|
|
player:hud_remove(marker[name])
|
|
|
|
marker[name] = nil
|
|
|
|
minetest.chat_send_player(name, "Marker removed")
|
2017-10-18 11:21:14 -05:00
|
|
|
end
|
2018-12-08 02:52:37 +05:30
|
|
|
return true
|
2017-10-18 11:21:14 -05:00
|
|
|
end
|
2017-10-18 11:49:20 -05:00
|
|
|
})
|
2018-12-08 02:52:37 +05:30
|
|
|
|
|
|
|
minetest.register_chatcommand("marker",
|
|
|
|
minetest.registered_chatcommands["mrkr"])
|
|
|
|
minetest.register_chatcommand("clearmarker",
|
|
|
|
minetest.registered_chatcommands["clrmrkr"])
|
2018-12-15 12:56:15 -06:00
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
marker[player:get_player_name()] = nil
|
|
|
|
end)
|