Fixed bug that could lead to item loss.
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Sat, 18 Nov 2017 15:15:04 +0000 (16:15 +0100)
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Sat, 18 Nov 2017 15:15:04 +0000 (16:15 +0100)
init.lua

index 2852e6c..5415438 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -102,10 +102,12 @@ smartshop.receive_fields=function(player,pressed)
                                        -- end\r
                                        if meta:get_int("ghost") ~=1 then\r
                                           -- transition shops to ghost inventory.\r
-                                          if inv:room_for_item("main", pay) and inv:room_for_item("main", stack) then\r
-                                             meta:set_int("ghost", 1)\r
-                                             inv:add_item("main", pay)\r
-                                             inv:add_item("main", stack)\r
+                                          for i=1,4 do\r
+                                             if inv:room_for_item("main", "pay"..i) and inv:room_for_item("main", "give"..i) then\r
+                                                meta:set_int("ghost", 1)\r
+                                                inv:add_item("main", inv:get_stack("pay"..i,1))\r
+                                                inv:add_item("main", inv:get_stack("give"..i,1))\r
+                                             end\r
                                           end\r
                                        end\r
                                        if type==1 and inv:contains_item("main", stack)==false then\r
@@ -157,7 +159,7 @@ smartshop.update_info=function(pos)
        local inv = meta:get_inventory()\r
        local owner=meta:get_string("owner")\r
        local gve=0\r
-       if meta:get_int("sellall")==1 then gve=1 end\r
+--     if meta:get_int("sellall")==1 then gve=1 end\r
        if meta:get_int("type")==0 then\r
                meta:set_string("infotext","(Smartshop by " .. owner ..") Stock is unlimited")\r
                return false\r
@@ -388,7 +390,7 @@ on_construct = function(pos)
                meta:get_inventory():set_size("pay3", 1)\r
                meta:get_inventory():set_size("give4", 1)\r
                meta:get_inventory():set_size("pay4", 1)\r
-               meta:set_int("ghost", 1)\r
+               meta:set_int("ghost", 0)\r
        end,\r
 on_rightclick = function(pos, node, player, itemstack, pointed_thing)\r
                smartshop.showform(pos,player)\r