Add settingtypes.txt to configure player trapping and message logging

There are also some changes to fix problems when trapping is enabled while damage is disabled or the other way round.
This commit is contained in:
HybridDog 2022-08-16 17:12:37 +02:00
parent 6507e43dc5
commit 817efcdd29
4 changed files with 64 additions and 31 deletions

View File

@ -19,15 +19,6 @@ end
--== EDITABLE OPTIONS ==--
--says some information.
nether.info = true
-- tell everyone about the generation
nether.inform_all = minetest.is_singleplayer()
--1:<a bit of information> 2:<acceptable amount of information> 3:<lots of text>
nether.max_spam = 2
-- Depth of the nether
local nether_middle = -20000
@ -94,9 +85,17 @@ local NETHER_SHROOM_FREQ = 100
--== END OF EDITABLE OPTIONS ==--
if nether.info then
local path = minetest.get_modpath"nether"
dofile(path .. "/settings.lua")
local nether_weird_noise = dofile(path .. "/weird_mapgen_noise.lua")
dofile(path .. "/items.lua")
--dofile(path .. "/furnace.lua")
dofile(path .. "/pearl.lua")
if nether.log_level >= 1 then
function nether:inform(msg, spam, t)
if spam <= self.max_spam then
if spam <= self.log_level then
local info
if t then
info = "[nether] " .. msg .. (" after ca. %.3g s"):format(
@ -105,7 +104,7 @@ if nether.info then
info = "[nether] " .. msg
end
print(info)
if self.inform_all then
if self.log_to_chat then
minetest.chat_send_all(info)
end
end
@ -116,12 +115,6 @@ else
end
local path = minetest.get_modpath"nether"
local nether_weird_noise = dofile(path.."/weird_mapgen_noise.lua")
dofile(path.."/items.lua")
--dofile(path.."/furnace.lua")
dofile(path.."/pearl.lua")
-- Weierstrass function stuff from https://github.com/slemonide/gen
local SIZE = 1000
local ssize = math.ceil(math.abs(SIZE))

View File

@ -2,8 +2,7 @@
-- kills the player if he uses PilzAdam portal
local portal_target = nether.buildings+1
local nether_prisons = minetest.settings:get_bool("enable_damage")
local obsidian_portal_kills = nether_prisons and true
local damage_enabled = minetest.settings:get_bool"enable_damage"
local mclike_portal = false
local abm_allowed
@ -15,7 +14,7 @@ local save_path = minetest.get_worldpath() .. "/nether_players"
local players_in_nether = {}
-- Load the list of players which are trapped in the nether
-- (or would be trapped if nether_prisons was true)
-- (or would be trapped if nether.trap_players was true)
do
local file = io.open(save_path, "r")
if file then
@ -43,7 +42,7 @@ local function save_nether_players()
end
local update_background
if nether_prisons then
if nether.trap_players then
function update_background(player, down)
if down then
player:set_sky({r=15, g=0, b=0}, "plain")
@ -95,9 +94,6 @@ end
-- teleports players to nether or helps it
local function player_to_nether(player, pos)
local pname = player:get_player_name()
if players_in_nether[pname] then
return
end
players_in_nether[pname] = true
save_nether_players()
update_background(player, true)
@ -107,8 +103,10 @@ local function player_to_nether(player, pos)
end
minetest.chat_send_player(pname, "For any reason you arrived here. " ..
"Type /nether_help to find out things like craft recipes.")
player:set_hp(0)
if not nether_prisons then
if nether.trap_players then
player:set_hp(0)
end
if not damage_enabled or not nether.trap_players then
player:set_pos(get_player_died_target(player))
end
end
@ -119,7 +117,7 @@ local function player_from_nether(player, pos)
players_in_nether[pname] = nil
save_nether_players()
end
update_background(player)
update_background(player, false)
player:set_pos(pos)
end
@ -180,7 +178,7 @@ minetest.register_chatcommand("from_hell", {
-- Disallow teleportation and change spawn positions if the nether traps players
if nether_prisons then
if nether.trap_players then
-- randomly set player position when he/she dies in nether
minetest.register_on_respawnplayer(function(player)
local pname = player:get_player_name()
@ -230,7 +228,7 @@ if nether_prisons then
else
minetest.log("action", "Player \"" .. pname ..
"\" must not be in the nether, teleporting it!")
update_background(player)
update_background(player, false)
current_pos.y = 20
player:set_pos(current_pos)
end
@ -312,7 +310,7 @@ local function obsi_teleport_player(player, pos, target)
end
local has_teleported
if obsidian_portal_kills then
if damage_enabled then
obsidian_teleport(player, pname)
has_teleported = true
elseif not mclike_portal then

23
nether/settings.lua Normal file
View File

@ -0,0 +1,23 @@
local default_settings = {
trap_players = true,
log_to_chat = false,
log_level = 2,
}
nether.settings = {}
for name,dv in pairs(default_settings) do
local setting
local setting_name = "nether." .. name
if type(dv) == "boolean" then
setting = minetest.settings:get_bool(setting_name)
elseif type(dv) == "number" then
setting = tonumber(minetest.settings:get(setting_name))
else
error"[nether] Only boolean and number settings are available"
end
if setting == nil then
setting = dv
end
nether[name] = setting
end

19
nether/settingtypes.txt Normal file
View File

@ -0,0 +1,19 @@
# If enabled, regular players which are in the nether can leave it only with
# a nether portal and other ways of teleportation, e.g. the /spawn
# chatcommand, are blocked. Similarly, the nether can only be entered with a
# portal.
# This forces the players to investigate the nether and build a portal with
# hellish effort to go back to their home in the overworld.
# It is recommended to disable this setting in creative mode or if damage is
# disabled.
nether.trap_players (Trap players) bool true
# If enabled, show log messages in the chat and not only in debug.txt
nether.log_to_chat (Log messages to chat) bool false
# Specify how much text is printed for debugging purposes
# 0: Disabled
# 1: A bit of information
# 2: Acceptable amount of information
# 3: Lots of text
nether.log_level (Log level) int 2 0 3