Merge pull request #28 from Wuzzy2/simplesurvival
Disable survival and damage when game is not running
This commit is contained in:
commit
03f8e1857c
@ -22,6 +22,10 @@ local timer_mode = nil -- nil, "vote", "starting", "grace"
|
||||
|
||||
local maintenance_mode = false -- is true when server is in maintenance mode, no games can be started while in maintenance mode
|
||||
|
||||
-- Initial setup
|
||||
minetest.setting_set("enable_damage", "false")
|
||||
survival.disable()
|
||||
|
||||
local update_timer_hud = function(text)
|
||||
local players = minetest.get_connected_players()
|
||||
for i=1,#players do
|
||||
@ -138,6 +142,8 @@ local stop_game = function()
|
||||
countdown = false
|
||||
starting_game = false
|
||||
force_init_warning = false
|
||||
survival.disable()
|
||||
minetest.setting_set("enable_damage", "false")
|
||||
unset_timer()
|
||||
end
|
||||
|
||||
@ -266,6 +272,7 @@ local start_game_now = function(input)
|
||||
unset_timer()
|
||||
end
|
||||
minetest.setting_set("enable_damage", "true")
|
||||
survival.enable()
|
||||
votes = 0
|
||||
voters = {}
|
||||
ingame = true
|
||||
@ -431,7 +438,7 @@ minetest.register_on_dieplayer(function(player)
|
||||
end)
|
||||
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
player:set_hp(1)
|
||||
player:set_hp(20)
|
||||
local name = player:get_player_name()
|
||||
local privs = minetest.get_player_privs(name)
|
||||
if (privs.interact or privs.fly) and (hungry_games.death_mode == "spectate") then
|
||||
@ -453,6 +460,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
minetest.set_player_privs(name, privs)
|
||||
minetest.chat_send_player(name, "You are now spectating")
|
||||
spawning.spawn(player, "lobby")
|
||||
reset_player_state(player)
|
||||
timer_hudids[name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = { x=0.5, y=0 },
|
||||
|
@ -1,7 +1,9 @@
|
||||
|
||||
survival = { };
|
||||
survival.active = false
|
||||
|
||||
local player_states = { };
|
||||
local hudbar_active = {}
|
||||
|
||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||
local S;
|
||||
@ -48,6 +50,42 @@ survival.register_state = function ( name, def )
|
||||
survival.registered_states[#survival.registered_states + 1] = def;
|
||||
end
|
||||
|
||||
survival.enable = function()
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
local inv = player:get_inventory();
|
||||
local plname = player:get_player_name();
|
||||
for i, def in ipairs(survival.registered_states) do
|
||||
if (def.enabled) then
|
||||
local name = def.name;
|
||||
survival.reset_player_state(plname, name);
|
||||
if hudbar_active[plname] then
|
||||
hb.unhide_hudbar(player, name);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
survival.active = true
|
||||
end
|
||||
|
||||
survival.disable = function()
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
local inv = player:get_inventory();
|
||||
local plname = player:get_player_name();
|
||||
for i, def in ipairs(survival.registered_states) do
|
||||
if (def.enabled) then
|
||||
local name = def.name;
|
||||
survival.reset_player_state(plname, name);
|
||||
local state = player_states[plname][name];
|
||||
if hudbar_active[plname] then
|
||||
hb.change_hudbar(player, name, math.floor(def.get_scaled_value(state)));
|
||||
hb.hide_hudbar(player, name);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
survival.active = false
|
||||
end
|
||||
|
||||
survival.get_player_state = function ( name, stname )
|
||||
if (name and stname and player_states[name]) then
|
||||
return player_states[name][stname];
|
||||
@ -89,7 +127,6 @@ minetest.register_chatcommand("s", chat_cmd_def);
|
||||
|
||||
local timer = 0;
|
||||
local MAX_TIMER = 0.5;
|
||||
local hudbar_active = {}
|
||||
|
||||
minetest.register_globalstep(function ( dtime )
|
||||
|
||||
@ -105,7 +142,7 @@ minetest.register_globalstep(function ( dtime )
|
||||
if (def.enabled) then
|
||||
local name = def.name;
|
||||
local state = player_states[plname][name];
|
||||
if (def.on_update) then
|
||||
if (survival.active and def.on_update) then
|
||||
def.on_update(tmr, player, state);
|
||||
end
|
||||
if hudbar_active[plname] then
|
||||
@ -138,7 +175,7 @@ minetest.register_on_joinplayer(function ( player )
|
||||
minetest.after(0.5, function ( self )
|
||||
for i, def in ipairs(survival.registered_states) do
|
||||
local name = def.name;
|
||||
hb.init_hudbar(player, name, math.floor(def.get_scaled_value(player_states[plname][def.name])), 100, false);
|
||||
hb.init_hudbar(player, name, math.floor(def.get_scaled_value(player_states[plname][def.name])), 100, not survival.active);
|
||||
hudbar_active[plname] = true;
|
||||
end
|
||||
end);
|
||||
|
Loading…
x
Reference in New Issue
Block a user