Okay here is the code. It works perfectly fine, but, if you were to type /dashboard twice and then /clean, one HUD element will linger on the screen while the other is cleared. If you type /clean again Minetest will crash. By the way, if you were to open the other menus, everything would work just fin. The bug only occurs when you open the same menu twice in a row and then run /clean. Any help on this specific problem would be great and you will receive an instant credit in my project. Sorry I have to ask help all of the time. However, once this one issue is solved, there will not be any more questions on this topic. Thanks and God bless!
init.lua:
Code: Select all
-- All glory to God, Jesus Christ, and the Holy Spirit.
minespy = {}
dofile(minetest.get_modpath("minespy") .. "/services/points.lua")
dofile(minetest.get_modpath("minespy") .. "/services/records.lua")
dofile(minetest.get_modpath("minespy") .. "/extra_content/contentTheSwarm.lua")
dofile(minetest.get_modpath("minespy") .. "/extra_content/contentColdOrigins.lua")
dofile(minetest.get_modpath("minespy") .. "/dashboard/ms.lua")
hudkit_ms = dofile(minetest.get_modpath("minespy") .. "/hudkit.lua")
minespy.hud = hudkit_ms()
minetest.register_chatcommand("dashboard", {
privs = { interact = true },
func = function(playername)
dir = "dashboard.png"
minespy.hud:add(playername, "dashboard", {
hud_elem_type = "image",
position = {x = 1, y = 1},
scale = {x = 2.6, y = 2.6},
alignment = { x = -0.5, y = -0.7},
text = dir,
offset = {x=-262, y = -103},
number = 0xFFFFFF
})
end,
})
minetest.register_chatcommand("profile", {
privs = { interact = true },
func = function(playername)
dir = "dashboard_profile_menu.png"
minespy.hud:add(playername, "dashboard_profile_menu", {
hud_elem_type = "image",
position = {x = 1, y = 1},
scale = {x = 2.6, y = 2.6},
alignment = { x = -0.5, y = -0.7},
text = dir,
offset = {x=-262, y = -103},
number = 0xFFFFFF
})
end,
})
minetest.register_chatcommand("clean", {
privs = { interact = true },
func = function(playername)
clean(playername)
end,
})
function clean(playername, type)
if(type == "dashboard")
then
minespy.hud:remove(playername, "dashboard")
end
minespy.hud:remove(playername, "dashboard")
minespy.hud:remove(playername, "dashboard_profile_menu")
end
hudkit.lua:
Code: Select all
-- HudKit, by rubenwardy
-- License: Either WTFPL or CC0, you can choose.
local function hudkit_ms()
return {
players = {},
add = function(self, player, id, def)
name = minetest.get_player_by_name(player)
elements = self.players[name]
if not elements then
self.players[name] = {}
elements = self.players[name]
end
elements[id] = name:hud_add(def)
end,
exists = function(self, player, id)
name = minetest.get_player_by_name(player)
local elements = self.players[name:get_player_name()]
return elements and elements[id]
end,
change = function(self, player, id, stat, value)
local elements = self.players[player:get_player_name()]
if not elements or not elements[id] then
return false
end
player:hud_change(elements[id], stat, value)
return true
end,
remove = function(self, player, id, def)
name = minetest.get_player_by_name(player)
elements = self.players[name]
if not elements then
self.players[name] = {}
elements = self.players[name]
end
elements[id] = name:hud_remove(elements[id])
end,
}
end
return hudkit_ms