Fix discharge of flashlight and sonic screwdriver
authorZefram <zefram@fysh.org>
Sun, 27 Apr 2014 17:40:21 +0000 (18:40 +0100)
committerShadowNinja <shadowninja@minetest.net>
Sun, 27 Apr 2014 18:43:31 +0000 (14:43 -0400)
These two tools wouldn't discharge all the way to zero through use,
unlike most chargeable items.

Incidentally remove a duplicate of the check_for_flashlight() function.

technic/tools/flashlight.lua
technic/tools/sonic_screwdriver.lua

index 02f329946633cffd2ab0720e0fad154b9c0f00b2..1be550e19ab58c93be8ac523bf320bdf8bf03d77 100644 (file)
@@ -40,7 +40,7 @@ local function check_for_flashlight(player)
                        if not meta or not meta.charge then
                                return false
                        end
-                       if meta.charge - 2 > 0 then
+                       if meta.charge >= 2 then
                                meta.charge = meta.charge - 2;
                                technic.set_RE_wear(hotbar[i], meta.charge, flashlight_max_charge)
                                hotbar[i]:set_metadata(minetest.serialize(meta))
@@ -72,31 +72,6 @@ minetest.register_on_leaveplayer(function(player)
        player_positions[player_name] = nil
 end)
 
-
-local function check_for_flashlight(player)
-       if player == nil then
-               return false
-       end
-       local inv = player:get_inventory()
-       local hotbar = inv:get_list("main")
-       for i = 1, 8 do
-               if hotbar[i]:get_name() == "technic:flashlight" then
-                       local meta = minetest.deserialize(hotbar[i]:get_metadata())
-                       if not meta or not meta.charge then
-                               return false
-                       end
-                       if meta.charge - 2 > 0 then
-                               meta.charge = meta.charge - 2;
-                               technic.set_RE_wear(hotbar[i], meta.charge, flashlight_max_charge)
-                               hotbar[i]:set_metadata(minetest.serialize(meta))
-                               inv:set_stack("main", i, hotbar[i])
-                               return true
-                       end
-               end
-       end
-       return false
-end
-
 minetest.register_globalstep(function(dtime)
        for i, player in pairs(minetest.get_connected_players()) do
                local player_name = player:get_player_name()
index 3951b8b6a8aa01164c8a956270c06334d7660569..a9a52d832a0e1101f99122a82f59841ed68700c0 100644 (file)
@@ -30,7 +30,7 @@ minetest.register_tool("technic:sonic_screwdriver", {
                if not meta1 or not meta1.charge then
                        return
                end
-               if meta1.charge - 100 > 0 then
+               if meta1.charge >= 100 then
                        minetest.sound_play("technic_sonic_screwdriver",
                                        {pos = pos, gain = 0.3, max_hear_distance = 10})
                        local p = node.param2