minetest-mod-vanish/init.lua

72 lines
1.7 KiB
Lua
Raw Normal View History

2022-01-28 12:55:06 -08:00
invis = {}
2022-01-27 13:11:01 -08:00
invisibility = {}
-- [function] Get visible
2022-01-28 12:55:06 -08:00
function invis.get(name)
2022-01-27 13:11:01 -08:00
if type(name) == "userdata" then
name = player:get_player_name()
end
2022-01-28 12:55:06 -08:00
return invisibility[name]
2022-01-27 13:11:01 -08:00
end
2022-01-28 12:55:06 -08:00
-- [function] Toggle invisibility
function invis.toggle(player, toggle)
2022-01-27 13:11:01 -08:00
if type(player) == "string" then
player = minetest.get_player_by_name(player)
end
local prop
local name = player:get_player_name()
2022-01-28 12:55:06 -08:00
invisibility[name] = toggle
2022-01-27 13:11:01 -08:00
if toggle == true then
-- Hide player and nametag
prop = {
2022-02-04 12:39:07 -08:00
visual = "",
collisionbox = {-0.01, 0, -0.01, 0.01, 0, 0.01},
2022-01-27 13:11:01 -08:00
show_on_minimap = false,
pointable = false,
2022-01-27 13:11:01 -08:00
}
2022-01-28 12:55:06 -08:00
--player:set_nametag_attributes({
--color = {a = 0},
--})
2022-01-27 21:06:40 -08:00
status = minetest.colorize("#F00"," vanished")
2022-01-27 13:11:01 -08:00
else
-- Show player and nametag
prop = {
2022-02-04 12:39:07 -08:00
visual = "mesh",
2022-01-27 13:11:01 -08:00
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
show_on_minimap = true,
pointable = true,
2022-01-27 13:11:01 -08:00
}
2022-01-28 12:55:06 -08:00
--player:set_nametag_attributes({
-- color = {a = 35},
--})
2022-01-27 21:06:40 -08:00
status = minetest.colorize("#0F0"," unvanished")
2022-01-27 13:11:01 -08:00
end
-- Update properties
player:set_properties(prop)
2022-01-27 21:06:40 -08:00
return minetest.colorize("#FF0","-!- "..name)..status
2022-01-27 13:11:01 -08:00
end
-- [register] Privilege
minetest.register_privilege("vanish", "Allow use of /vanish command")
-- [register] Command
minetest.register_chatcommand("vanish", {
2022-01-28 12:55:06 -08:00
description = "Make yourself or another player invisibility",
2022-01-27 13:11:01 -08:00
params = "<name>",
privs = {vanish=true},
func = function(name, param)
if minetest.get_player_by_name(param) then
name = param
elseif param ~= "" then
return false, "Invalid player \""..param.."\""
end
2022-01-28 12:55:06 -08:00
return true, invis.toggle(name, not invisibility[name])
2022-01-27 13:11:01 -08:00
end,
})