Create init.lua

master
zmv7 2022-01-28 02:11:01 +05:00 committed by GitHub
commit 6985ec05c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 66 additions and 0 deletions

66
init.lua Normal file
View File

@ -0,0 +1,66 @@
invisibility = {}
local invisible = {}
-- [function] Get visible
function invisibility.get(name)
if type(name) == "userdata" then
name = player:get_player_name()
end
return invisible[name]
end
-- [function] Toggle invisible
function invisibility.toggle(player, toggle)
if type(player) == "string" then
player = minetest.get_player_by_name(player)
end
local prop
local name = player:get_player_name()
invisible[name] = toggle
if toggle == true then
-- Hide player and nametag
prop = {
visual_size = {x = 0, y = 0},
collisionbox = {0, 0, 0, 0, 0, 0},
show_on_minimap = false,
}
player:set_nametag_attributes({
color = {a = 0, r = 255, g = 255, b = 255},
})
else
-- Show player and nametag
prop = {
visual_size = {x = 1, y = 1},
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
show_on_minimap = true,
}
player:set_nametag_attributes({
color = {a = 255, r = 255, g = 255, b = 255},
})
end
-- Update properties
player:set_properties(prop)
end
-- [register] Privilege
minetest.register_privilege("vanish", "Allow use of /vanish command")
-- [register] Command
minetest.register_chatcommand("vanish", {
description = "Make yourself or another player invisible",
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
return true, invisibility.toggle(name, not invisible[name])
end,
})