Merge pull request #28 from Wuzzy2/simplesurvival

Disable survival and damage when game is not running
This commit is contained in:
GunshipPenguin 2015-07-02 20:30:26 -07:00
commit 03f8e1857c
2 changed files with 49 additions and 4 deletions

View File

@ -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 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 update_timer_hud = function(text)
local players = minetest.get_connected_players() local players = minetest.get_connected_players()
for i=1,#players do for i=1,#players do
@ -138,6 +142,8 @@ local stop_game = function()
countdown = false countdown = false
starting_game = false starting_game = false
force_init_warning = false force_init_warning = false
survival.disable()
minetest.setting_set("enable_damage", "false")
unset_timer() unset_timer()
end end
@ -266,6 +272,7 @@ local start_game_now = function(input)
unset_timer() unset_timer()
end end
minetest.setting_set("enable_damage", "true") minetest.setting_set("enable_damage", "true")
survival.enable()
votes = 0 votes = 0
voters = {} voters = {}
ingame = true ingame = true
@ -431,7 +438,7 @@ minetest.register_on_dieplayer(function(player)
end) end)
minetest.register_on_respawnplayer(function(player) minetest.register_on_respawnplayer(function(player)
player:set_hp(1) player:set_hp(20)
local name = player:get_player_name() local name = player:get_player_name()
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if (privs.interact or privs.fly) and (hungry_games.death_mode == "spectate") then 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.set_player_privs(name, privs)
minetest.chat_send_player(name, "You are now spectating") minetest.chat_send_player(name, "You are now spectating")
spawning.spawn(player, "lobby") spawning.spawn(player, "lobby")
reset_player_state(player)
timer_hudids[name] = player:hud_add({ timer_hudids[name] = player:hud_add({
hud_elem_type = "text", hud_elem_type = "text",
position = { x=0.5, y=0 }, position = { x=0.5, y=0 },

View File

@ -1,7 +1,9 @@
survival = { }; survival = { };
survival.active = false
local player_states = { }; local player_states = { };
local hudbar_active = {}
-- Boilerplate to support localized strings if intllib mod is installed. -- Boilerplate to support localized strings if intllib mod is installed.
local S; local S;
@ -48,6 +50,42 @@ survival.register_state = function ( name, def )
survival.registered_states[#survival.registered_states + 1] = def; survival.registered_states[#survival.registered_states + 1] = def;
end 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 ) survival.get_player_state = function ( name, stname )
if (name and stname and player_states[name]) then if (name and stname and player_states[name]) then
return player_states[name][stname]; return player_states[name][stname];
@ -89,7 +127,6 @@ minetest.register_chatcommand("s", chat_cmd_def);
local timer = 0; local timer = 0;
local MAX_TIMER = 0.5; local MAX_TIMER = 0.5;
local hudbar_active = {}
minetest.register_globalstep(function ( dtime ) minetest.register_globalstep(function ( dtime )
@ -105,7 +142,7 @@ minetest.register_globalstep(function ( dtime )
if (def.enabled) then if (def.enabled) then
local name = def.name; local name = def.name;
local state = player_states[plname][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); def.on_update(tmr, player, state);
end end
if hudbar_active[plname] then if hudbar_active[plname] then
@ -138,7 +175,7 @@ minetest.register_on_joinplayer(function ( player )
minetest.after(0.5, function ( self ) minetest.after(0.5, function ( self )
for i, def in ipairs(survival.registered_states) do for i, def in ipairs(survival.registered_states) do
local name = def.name; 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; hudbar_active[plname] = true;
end end
end); end);