From cda35094946a55b972bc8fcab917c12df0cf46d6 Mon Sep 17 00:00:00 2001 From: cornernote Date: Sun, 16 Aug 2015 17:36:25 +0930 Subject: [PATCH] option to restart from current level, closes #35 --- skyblock_levels/register_misc.lua | 14 ++++++++++---- skyblock_levels/skyblock.feats.lua | 13 +++++++++++++ skyblock_levels/skyblock.levels.lua | 8 ++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/skyblock_levels/register_misc.lua b/skyblock_levels/register_misc.lua index 4d69cee..31a3069 100644 --- a/skyblock_levels/register_misc.lua +++ b/skyblock_levels/register_misc.lua @@ -31,10 +31,16 @@ minetest.register_on_dieplayer(function(player) local player_name = player:get_player_name() -- empty inventory skyblock.levels.empty_inventory(player) - -- reset feats - skyblock.feats.reset(player_name) - -- init level1 - skyblock.levels[1].init(player_name) + + -- back to beginning + if skyblock.levels.restart_on_die then + skyblock.feats.reset(player_name) + else + skyblock.feats.reset_level(player_name) + end + + -- back to start of this level + end) -- player receive fields diff --git a/skyblock_levels/skyblock.feats.lua b/skyblock_levels/skyblock.feats.lua index 38552d3..db6dba9 100644 --- a/skyblock_levels/skyblock.feats.lua +++ b/skyblock_levels/skyblock.feats.lua @@ -27,7 +27,9 @@ end function skyblock.feats.set_level(player_name, level) if skyblock.levels[level] then skyblock.feats.set(0, player_name, 'level', level) + players_feat[player_name][level] = {} skyblock.levels[level].init(player_name) + skyblock.feats.update(player_name) return true end end @@ -38,6 +40,17 @@ function skyblock.feats.reset(player_name) players_feat[player_name] = {} skyblock.feats.save(players_feat[player_name], player_name) skyblock.feats.update(player_name) + skyblock.levels[1].init(player_name) +end + +-- reset level +function skyblock.feats.reset_level(player_name) + skyblock.log('skyblock.feats.reset_level('..player_name..')') + local level = skyblock.feats.get_level(player_name) + players_feat[player_name][level] = {} + skyblock.feats.save(players_feat[player_name], player_name) + skyblock.feats.update(player_name) + skyblock.levels[level].init(player_name) end -- update feats diff --git a/skyblock_levels/skyblock.levels.lua b/skyblock_levels/skyblock.levels.lua index b97c12e..f6775f1 100644 --- a/skyblock_levels/skyblock.levels.lua +++ b/skyblock_levels/skyblock.levels.lua @@ -11,6 +11,14 @@ License: GPLv3 skyblock.levels = {} +-- +-- CONFIG OPTIONS +-- + +-- true to restart from level1, false to restart from current level +skyblock.levels.restart_on_die = minetest.setting_getbool('skyblock.levels.restart_on_die') + + -- -- Functions --