Improvement / Fix hotkeys

- Hotkeys now check items in inventory
- Fixed USEONETARGET hotkey bug
This commit is contained in:
Sam 2013-10-05 02:31:44 +02:00
parent 5843b78e87
commit e6977b1b43
2 changed files with 19 additions and 4 deletions

View File

@ -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

View File

@ -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