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 ==-- --== 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 -- Depth of the nether
local nether_middle = -20000 local nether_middle = -20000
@ -94,9 +85,17 @@ local NETHER_SHROOM_FREQ = 100
--== END OF EDITABLE OPTIONS ==-- --== 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) function nether:inform(msg, spam, t)
if spam <= self.max_spam then if spam <= self.log_level then
local info local info
if t then if t then
info = "[nether] " .. msg .. (" after ca. %.3g s"):format( info = "[nether] " .. msg .. (" after ca. %.3g s"):format(
@ -105,7 +104,7 @@ if nether.info then
info = "[nether] " .. msg info = "[nether] " .. msg
end end
print(info) print(info)
if self.inform_all then if self.log_to_chat then
minetest.chat_send_all(info) minetest.chat_send_all(info)
end end
end end
@ -116,12 +115,6 @@ else
end 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 -- Weierstrass function stuff from https://github.com/slemonide/gen
local SIZE = 1000 local SIZE = 1000
local ssize = math.ceil(math.abs(SIZE)) local ssize = math.ceil(math.abs(SIZE))

View File

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