techage/basis/formspec_update.lua

53 lines
1.0 KiB
Lua
Raw Permalink Normal View History

2020-01-26 01:22:06 +03:00
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
2020-10-19 20:09:17 +03:00
AGPL v3
2020-01-26 01:22:06 +03:00
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
2020-01-26 01:22:06 +03:00
Keep only one formspec active per player
]]--
local P2S = minetest.pos_to_string
local ActiveFormspecs = {}
local ActivePlayer = {}
function techage.is_activeformspec(pos)
return ActiveFormspecs[P2S(pos)]
end
function techage.set_activeformspec(pos, player)
local name = player and player:get_player_name()
if name then
if ActivePlayer[name] then
ActiveFormspecs[ActivePlayer[name]] = nil
end
ActivePlayer[name] = P2S(pos)
ActiveFormspecs[P2S(pos)] = true
end
end
2020-04-11 11:14:52 +03:00
function techage.reset_activeformspec(pos, player)
local name = player and player:get_player_name()
if name then
if ActivePlayer[name] then
ActiveFormspecs[ActivePlayer[name]] = nil
ActivePlayer[name] = nil
end
end
end
2020-01-26 01:22:06 +03:00
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
if ActivePlayer[name] then
ActiveFormspecs[ActivePlayer[name]] = nil
ActivePlayer[name] = nil
end
end)