1
0
forked from MTSR/invisible
invisible/init.lua

81 lines
2.5 KiB
Lua
Raw Normal View History

2024-05-14 23:07:45 +03:00
local S = minetest.get_translator("invisible")
2018-07-24 17:09:35 +03:00
minetest.register_alias("i", "invisible:tool")
2018-07-26 09:11:43 +03:00
invisible = { time = 0, armor = minetest.get_modpath("3d_armor")}
2018-07-24 17:09:35 +03:00
minetest.register_privilege("invisible", {
2024-05-14 23:07:45 +03:00
description = S("Allows the player to become invisible."),
2018-07-26 09:11:43 +03:00
give_to_singleplayer = false,
2018-07-24 17:09:35 +03:00
})
2018-07-26 09:11:43 +03:00
invisible.toggle=function(user,sneak)
2018-07-24 17:09:35 +03:00
local name=user:get_player_name()
if minetest.check_player_privs(user:get_player_name(), {invisible=true}) then
if not invisible[name] then
user:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}})
invisible[name]={}
invisible[name].tool=sneak
invisible[name].visual_size=user:get_properties().visual_size
invisible[name].textures=user:get_properties().textures
user:set_properties({
visual = "mesh",
textures={"invisible_skin.png"},
visual_size = {x=0, y=0},
2021-01-05 23:59:43 +03:00
pointable=false,
2018-07-24 17:09:35 +03:00
})
2024-05-14 23:07:45 +03:00
minetest.chat_send_player(name, S("invisible on"))
2018-07-24 17:09:35 +03:00
else
user:set_nametag_attributes({color = {a = 255, r = 255, g = 255, b = 255}})
user:set_properties({
visual = "mesh",
textures=invisible[name].textures,
visual_size = invisible[name].visual_size,
2021-01-05 23:59:43 +03:00
pointable=true,
2018-07-24 17:09:35 +03:00
})
invisible[name]=nil
if invisible.armor then
armor:set_player_armor(user)
armor:update_inventory(user)
end
2024-05-14 23:07:45 +03:00
minetest.chat_send_player(name, S("invisible off"))
2018-07-24 17:09:35 +03:00
end
else
if not invisible[name] then
invisible[name]={}
user:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}})
else
user:set_nametag_attributes({color = {a = 255, r = 255, g = 255, b = 255}})
invisible[name]=nil
end
end
end
minetest.register_tool("invisible:tool", {
2024-05-14 23:07:45 +03:00
description = S("invisible"),
2018-07-24 17:09:35 +03:00
inventory_image = "default_stick.png",
groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing)
if minetest.check_player_privs(user:get_player_name(), {invisible=true}) then
2018-07-26 09:11:43 +03:00
invisible.toggle(user,true)
2018-07-24 17:09:35 +03:00
else
itemstack:replace(nil)
end
return itemstack
end
})
minetest.register_globalstep(function(dtime)
invisible.time=invisible.time+dtime
if invisible.time<0.5 then return end
invisible.time=0
for _, player in pairs(minetest.get_connected_players()) do
local name=player:get_player_name()
local sneak=player:get_player_control().sneak
if (sneak and not invisible[name]) or (sneak==false and invisible[name] and not invisible[name].tool) then
2018-07-26 09:11:43 +03:00
invisible.toggle(player)
2018-07-24 17:09:35 +03:00
end
end
2021-01-05 23:59:43 +03:00
end)