diff --git a/init.lua b/init.lua index 49affdb..da895b4 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,9 @@ local S = minetest.get_translator("chest_recovery") -- Récupérer le traducteur pour ce mod +-- settings + +local setting_give_recovery_compass = minetest.settings:get_bool("chest_recovery_give_recovery_compass", false) + chest_positions = {} @@ -305,11 +309,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) -- Traitement du bouton de transfert if fields.transfer then - -- Supprimer les éléments de récupération du joueur - for i = 1, player_inv:get_size("main") do - local stack = player_inv:get_stack("main", i) - if stack:get_name():find("mcl_compass:.*_recovery") then - player_inv:remove_item("main", stack) + if setting_give_recovery_compass == true then + -- Supprimer les éléments de récupération du joueur + for i = 1, player_inv:get_size("main") do + local stack = player_inv:get_stack("main", i) + if stack:get_name():find("mcl_compass:.*_recovery") then + player_inv:remove_item("main", stack) + end end end @@ -546,23 +552,24 @@ minetest.register_privilege("chest_recovery_bypass", { + if setting_give_recovery_compass == true then + -- Define compass_frames as a global variable + compass_frames = 32 - -- Define compass_frames as a global variable - compass_frames = 32 + minetest.register_on_respawnplayer(function(player) + -- Generate a new random frame for the recovery compass + local random_frame = math.random(0, compass_frames - 1) - minetest.register_on_respawnplayer(function(player) - -- Generate a new random frame for the recovery compass - local random_frame = math.random(0, compass_frames - 1) + -- Create the recovery compass item + local recovery_compass = ItemStack("mcl_compass:" .. random_frame .. "_recovery") + local player_inv_2 = player:get_inventory() - -- Create the recovery compass item - local recovery_compass = ItemStack("mcl_compass:" .. random_frame .. "_recovery") - local player_inv_2 = player:get_inventory() + if player_inv_2 then + player_inv_2:add_item("main", recovery_compass) + end - if player_inv_2 then - player_inv_2:add_item("main", recovery_compass) - end - - end) + end) + end @@ -599,4 +606,4 @@ minetest.register_privilege("chest_recovery_bypass", { return true, "Coffre ouvert à distance." end, }) - \ No newline at end of file + diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..b32bfc3 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,2 @@ +# give player a recovery compass on death, and delete it on recovery +chest_recovery_give_recovery_compass (Recovery Compass) bool false