clean inventory when relogging

This commit is contained in:
Eduardo Bart 2012-04-27 17:35:39 -03:00
parent a329deb8c5
commit 220701e90f
1 changed files with 7 additions and 5 deletions

View File

@ -9,7 +9,7 @@ local inventoryButton
function Inventory.init() function Inventory.init()
connect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange, connect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange }) onFreeCapacityChange = Inventory.onFreeCapacityChange })
connect(g_game, { onGameEnd = Inventory.clear }) connect(g_game, { onGameStart = Inventory.refresh })
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle) Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
@ -25,7 +25,7 @@ end
function Inventory.terminate() function Inventory.terminate()
disconnect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange, disconnect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange }) onFreeCapacityChange = Inventory.onFreeCapacityChange })
disconnect(g_game, { onGameEnd = Inventory.clear }) disconnect(g_game, { onGameStart = Inventory.refresh })
Keyboard.unbindKeyDown('Ctrl+I') Keyboard.unbindKeyDown('Ctrl+I')
@ -40,10 +40,12 @@ end
function Inventory.refresh() function Inventory.refresh()
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
if not player then return end
for i=1,10 do for i=1,10 do
if player then
Inventory.onInventoryChange(player, i, player:getInventoryItem(i)) Inventory.onInventoryChange(player, i, player:getInventoryItem(i))
else
Inventory.onInventoryChange(player, i, nil)
end
end end
end end