Fix beds #798 attempt 5

kay27 2020-07-30 02:01:15 +04:00 committed by Wuzzy
parent 50fa36aa2c
commit 92385364e5

@ -202,8 +202,13 @@ local function lay_down(player, pos, bed_pos, state, skip)
return true return true
end end
local function update_formspecs(finished) local function update_formspecs(finished, players)
local ges = #minetest.get_connected_players() local ges
if players then
ges = #players
else
ges = #minetest.get_connected_players()
end
local form_n = "size[6,5;true]" local form_n = "size[6,5;true]"
local all_in_bed = ges == player_in_bed local all_in_bed = ges == player_in_bed
local night_skip = is_night_skip_enabled() local night_skip = is_night_skip_enabled()
@ -364,7 +369,14 @@ end)
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
lay_down(player, nil, nil, false, true) lay_down(player, nil, nil, false, true)
if check_in_beds() then players = minetest.get_connected_players()
for n, player in ipairs(players) do
if player:get_player_name() == name then
players[n] = nil
break
end
end
if check_in_beds(players) then
minetest.after(5, function() minetest.after(5, function()
if check_in_beds() then if check_in_beds() then
update_formspecs(is_night_skip_enabled()) update_formspecs(is_night_skip_enabled())
@ -372,7 +384,7 @@ minetest.register_on_leaveplayer(function(player)
end end
end) end)
end end
update_formspecs(false) update_formspecs(false, players)
end) end)
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)