2016-06-07 08:38:50 -07:00
|
|
|
|
|
|
|
invisibility = {}
|
|
|
|
|
2016-06-29 01:42:56 -07:00
|
|
|
local effect_time = 300 -- 5 minutes
|
|
|
|
|
2016-06-07 09:20:05 -07:00
|
|
|
-- reset player invisibility if they go offline
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
|
|
|
|
|
|
|
if invisibility[name] then
|
|
|
|
invisibility[name] = nil
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-06-07 08:38:50 -07:00
|
|
|
-- invisibility potion
|
|
|
|
|
|
|
|
minetest.register_node("invisibility:potion", {
|
|
|
|
description = "Invisibility Potion",
|
|
|
|
drawtype = "plantlike",
|
|
|
|
tiles = {"invisibility_potion.png"},
|
|
|
|
inventory_image = "invisibility_potion.png",
|
|
|
|
wield_image = "invisibility_potion.png",
|
|
|
|
paramtype = "light",
|
|
|
|
is_ground_content = false,
|
|
|
|
walkable = false,
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
|
|
|
|
},
|
2016-06-09 05:52:40 -07:00
|
|
|
groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
|
2016-06-07 08:38:50 -07:00
|
|
|
sounds = default.node_sound_glass_defaults(),
|
|
|
|
|
|
|
|
on_use = function(itemstack, user)
|
|
|
|
|
|
|
|
local pos = user:getpos()
|
2016-06-29 01:42:56 -07:00
|
|
|
local name = user:get_player_name()
|
|
|
|
|
|
|
|
-- are we already invisible?
|
|
|
|
if invisibility[name] then
|
|
|
|
|
|
|
|
minetest.chat_send_player(name,
|
|
|
|
">>> You are already invisible!")
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2016-06-07 08:38:50 -07:00
|
|
|
|
2016-06-09 02:54:48 -07:00
|
|
|
-- make player invisible
|
2016-06-09 13:47:17 -07:00
|
|
|
invisible(user, true)
|
2016-06-07 08:38:50 -07:00
|
|
|
|
2016-06-09 02:54:48 -07:00
|
|
|
-- play sound
|
2016-06-07 08:38:50 -07:00
|
|
|
minetest.sound_play("pop", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 5
|
|
|
|
})
|
|
|
|
|
2016-06-09 02:54:48 -07:00
|
|
|
-- display 10 second warning
|
2016-06-29 01:42:56 -07:00
|
|
|
minetest.after(effect_time - 10, function()
|
2016-06-09 02:54:48 -07:00
|
|
|
|
2016-06-29 01:42:56 -07:00
|
|
|
if invisibility[name]
|
|
|
|
and user:getpos() then
|
2016-06-09 02:54:48 -07:00
|
|
|
|
2016-06-29 01:42:56 -07:00
|
|
|
minetest.chat_send_player(name,
|
2016-06-09 02:54:48 -07:00
|
|
|
">>> You have 10 seconds before invisibility wears off!")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- make player visible 5 minutes later
|
2016-06-29 01:42:56 -07:00
|
|
|
minetest.after(effect_time, function()
|
2016-06-07 08:38:50 -07:00
|
|
|
|
2016-06-29 01:42:56 -07:00
|
|
|
if invisibility[name]
|
|
|
|
and user:getpos() then
|
2016-06-09 02:54:48 -07:00
|
|
|
|
|
|
|
-- show aready hidden player
|
2016-06-09 13:47:17 -07:00
|
|
|
invisible(user, nil)
|
2016-06-07 08:38:50 -07:00
|
|
|
|
2016-06-09 02:54:48 -07:00
|
|
|
-- play sound
|
|
|
|
minetest.sound_play("pop", {
|
2016-06-11 02:36:40 -07:00
|
|
|
pos = pos,
|
2016-06-09 02:54:48 -07:00
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 5
|
|
|
|
})
|
|
|
|
end
|
2016-06-11 02:36:40 -07:00
|
|
|
end)
|
2016-06-07 08:38:50 -07:00
|
|
|
|
2016-06-29 01:42:56 -07:00
|
|
|
-- take potion, return empty bottle (and rest of potion stack)
|
2016-06-07 08:38:50 -07:00
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
|
2016-06-29 01:42:56 -07:00
|
|
|
local item_count = user:get_wielded_item():get_count()
|
|
|
|
local inv = user:get_inventory()
|
|
|
|
local giving_back = "vessels:glass_bottle"
|
|
|
|
|
|
|
|
if inv and item_count > 1 then
|
|
|
|
|
|
|
|
if inv:room_for_item("main", {name = "vessels:glass_bottle"}) then
|
|
|
|
|
|
|
|
inv:add_item("main", {name = "vessels:glass_bottle"})
|
|
|
|
else
|
|
|
|
pos.y = pos.y + 1
|
|
|
|
|
|
|
|
minetest.add_item(pos, {name = "vessels:glass_bottle"})
|
|
|
|
end
|
|
|
|
|
|
|
|
giving_back = "invisibility:potion " .. tostring(item_count - 1)
|
|
|
|
|
|
|
|
end
|
2016-06-07 08:38:50 -07:00
|
|
|
|
2016-06-29 01:42:56 -07:00
|
|
|
return ItemStack(giving_back)
|
2016-06-07 08:38:50 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2016-06-09 02:54:48 -07:00
|
|
|
-- craft recipe
|
|
|
|
|
2016-06-07 08:38:50 -07:00
|
|
|
minetest.register_craft( {
|
|
|
|
output = "invisibility:potion",
|
|
|
|
type = "shapeless",
|
2016-06-09 02:54:48 -07:00
|
|
|
recipe = {"default:nyancat_rainbow", "vessels:glass_bottle"},
|
2016-06-07 08:38:50 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
-- invisibility function
|
|
|
|
|
2016-06-09 13:47:17 -07:00
|
|
|
invisible = function(player, toggle)
|
2016-06-07 08:38:50 -07:00
|
|
|
|
|
|
|
if not player then return false end
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
|
|
|
|
2016-06-09 13:47:17 -07:00
|
|
|
invisibility[name] = toggle
|
2016-06-07 08:38:50 -07:00
|
|
|
|
|
|
|
local prop
|
|
|
|
|
2016-06-09 13:47:17 -07:00
|
|
|
if toggle == true then
|
2016-06-07 08:38:50 -07:00
|
|
|
|
|
|
|
-- hide player and name tag
|
|
|
|
prop = {
|
|
|
|
visual_size = {x = 0, y = 0},
|
|
|
|
collisionbox = {0, 0, 0, 0, 0, 0}
|
|
|
|
}
|
|
|
|
|
|
|
|
player:set_nametag_attributes({
|
|
|
|
color = {a = 0, r = 255, g = 255, b = 255}
|
|
|
|
})
|
|
|
|
else
|
|
|
|
-- show player and tag
|
|
|
|
prop = {
|
|
|
|
visual_size = {x = 1, y = 1},
|
|
|
|
collisionbox = {-0.35, -1, -0.35, 0.35, 1, 0.35}
|
|
|
|
}
|
|
|
|
|
|
|
|
player:set_nametag_attributes({
|
|
|
|
color = {a = 255, r = 255, g = 255, b = 255}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
player:set_properties(prop)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- vanish command (admin only)
|
|
|
|
|
|
|
|
minetest.register_chatcommand("vanish", {
|
|
|
|
params = "<name>",
|
|
|
|
description = "Make player invisible",
|
|
|
|
privs = {server = true},
|
|
|
|
|
|
|
|
func = function(name, param)
|
|
|
|
|
|
|
|
-- player online
|
|
|
|
if param ~= ""
|
|
|
|
and minetest.get_player_by_name(param) then
|
|
|
|
|
|
|
|
name = param
|
|
|
|
|
|
|
|
-- player not online
|
|
|
|
elseif param ~= "" then
|
|
|
|
|
|
|
|
return false, "Player " .. param .. " is not online!"
|
|
|
|
end
|
|
|
|
|
2016-06-09 13:47:17 -07:00
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
|
|
|
|
-- hide / show player
|
|
|
|
if invisibility[name] then
|
|
|
|
|
|
|
|
invisible(player, nil)
|
|
|
|
else
|
|
|
|
invisible(player, true)
|
|
|
|
end
|
2016-06-07 08:38:50 -07:00
|
|
|
|
|
|
|
end
|
|
|
|
})
|