Add playersSleepingPercentage server setting (Fix #920)
This commit is contained in:
parent
6c6d40eb9d
commit
89ff666a6a
|
@ -9,6 +9,7 @@ local weather_mod = minetest.get_modpath("mcl_weather")
|
|||
local explosions_mod = minetest.get_modpath("mcl_explosions")
|
||||
local spawn_mod = minetest.get_modpath("mcl_spawn")
|
||||
local worlds_mod = minetest.get_modpath("mcl_worlds")
|
||||
local players_in_bed_setting = tonumber(minetest.settings:get("mcl_playersSleepingPercentage"))
|
||||
|
||||
-- Helper functions
|
||||
|
||||
|
@ -34,19 +35,10 @@ local function is_night_skip_enabled()
|
|||
end
|
||||
|
||||
local function check_in_beds(players)
|
||||
local in_bed = mcl_beds.player
|
||||
if not players then
|
||||
players = minetest.get_connected_players()
|
||||
end
|
||||
|
||||
for n, player in pairs(players) do
|
||||
local name = player:get_player_name()
|
||||
if not in_bed[name] then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return #players > 0
|
||||
return players_in_bed_setting <= (#mcl_beds.player * 100) / #players
|
||||
end
|
||||
|
||||
-- These monsters do not prevent sleep
|
||||
|
@ -198,8 +190,8 @@ end
|
|||
local function update_formspecs(finished, ges)
|
||||
local ges = ges or #minetest.get_connected_players()
|
||||
local form_n = "size[12,5;true]"
|
||||
local all_in_bed = ges == player_in_bed
|
||||
local night_skip = is_night_skip_enabled()
|
||||
local all_in_bed = players_in_bed_setting <= (player_in_bed * 100) / ges
|
||||
local night_skip = is_night_skip_enabled() and players_in_bed_setting <= 100
|
||||
local button_leave = "button_exit[4,3;4,0.75;leave;"..F(S("Leave bed")).."]"
|
||||
local button_abort = "button_exit[4,3;4,0.75;leave;"..F(S("Abort sleep")).."]"
|
||||
local bg_presleep = "bgcolor[#00000080;true]"
|
||||
|
@ -212,7 +204,7 @@ local function update_formspecs(finished, ges)
|
|||
return
|
||||
elseif not is_sp then
|
||||
local text = S("Players in bed: @1/@2", player_in_bed, ges)
|
||||
if not night_skip then
|
||||
if not night_skip or players_in_bed_setting > 100 then
|
||||
text = text .. "\n" .. S("Note: Night skip is disabled.")
|
||||
form_n = form_n .. bg_presleep
|
||||
form_n = form_n .. button_leave
|
||||
|
@ -221,7 +213,13 @@ local function update_formspecs(finished, ges)
|
|||
form_n = form_n .. bg_sleep
|
||||
form_n = form_n .. button_abort
|
||||
else
|
||||
text = text .. "\n" .. S("You will fall asleep when all players are in bed.")
|
||||
local comment = "You will fall asleep when "
|
||||
if players_in_bed_setting == 100 then
|
||||
comment = comment .. "all players are in bed."
|
||||
else
|
||||
comment = comment .. players_in_bed_setting .. "% of all players are in bed."
|
||||
end
|
||||
text = text .. "\n" .. S(comment)
|
||||
form_n = form_n .. bg_presleep
|
||||
form_n = form_n .. button_leave
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user