separate player table from global, add is_visible()
This commit is contained in:
parent
e201501aef
commit
0f2ed75207
@ -17,3 +17,4 @@ Changelog:
|
||||
- 0.4 - Potion recipe changed now that Nyan Cat no longer in default game
|
||||
- 0.5 - Use newer functions, Minetest 0.4.16 and anove needed to run
|
||||
- 0.6 - Make invisibility function global for API use, add time setting.
|
||||
- 0.7 - Remove player list from global table and add invisibility.is_visible(name).
|
||||
|
6
api.txt
6
api.txt
@ -9,6 +9,12 @@ visible once again e.g.
|
||||
invisibility.invisible(player, [true for invisible, false for visible])
|
||||
|
||||
|
||||
Mods can also check if a player is invisible by using the following function, which will
|
||||
return True if they can be seen and False when invisible.
|
||||
|
||||
invisibility.is_visible(player_name)
|
||||
|
||||
|
||||
Server owners can also use the /vanish command to hide either themselves or another
|
||||
player in their worlds e.g.
|
||||
|
||||
|
30
init.lua
30
init.lua
@ -5,7 +5,10 @@ invisibility = {
|
||||
effect_time = minetest.settings:get("invisibility.effect_time") or 180 -- 3 mins
|
||||
}
|
||||
|
||||
local S = minetest.get_translator("invisibility") -- translation support
|
||||
-- translation and player table
|
||||
|
||||
local S = minetest.get_translator("invisibility")
|
||||
local players = {}
|
||||
|
||||
-- reset player invisibility if they go offline or die
|
||||
|
||||
@ -13,9 +16,7 @@ minetest.register_on_leaveplayer(function(player)
|
||||
|
||||
local name = player:get_player_name()
|
||||
|
||||
if invisibility[name] then
|
||||
invisibility[name] = nil
|
||||
end
|
||||
if players[name] then players[name] = nil end
|
||||
end)
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
@ -29,7 +30,14 @@ local function is_creative(name)
|
||||
return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
|
||||
end
|
||||
|
||||
-- invisibility function
|
||||
-- invisibility functions
|
||||
|
||||
function invisibility.is_visible(player_name)
|
||||
|
||||
if players[player_name] then return false end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function invisibility.invisible(player, toggle)
|
||||
|
||||
@ -37,7 +45,7 @@ function invisibility.invisible(player, toggle)
|
||||
|
||||
local name = player:get_player_name()
|
||||
|
||||
invisibility[name] = toggle
|
||||
players[name] = toggle
|
||||
|
||||
local prop
|
||||
|
||||
@ -80,7 +88,7 @@ minetest.register_node("invisibility:potion", {
|
||||
local name = user:get_player_name()
|
||||
|
||||
-- are we already invisible?
|
||||
if invisibility[name] then
|
||||
if players[name] then
|
||||
|
||||
minetest.chat_send_player(name, S(">>> You are already invisible!"))
|
||||
|
||||
@ -97,7 +105,7 @@ minetest.register_node("invisibility:potion", {
|
||||
-- display 10 second warning
|
||||
minetest.after(invisibility.effect_time - 10, function()
|
||||
|
||||
if invisibility[name] and user:get_pos() then
|
||||
if players[name] and user:get_pos() then
|
||||
|
||||
minetest.chat_send_player(name,
|
||||
S(">>> You have 10 seconds before invisibility wears off!"))
|
||||
@ -107,7 +115,7 @@ minetest.register_node("invisibility:potion", {
|
||||
-- make player visible 5 minutes later
|
||||
minetest.after(invisibility.effect_time, function()
|
||||
|
||||
if invisibility[name] and user:get_pos() then
|
||||
if players[name] and user:get_pos() then
|
||||
|
||||
-- show hidden player
|
||||
invisibility.invisible(user, nil)
|
||||
@ -119,7 +127,7 @@ minetest.register_node("invisibility:potion", {
|
||||
end)
|
||||
|
||||
-- take potion, return empty bottle (and rest of potion stack)
|
||||
if not is_creative(user:get_player_name()) then
|
||||
if not is_creative(name) then
|
||||
|
||||
local item_count = user:get_wielded_item():get_count()
|
||||
local inv = user:get_inventory()
|
||||
@ -182,7 +190,7 @@ minetest.register_chatcommand("vanish", {
|
||||
local msg
|
||||
|
||||
-- hide / show player
|
||||
if invisibility[name] then
|
||||
if players[name] then
|
||||
|
||||
invisibility.invisible(player, nil) ; msg = "visible"
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user