Browse Source

clean inventory when relogging

Eduardo Bart 8 years ago
parent
commit
220701e90f
1 changed files with 7 additions and 5 deletions
  1. 7
    5
      modules/game_inventory/inventory.lua

+ 7
- 5
modules/game_inventory/inventory.lua View File

@@ -9,7 +9,7 @@ local inventoryButton
9 9
 function Inventory.init()
10 10
   connect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
11 11
                          onFreeCapacityChange = Inventory.onFreeCapacityChange })
12
-  connect(g_game, { onGameEnd = Inventory.clear })
12
+  connect(g_game, { onGameStart = Inventory.refresh })
13 13
 
14 14
   Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
15 15
 
@@ -25,7 +25,7 @@ end
25 25
 function Inventory.terminate()
26 26
   disconnect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
27 27
                          onFreeCapacityChange = Inventory.onFreeCapacityChange })
28
-  disconnect(g_game, { onGameEnd = Inventory.clear })
28
+  disconnect(g_game, { onGameStart = Inventory.refresh })
29 29
 
30 30
   Keyboard.unbindKeyDown('Ctrl+I')
31 31
 
@@ -40,10 +40,12 @@ end
40 40
 
41 41
 function Inventory.refresh()
42 42
   local player = g_game.getLocalPlayer()
43
-  if not player then return end
44
-
45 43
   for i=1,10 do
46
-    Inventory.onInventoryChange(player, i, player:getInventoryItem(i))
44
+    if player then
45
+      Inventory.onInventoryChange(player, i, player:getInventoryItem(i))
46
+    else
47
+      Inventory.onInventoryChange(player, i, nil)
48
+    end
47 49
   end
48 50
 end
49 51
 

Loading…
Cancel
Save