Cleanup, and add a flag on world creation to remember Hardcore mode.

This commit is contained in:
MysticTempest 2022-07-28 05:27:48 -05:00
parent c1bae69844
commit 605f1b4cc9
5 changed files with 53 additions and 32 deletions

View File

@ -486,17 +486,9 @@ function hb.get_hudbar_identifiers()
return ids
end
local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false)
if hardcore_mode then
heart_texture_fg = "hudbars_icon_health_hardcore.png"
else
heart_texture_fg = "hudbars_icon_health.png"
end
--register built-in HUD bars
if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_hudbars then
hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = heart_texture_fg, bgicon = "hudbars_bgicon_health.png" }, 0, 20, 20, false)
hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = "hudbars_icon_health.png", bgicon = "hudbars_bgicon_health.png" }, 0, 20, 20, false)
hb.register_hudbar("breath", 0xFFFFFF, S("Breath"), { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png", bgicon = "hudbars_bgicon_breath.png" }, 1, 10, 10, true)
end

View File

@ -17,9 +17,14 @@ end
local icon_ids = {}
-- Hardcore mode Healthbar change
local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false)
local file = io.open(minetest.get_worldpath().."/hardcore_mode.txt", "r")
if file ~= nil then
hardcore_world = true
end
if hardcore_mode then
if hardcore_mode or hardcore_world then
heart_texture_fg = "hudbars_icon_health_hardcore.png"
else
heart_texture_fg = "hudbars_icon_health.png"

View File

@ -8,13 +8,24 @@ of the license, or (at your option) any later version.
--]]
--Spectator mode:
-- Spectator mode:
-- Players are unable to interact with the world, invisible, have fast, fly & noclip, are immortal and their health/hunger hudbars are hidden.
--
--
mcl_hardcore = {}
-- Write Hardcore mode state to world.
function mcl_hardcore.save()
local file = io.open(minetest.get_worldpath().."/hardcore_mode.txt", "w")
if file then
file:write("Enabled")
file:close()
end
end
-- Spectator mode
mcl_hardcore = {}
function mcl_hardcore.spectator_mode(player)
local meta = player:get_meta()
local player_name = player:get_player_name()
@ -53,6 +64,7 @@ function mcl_hardcore.spectator_mode_disabled(player)
elseif meta:get_string("gamemode") == "creative" then
privs.fast = nil
privs.noclip = nil
privs.fly = true
privs.interact = true
minetest.set_player_privs(player_name, privs)
else -- survival; only basic privs
@ -62,8 +74,18 @@ function mcl_hardcore.spectator_mode_disabled(player)
end
local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false)
if hardcore_mode then
-- Hardcore mode
function mcl_hardcore.hardcore_mode(player)
local meta = player:get_meta()
local player_name = player:get_player_name()
if meta:get_int("dead") == 1 then
mcl_hardcore.spectator_mode(player)
minetest.chat_send_player(player_name, "You died in hardcore mode; rejoining as a spectator.")
else
minetest.after(4, function(player)
hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health_hardcore.png", nil, "hudbars_bar_health.png")
end, player)
end
minetest.register_on_dieplayer(function(player, reason)
local name = player:get_player_name()
@ -80,20 +102,22 @@ if hardcore_mode then
minetest.chat_send_player(player_name, "You died in hardcore mode; respawning as a spectator.")
end
end)
-- If hardcore is enabled or re-enabled, & you've already died once; ensure that you're a spectator when rejoining.
minetest.register_on_joinplayer(function(player)
local meta = player:get_meta()
local player_name = player:get_player_name()
if meta:get_int("dead") == 1 then
mcl_hardcore.spectator_mode(player)
minetest.chat_send_player(player_name, "You died in hardcore mode; rejoining as a spectator.")
end
end)
else
-- If hardcore disabled, make sure settings are back to basics via the 'spectator_mode_disabled' function.
minetest.register_on_joinplayer(function(player)
mcl_hardcore.spectator_mode_disabled(player)
end)
end
local hardcore_mode = minetest.settings:get_bool("hardcore_mode_enabled", false)
--Set world state:
minetest.register_on_joinplayer(function(player)
if minetest.get_gametime() <= 5 and hardcore_mode then
mcl_hardcore.save()
else
local file = io.open(minetest.get_worldpath().."/hardcore_mode.txt", "r")
if file ~= nil then
hardcore_world = true
end
end
if hardcore_mode or hardcore_world then
mcl_hardcore.hardcore_mode(player)
end
end)

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

View File

@ -63,7 +63,7 @@ mcl_showDeathMessages (Show death messages) bool true
# If disabled, all recipes will be shown.
mcl_craftguide_progressive_mode (Learn crafting recipes progressively) bool true
# If enabled, you will only have 1 life to use. After death you will be immortal, and unable to interact with the world while 'hardcore_mode' is enabled.
# If enabled, you will only have 1 life to use. After death you will be dropped into spectator mode, and unable to interact with the world.
hardcore_mode_enabled (Enable Hardcore mode) bool false
[Mobs]