diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 1a73e59df7..3794402b06 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -200,7 +200,8 @@ end local gamemodes = { "survival", - "creative" + "creative", + "spectator" } function mcl_inventory.player_set_gamemode(p,g) @@ -209,8 +210,13 @@ function mcl_inventory.player_set_gamemode(p,g) if g == "survival" then mcl_experience.setup_hud(p) mcl_experience.update(p) + mcl_hardcore.spectator_mode_disabled(p) elseif g == "creative" then mcl_experience.remove_hud(p) + mcl_hardcore.spectator_mode_disabled(p) + elseif g == "spectator" then + mcl_experience.remove_hud(p) + mcl_hardcore.spectator_mode(p) end set_inventory(p) end diff --git a/mods/PLAYER/mcl_hardcore/init.lua b/mods/PLAYER/mcl_hardcore/init.lua index 094a8ff4f3..6798860d32 100644 --- a/mods/PLAYER/mcl_hardcore/init.lua +++ b/mods/PLAYER/mcl_hardcore/init.lua @@ -8,12 +8,9 @@ of the license, or (at your option) any later version. --]] ---[[ TODO: - * Add Spectator mode to gamemode. - Spectator mode: Players are invisible, have fast, fly & noclip, are immortal and their health/hunger hudbars are hidden. - * Also, only Survival mode for the GUI. +--Spectator mode: +-- Players are unable to interact with the world, invisible, have fast, fly & noclip, are immortal and their health/hunger hudbars are hidden. ---]] -- Spectator mode mcl_hardcore = {} @@ -28,7 +25,7 @@ function mcl_hardcore.spectator_mode(player) -- Have to wait since mcl_potions clears old effects on startup. minetest.after(3, function(player) - mcl_potions.make_invisible(player, true) + mcl_potions.invisiblility_func(player, null, 86400) -- Invisible for 24 hours. hb.hide_hudbar(player, "hunger") hb.change_hudbar(player, "health", nil, nil, "blank.png", nil, "hudbars_bar_health.png") end, player) @@ -38,9 +35,15 @@ function mcl_hardcore.spectator_mode_disabled(player) local meta = player:get_meta() local player_name = player:get_player_name() + mcl_potions._reset_player_effects(player, true) + hb.unhide_hudbar(player, "hunger") meta:set_int("mcl_privs:interact_revoked", 0) player:set_armor_groups({immortal=0}) - minetest.set_player_privs(player_name, {basic_privs=true}) + if meta:get_string("gamemode") == "creative" then + minetest.set_player_privs(player_name, {basic_privs=true,fly=true}) + else + minetest.set_player_privs(player_name, {basic_privs=true}) + end end @@ -51,7 +54,6 @@ if hardcore_mode then local name = player:get_player_name() local meta = player:get_meta() meta:set_int("dead", 1) - --minetest.kick_player(name, "You died on a hardcore server.") end) -- Make player a spectator on respawn in hardcore mode. @@ -60,6 +62,7 @@ if hardcore_mode then 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; respawning as a spectator.") end end) @@ -69,17 +72,10 @@ if hardcore_mode then 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) - --[[minetest.register_on_joinplayer(function(player) - local meta = player:get_meta() - if meta:get_int("dead") == 1 then - local name = player:get_player_name() - minetest.kick_player(name, "You died on a hardcore server.") - 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)