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 explosions_mod = minetest.get_modpath("mcl_explosions")
|
||||||
local spawn_mod = minetest.get_modpath("mcl_spawn")
|
local spawn_mod = minetest.get_modpath("mcl_spawn")
|
||||||
local worlds_mod = minetest.get_modpath("mcl_worlds")
|
local worlds_mod = minetest.get_modpath("mcl_worlds")
|
||||||
|
local players_in_bed_setting = tonumber(minetest.settings:get("mcl_playersSleepingPercentage"))
|
||||||
|
|
||||||
-- Helper functions
|
-- Helper functions
|
||||||
|
|
||||||
|
@ -34,19 +35,10 @@ local function is_night_skip_enabled()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function check_in_beds(players)
|
local function check_in_beds(players)
|
||||||
local in_bed = mcl_beds.player
|
|
||||||
if not players then
|
if not players then
|
||||||
players = minetest.get_connected_players()
|
players = minetest.get_connected_players()
|
||||||
end
|
end
|
||||||
|
return players_in_bed_setting <= (#mcl_beds.player * 100) / #players
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- These monsters do not prevent sleep
|
-- These monsters do not prevent sleep
|
||||||
|
@ -198,8 +190,8 @@ end
|
||||||
local function update_formspecs(finished, ges)
|
local function update_formspecs(finished, ges)
|
||||||
local ges = ges or #minetest.get_connected_players()
|
local ges = ges or #minetest.get_connected_players()
|
||||||
local form_n = "size[12,5;true]"
|
local form_n = "size[12,5;true]"
|
||||||
local all_in_bed = ges == player_in_bed
|
local all_in_bed = players_in_bed_setting <= (player_in_bed * 100) / ges
|
||||||
local night_skip = is_night_skip_enabled()
|
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_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 button_abort = "button_exit[4,3;4,0.75;leave;"..F(S("Abort sleep")).."]"
|
||||||
local bg_presleep = "bgcolor[#00000080;true]"
|
local bg_presleep = "bgcolor[#00000080;true]"
|
||||||
|
@ -212,7 +204,7 @@ local function update_formspecs(finished, ges)
|
||||||
return
|
return
|
||||||
elseif not is_sp then
|
elseif not is_sp then
|
||||||
local text = S("Players in bed: @1/@2", player_in_bed, ges)
|
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.")
|
text = text .. "\n" .. S("Note: Night skip is disabled.")
|
||||||
form_n = form_n .. bg_presleep
|
form_n = form_n .. bg_presleep
|
||||||
form_n = form_n .. button_leave
|
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 .. bg_sleep
|
||||||
form_n = form_n .. button_abort
|
form_n = form_n .. button_abort
|
||||||
else
|
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 .. bg_presleep
|
||||||
form_n = form_n .. button_leave
|
form_n = form_n .. button_leave
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user