diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua index e40d8d99..ae48c097 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/game_hotkeys/hotkeys_manager.lua @@ -376,7 +376,7 @@ function doKeyCombo(keyCombo) end elseif hotKey.useType == HOTKEY_MANAGER_USE then if g_game.getProtocolVersion() < 780 then - local item = g_game.findItemInContainers(hotKey.itemId, -1) + local item = g_game.findPlayerItem(hotKey.itemId, -1) if item then g_game.use(item) end @@ -385,7 +385,7 @@ function doKeyCombo(keyCombo) end elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then if g_game.getProtocolVersion() < 780 then - local item = g_game.findItemInContainers(hotKey.itemId, -1) + local item = g_game.findPlayerItem(hotKey.itemId, -1) if item then g_game.useWith(item, g_game.getLocalPlayer()) end @@ -395,8 +395,9 @@ function doKeyCombo(keyCombo) elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then local attackingCreature = g_game.getAttackingCreature() if not attackingCreature then return end + if not attackingCreature:getTile() then return end if g_game.getProtocolVersion() < 780 then - local item = g_game.findItemInContainers(hotKey.itemId, -1) + local item = g_game.findPlayerItem(hotKey.itemId, -1) if item then g_game.useWith(item, attackingCreature) end @@ -406,7 +407,7 @@ function doKeyCombo(keyCombo) elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then local item = Item.create(hotKey.itemId) if g_game.getProtocolVersion() < 780 then - local tmpItem = g_game.findItemInContainers(hotKey.itemId, -1) + local tmpItem = g_game.findPlayerItem(hotKey.itemId, -1) if not tmpItem then return true end item = tmpItem end diff --git a/modules/gamelib/game.lua b/modules/gamelib/game.lua index 4593e877..468ece37 100644 --- a/modules/gamelib/game.lua +++ b/modules/gamelib/game.lua @@ -4,6 +4,20 @@ function g_game.getRsa() return currentRsa end +function g_game.findPlayerItem(itemId, subType) + local localPlayer = g_game.getLocalPlayer() + if localPlayer then + for slot = InventorySlotFirst, InventorySlotLast do + local item = localPlayer:getInventoryItem(slot) + if item and item:getId() == itemId and (subType == -1 or item:getSubType() == subType) then + return item + end + end + end + + return g_game.findItemInContainers(itemId, subType) +end + function g_game.chooseRsa(host) if currentRsa ~= CIPSOFT_RSA and currentRsa ~= OTSERV_RSA then return end if host:ends('.tibia.com') or host:ends('.cipsoft.com') then