48 lines
2.8 KiB
Lua
48 lines
2.8 KiB
Lua
local player_waypoints = {}
|
|
|
|
minetest.register_tool("waypoint_compass:compass", {
|
|
description = "Waypoint compass",
|
|
inventory_image = "Waypoint_compass_inventory_image.png",
|
|
-- Display HUD waypoint on use
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
if not itemstack then
|
|
return nil
|
|
end
|
|
local meta = itemstack:get_meta()
|
|
local waypoint_id = meta:get_string("waypoint_compass:id")
|
|
if user and user:is_player() then
|
|
local player = user
|
|
local player_name = player:get_player_name()
|
|
if (player_waypoints[player_name] and
|
|
player_waypoints[player_name][waypoint_id]) then
|
|
-- Waypoint is currently displayed, remove it
|
|
local hud_id = player_waypoints[player_name][waypoint_id]
|
|
print("hud_id remove", hud_id)
|
|
player_waypoints[player_name][waypoint_id] = nil
|
|
player:hud_remove(hud_id)
|
|
else
|
|
-- Show this waypoint
|
|
local waypoint_name = meta:get_string("waypoint_compass:name") ~= "" or "destination"
|
|
local hud_id = player:hud_add({
|
|
hud_elem_type = "waypoint",
|
|
name = waypoint_name,
|
|
text = "m",
|
|
precision=1,
|
|
number = 0xFF, --0xFFFFFF,
|
|
world_pos = {x=0, y=0, z=0},
|
|
})
|
|
-- store HUD elemnt id to remove it later
|
|
if not player_waypoints[player_name] then
|
|
player_waypoints[player_name] = {}
|
|
end
|
|
print("hud_id add", hud_id)
|
|
player_waypoints[player_name][waypoint_id] = hud_id
|
|
end
|
|
|
|
end
|
|
return nil
|
|
end,
|
|
})
|
|
|
|
|