Added persistant formspec

This commit is contained in:
Billy S 2018-07-24 20:49:21 -04:00
parent 881756c37d
commit 5cde0f65e9
2 changed files with 20 additions and 0 deletions

View File

@ -10,6 +10,11 @@ local function carrierQuit(pName)
end
end
-- Create formspec structure
local function getFs(name)
return "size[5,3]label[1.4,1;You are unconscious!]label[0.8,2;Time remaining: " .. tostring(knockout.knocked_out[name]) .. " seconds]"
end
-- Globalstep to revive players
local gs_time = 0
minetest.register_globalstep(function(dtime)
@ -20,8 +25,10 @@ minetest.register_globalstep(function(dtime)
for name, _ in pairs(knockout.knocked_out) do
if minetest.get_player_by_name(name) ~= nil then
knockout.decrease_knockout_time(name, 1)
minetest.show_formspec(name, "knockout:fs", getFs(name))
end
end
knockout.save()
end
-- Check for player drop
for name, _ in pairs(knockout.carrying) do
@ -32,6 +39,15 @@ minetest.register_globalstep(function(dtime)
end
end)
-- Oh no you don't. I like that formspec open
minetest.register_on_player_receive_fields(function(player, fName, _)
if fName == "knockout:fs" then
local name = player:get_player_name()
minetest.show_formspec(name, fName, getFs(name))
return true
end
end)
-- If the player is killed, they "wake up"
minetest.register_on_dieplayer(function(p)
local pName = p:get_player_name()

View File

@ -1,6 +1,8 @@
local path = minetest.get_modpath(minetest.get_current_modname())
dofile(path .. "/overrides.lua")
-- Create globals
knockout = {}
knockout.knocked_out = {}
@ -135,6 +137,8 @@ knockout.wake_up = function(pName)
privs.shout = true
privs.interact = true
minetest.set_player_privs(pName, privs)
-- Hide formspec
minetest.close_formspec(pName, "knockout:fs")
-- Save
knockout.save()
end