Bug fixes for bot

This commit is contained in:
OTCv8 2019-10-27 20:24:54 +01:00
parent 95f7b39a10
commit 12e5c1557c
10 changed files with 242 additions and 58 deletions

View File

@ -422,7 +422,9 @@ function EnterGame.doLogin()
g_game.setProtocolVersion(g_game.getClientProtocolVersion(G.clientVersion)) g_game.setProtocolVersion(g_game.getClientProtocolVersion(G.clientVersion))
g_game.setCustomProtocolVersion(0) g_game.setCustomProtocolVersion(0)
g_game.chooseRsa(G.host) g_game.chooseRsa(G.host)
-- g_game.setCustomOs(2) -- windows, optional if #server_params <= 3 then
g_game.setCustomOs(2) -- set os to windows
end
-- extra features from init.lua -- extra features from init.lua
for i = 4, #server_params do for i = 4, #server_params do

View File

@ -181,7 +181,13 @@ function editConfig()
configWindow:raise() configWindow:raise()
configWindow:focus() configWindow:focus()
editorText = {botConfig.configs[config].script or "", ""} editorText = {botConfig.configs[config].script or "", ""}
configEditorText:setText(botConfig.configs[config].script) if #editorText[1] <= 2 then
editorText[1] = "--config name\n\n"
for k, v in ipairs(tabs) do
editorText[1] = editorText[1] .. "--#" .. v .. "\n\n"
end
end
configEditorText:setText(editorText[1])
configEditorText:setEditable(true) configEditorText:setEditable(true)
activeTab = mainTab activeTab = mainTab
configTab:selectTab(mainTab) configTab:selectTab(mainTab)
@ -208,7 +214,11 @@ function restoreMainTab()
editorText = {configEditorText:getText(), ""} editorText = {configEditorText:getText(), ""}
return return
end end
editorText = {editorText[1] .. "--#" .. activeTab:getText():lower() .. "\n" .. configEditorText:getText() .. editorText[2], ""} local currentText = configEditorText:getText()
if #currentText > 0 and currentText:sub(#currentText, #currentText) ~= '\n' then
currentText = currentText .. '\n'
end
editorText = {editorText[1] .. "--#" .. activeTab:getText():lower() .. "\n" .. currentText .. editorText[2], ""}
configEditorText:setText(editorText[1]) configEditorText:setText(editorText[1])
end end
@ -279,7 +289,7 @@ function refreshConfig()
local status, result = pcall(function() return executeBot(config.script, config.storage, botPanel, botMsgCallback) end) local status, result = pcall(function() return executeBot(config.script, config.storage, botPanel, botMsgCallback) end)
if not status then if not status then
errorOccured = true errorOccured = true
statusLabel:setText(tr("Error: " .. tostring(result))) statusLabel:setText("Error: " .. tostring(result))
return return
end end
compiledConfig = result compiledConfig = result
@ -300,7 +310,7 @@ function executeConfig()
local status, result = pcall(function() return compiledConfig.script() end) local status, result = pcall(function() return compiledConfig.script() end)
if not status then if not status then
errorOccured = true errorOccured = true
statusLabel:setText(tr("Error: " .. result)) statusLabel:setText("Error: " .. result)
return return
end end
end end
@ -337,7 +347,7 @@ function botKeyDown(widget, keyCode, keyboardModifiers)
local status, result = pcall(function() compiledConfig.callbacks.onKeyDown(keyCode, keyboardModifiers) end) local status, result = pcall(function() compiledConfig.callbacks.onKeyDown(keyCode, keyboardModifiers) end)
if not status then if not status then
errorOccured = true errorOccured = true
statusLabel:setText(tr("Error: " .. result)) statusLabel:setText("Error: " .. result)
end end
return false return false
end end
@ -347,7 +357,7 @@ function botKeyUp(widget, keyCode, keyboardModifiers)
local status, result = pcall(function() compiledConfig.callbacks.onKeyUp(keyCode, keyboardModifiers) end) local status, result = pcall(function() compiledConfig.callbacks.onKeyUp(keyCode, keyboardModifiers) end)
if not status then if not status then
errorOccured = true errorOccured = true
statusLabel:setText(tr("Error: " .. result)) statusLabel:setText("Error: " .. result)
end end
return false return false
end end
@ -357,7 +367,7 @@ function botKeyPress(widget, keyCode, keyboardModifiers, autoRepeatTicks)
local status, result = pcall(function() compiledConfig.callbacks.onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks) end) local status, result = pcall(function() compiledConfig.callbacks.onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks) end)
if not status then if not status then
errorOccured = true errorOccured = true
statusLabel:setText(tr("Error: " .. result)) statusLabel:setText("Error: " .. result)
end end
return false return false
end end
@ -367,7 +377,7 @@ function botOnTalk(name, level, mode, text, channelId, pos)
local status, result = pcall(function() compiledConfig.callbacks.onTalk(name, level, mode, text, channelId, pos) end) local status, result = pcall(function() compiledConfig.callbacks.onTalk(name, level, mode, text, channelId, pos) end)
if not status then if not status then
errorOccured = true errorOccured = true
statusLabel:setText(tr("Error: " .. result)) statusLabel:setText("Error: " .. result)
end end
return false return false
end end
@ -377,7 +387,7 @@ function botAddThing(tile, thing, asd)
local status, result = pcall(function() compiledConfig.callbacks.onAddThing(tile, thing) end) local status, result = pcall(function() compiledConfig.callbacks.onAddThing(tile, thing) end)
if not status then if not status then
errorOccured = true errorOccured = true
statusLabel:setText(tr("Error: " .. result)) statusLabel:setText("Error: " .. result)
end end
return false return false
end end
@ -387,7 +397,7 @@ function botRemoveThing(tile, thing)
local status, result = pcall(function() compiledConfig.callbacks.onRemoveThing(tile, thing) end) local status, result = pcall(function() compiledConfig.callbacks.onRemoveThing(tile, thing) end)
if not status then if not status then
errorOccured = true errorOccured = true
statusLabel:setText(tr("Error: " .. result)) statusLabel:setText("Error: " .. result)
end end
return false return false
end end

View File

@ -13,16 +13,22 @@ BotLabel < Label
text-align: center text-align: center
text-wrap: true text-wrap: true
BotItem < UIItem
virtual: true
size: 32 32
border: 1 black
&selectable: true
BotSeparator < HorizontalSeparator
margin-top: 5
margin-bottom: 3
BotPanel < Panel BotPanel < Panel
margin-top: 2 margin-top: 2
layout: layout:
type: verticalBox type: verticalBox
fit-children: true fit-children: true
BotSeparator < HorizontalSeparator
margin-top: 5
margin-bottom: 3
MiniWindow MiniWindow
id: botWindow id: botWindow
!text: tr('Bot') !text: tr('Bot')
@ -33,7 +39,7 @@ MiniWindow
MiniWindowContents MiniWindowContents
margin-left: 5 margin-left: 5
margin-right: 5 margin-right: 3
ComboBox ComboBox
id: config id: config

View File

@ -55,7 +55,7 @@ MainWindow
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.left: parent.left
width: 150 width: 150
@onClick: scheduleEvent(function() g_platform.openUrl("https://github.com/OTCv8/otclient_bot") end, 50) @onClick: scheduleEvent(function() g_platform.openUrl("https://github.com/OTCv8/otclientv8_bot") end, 50)
Button Button
id: okButton id: okButton

View File

@ -1,10 +1,11 @@
botDefaultConfig = { botDefaultConfig = {
configs = { configs = {
{name = "Example", script = [[ {name = "Example", script = [=[
--#Example config --#Example
info("Tested on 10.99")
--#main --#main
local widget = setupUI(%[%[ local widget = setupUI([[
Panel Panel
id: redPanel id: redPanel
background: red background: red
@ -16,7 +17,7 @@ Panel
anchors.fill: parent anchors.fill: parent
text: custom ui, otml based text: custom ui, otml based
text-align: center text-align: center
%]%]) ]])
--#macros --#macros
macro(5000, "macro send link", "f5", function() macro(5000, "macro send link", "f5", function()
@ -25,7 +26,7 @@ macro(5000, "macro send link", "f5", function()
end) end)
macro(1000, "flag tiles", function() macro(1000, "flag tiles", function()
tile:setText("Hello =)", "red") player:getTile():setText("Hello =)", "red")
end) end)
macro(25, "auto healing", function() macro(25, "auto healing", function()
@ -85,8 +86,154 @@ HTTP.getJSON("https://api.ipify.org/?format=json", function(data, err)
info("HTTP: My IP is: " .. tostring(data['ip'])) info("HTTP: My IP is: " .. tostring(data['ip']))
end) end)
]]}, ]=]},
{}, {}, {}, {} {name = "UI & Healing", script = [=[
-- UI & healing
info("Tested on 10.99")
--#main
local healthPanel = setupUI([[
Panel
id: healingPanel
height: 150
margin-top: 3
Label
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
text: Use item if
text-align: center
BotItem
id: item1
anchors.left: parent.left
anchors.top: prev.bottom
Label
id: label1
anchors.left: prev.right
anchors.right: parent.right
anchors.top: prev.top
margin: 0 5 0 5
text-align: center
HorizontalScrollBar
id: scroll1
anchors.left: prev.left
anchors.right: prev.right
anchors.top: prev.bottom
margin-top: 5
minimum: 0
maximum: 100
step: 1
BotItem
id: item2
anchors.left: parent.left
anchors.top: item1.bottom
margin-top: 3
Label
id: label2
anchors.left: prev.right
anchors.right: parent.right
anchors.top: prev.top
margin: 0 5 0 5
text-align: center
HorizontalScrollBar
id: scroll2
anchors.left: label2.left
anchors.right: label2.horizontalCenter
anchors.top: label2.bottom
margin-top: 5
minimum: 0
maximum: 100
step: 1
HorizontalScrollBar
id: scroll3
anchors.left: label2.horizontalCenter
anchors.right: label2.right
anchors.top: label2.bottom
margin-top: 5
minimum: 0
maximum: 100
step: 1
Label
anchors.top: item2.bottom
anchors.left: parent.left
anchors.right: parent.right
margin-top: 3
text: Drag item to change it
text-align: center
HorizontalSeparator
anchors.top: prev.bottom
anchors.left: parent.left
anchors.right: parent.right
margin-top: 3
]])
healthPanel.item1:setItemId(storage.healItem1 or 266)
healthPanel.item1.onItemChange = function(widget, item)
storage.healItem1 = item:getId()
widget:setItemId(storage.healItem1)
end
healthPanel.item2:setItemId(storage.healItem2 or 268)
healthPanel.item2.onItemChange = function(widget, item)
storage.healItem2 = item:getId()
widget:setItemId(storage.healItem2)
end
healthPanel.scroll1.onValueChange = function(scroll, value)
storage.healPercent1 = value
healthPanel.label1:setText("0% <= hp <= " .. storage.healPercent1 .. "%")
end
healthPanel.scroll1:setValue(storage.healPercent1 or 50)
healthPanel.scroll2.onValueChange = function(scroll, value)
storage.healPercent2 = value
healthPanel.label2:setText("" .. storage.healPercent2 .. "% <= mana <= " .. storage.healPercent3 .. "%")
end
healthPanel.scroll3.onValueChange = function(scroll, value)
storage.healPercent3 = value
healthPanel.label2:setText("" .. storage.healPercent2 .. "% <= mana <= " .. storage.healPercent3 .. "%")
end
healthPanel.scroll2:setValue(storage.healPercent2 or 40)
healthPanel.scroll3:setValue(storage.healPercent3 or 60)
macro(25, function()
if not storage.healItem1 then
return
end
if healthPanel.scroll1:getValue() >= hppercent() then
useWith(storage.healItem1, player)
delay(500)
end
end)
macro(25, function()
if not storage.healItem2 then
return
end
if storage.healPercent2 <= manapercent() and manapercent() <= storage.healPercent3 then
useWith(storage.healItem2, player)
delay(500)
end
end)
--#macros
--#hotkeys
--#callbacks
--#other
]=]},
{}, {}, {}
}, },
enabled = false, enabled = false,
selectedConfig = 1 selectedConfig = 1

View File

@ -8,7 +8,7 @@ function setupFunctions(context)
context.hp = function() return context.player:getHealth() end context.hp = function() return context.player:getHealth() end
context.mana = function() return context.player:getMana() end context.mana = function() return context.player:getMana() end
context.hppercent = function() return context.player:getHealthPercent() end context.hppercent = function() return context.player:getHealthPercent() end
context.manapercent = function() return context.player:getManaPercent() end context.manapercent = function() if context.player:getMaxMana() <= 1 then return 100 else return math.floor(context.player:getMana() * 100 / context.player:getMaxMana()) end end
context.maxhp = function() return context.player:getMaxHealth() end context.maxhp = function() return context.player:getMaxHealth() end
context.maxmana = function() return context.player:getMaxMana() end context.maxmana = function() return context.player:getMaxMana() end
context.hpmax = function() return context.player:getMaxHealth() end context.hpmax = function() return context.player:getMaxHealth() end

View File

@ -12,11 +12,11 @@ function init()
bugTextEdit = bugReportWindow:getChildById('bugTextEdit') bugTextEdit = bugReportWindow:getChildById('bugTextEdit')
g_keyboard.bindKeyDown(HOTKEY, show) g_keyboard.bindKeyDown(HOTKEY, show, modules.game_interface.getRootPanel())
end end
function terminate() function terminate()
g_keyboard.unbindKeyDown(HOTKEY) g_keyboard.unbindKeyDown(HOTKEY, modules.game_interface.getRootPanel())
bugReportWindow:destroy() bugReportWindow:destroy()
end end

View File

@ -151,9 +151,10 @@ function init()
consoleTabBar.onTabChange = onTabChange consoleTabBar.onTabChange = onTabChange
-- tibia like hotkeys -- tibia like hotkeys
g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels) local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.bindKeyDown('Ctrl+E', removeCurrentTab) g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+H', openHelp) g_keyboard.bindKeyDown('Ctrl+E', removeCurrentTab, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+H', openHelp, gameRootPanel)
consoleToggleChat = consolePanel:getChildById('toggleChat') consoleToggleChat = consolePanel:getChildById('toggleChat')
load() load()
@ -204,18 +205,19 @@ function enableChat(temporarily)
consoleTextEdit:setText("") consoleTextEdit:setText("")
consoleTextEdit:focus() consoleTextEdit:focus()
g_keyboard.unbindKeyDown("Space") local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.unbindKeyDown("Enter") g_keyboard.unbindKeyDown("Space", gameRootPanel)
g_keyboard.unbindKeyDown("Enter", gameRootPanel)
if temporarily then if temporarily then
local quickFunc = function() local quickFunc = function()
if not g_game.isOnline() then return end if not g_game.isOnline() then return end
g_keyboard.unbindKeyDown("Enter") g_keyboard.unbindKeyDown("Enter", gameRootPanel)
g_keyboard.unbindKeyDown("Escape") g_keyboard.unbindKeyDown("Escape", gameRootPanel)
disableChat(temporarily) disableChat(temporarily)
end end
g_keyboard.bindKeyDown("Enter", quickFunc) g_keyboard.bindKeyDown("Enter", quickFunc, gameRootPanel)
g_keyboard.bindKeyDown("Escape", quickFunc) g_keyboard.bindKeyDown("Escape", quickFunc, gameRootPanel)
end end
modules.game_walking.disableWSAD() modules.game_walking.disableWSAD()
@ -241,8 +243,10 @@ function disableChat()
end end
enableChat(true) enableChat(true)
end end
g_keyboard.bindKeyDown("Space", quickFunc)
g_keyboard.bindKeyDown("Enter", quickFunc) local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.bindKeyDown("Space", quickFunc, gameRootPanel)
g_keyboard.bindKeyDown("Enter", quickFunc, gameRootPanel)
modules.game_walking.enableWSAD() modules.game_walking.enableWSAD()
@ -273,9 +277,10 @@ function terminate()
if g_game.isOnline() then clear() end if g_game.isOnline() then clear() end
g_keyboard.unbindKeyDown('Ctrl+O') local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.unbindKeyDown('Ctrl+E') g_keyboard.unbindKeyDown('Ctrl+O', gameRootPanel)
g_keyboard.unbindKeyDown('Ctrl+H') g_keyboard.unbindKeyDown('Ctrl+E', gameRootPanel)
g_keyboard.unbindKeyDown('Ctrl+H', gameRootPanel)
saveCommunicationSettings() saveCommunicationSettings()
@ -1495,7 +1500,8 @@ function online()
serverTab = addTab(tr('Server Log'), false) serverTab = addTab(tr('Server Log'), false)
if g_game.getClientVersion() < 862 then if g_game.getClientVersion() < 862 then
g_keyboard.bindKeyDown('Ctrl+R', openPlayerReportRuleViolationWindow) local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.bindKeyDown('Ctrl+R', openPlayerReportRuleViolationWindow, gameRootPanel)
end end
-- open last channels -- open last channels
local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') local lastChannelsOpen = g_settings.getNode('lastChannelsOpen')
@ -1519,7 +1525,8 @@ end
function offline() function offline()
if g_game.getClientVersion() < 862 then if g_game.getClientVersion() < 862 then
g_keyboard.unbindKeyDown('Ctrl+R') local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.unbindKeyDown('Ctrl+R', gameRootPanel)
end end
clear() clear()
end end

View File

@ -36,7 +36,6 @@ useRadioGroup = nil
currentHotkeys = nil currentHotkeys = nil
boundCombosCallback = {} boundCombosCallback = {}
hotkeysList = {} hotkeysList = {}
lastHotkeyTime = g_clock.millis()
hotkeyConfigs = {} hotkeyConfigs = {}
currentConfig = 1 currentConfig = 1
configValueChanged = false configValueChanged = false
@ -182,8 +181,9 @@ function load(forceDefaults)
end end
function unload() function unload()
local gameRootPanel = modules.game_interface.getRootPanel()
for keyCombo,callback in pairs(boundCombosCallback) do for keyCombo,callback in pairs(boundCombosCallback) do
g_keyboard.unbindKeyPress(keyCombo, callback) g_keyboard.unbindKeyPress(keyCombo, callback, gameRootPanel)
end end
boundCombosCallback = {} boundCombosCallback = {}
currentHotkeys:destroyChildren() currentHotkeys:destroyChildren()
@ -373,21 +373,21 @@ function addKeyCombo(keyCombo, keySettings, focus)
updateHotkeyLabel(hotkeyLabel) updateHotkeyLabel(hotkeyLabel)
local gameRootPanel = modules.game_interface.getRootPanel()
if keyCombo:lower():find("ctrl") then if keyCombo:lower():find("ctrl") then
if boundCombosCallback[keyCombo] then if boundCombosCallback[keyCombo] then
g_keyboard.unbindKeyPress(keyCombo, boundCombosCallback[keyCombo]) g_keyboard.unbindKeyPress(keyCombo, boundCombosCallback[keyCombo], gameRootPanel)
end end
end end
boundCombosCallback[keyCombo] = function() prepareKeyCombo(keyCombo) end boundCombosCallback[keyCombo] = function() prepareKeyCombo(keyCombo) end
g_keyboard.bindKeyPress(keyCombo, boundCombosCallback[keyCombo]) g_keyboard.bindKeyPress(keyCombo, boundCombosCallback[keyCombo], gameRootPanel)
if not keyCombo:lower():find("ctrl") then if not keyCombo:lower():find("ctrl") then
local keyComboCtrl = "Ctrl+" .. keyCombo local keyComboCtrl = "Ctrl+" .. keyCombo
if not boundCombosCallback[keyComboCtrl] then if not boundCombosCallback[keyComboCtrl] then
boundCombosCallback[keyComboCtrl] = function() prepareKeyCombo(keyComboCtrl) end boundCombosCallback[keyComboCtrl] = function() prepareKeyCombo(keyComboCtrl) end
g_keyboard.bindKeyPress(keyComboCtrl, boundCombosCallback[keyComboCtrl]) g_keyboard.bindKeyPress(keyComboCtrl, boundCombosCallback[keyComboCtrl], gameRootPanel)
end end
end end
end end
@ -400,7 +400,7 @@ function addKeyCombo(keyCombo, keySettings, focus)
configValueChanged = true configValueChanged = true
end end
function prepareKeyCombo(keyCombo) function prepareKeyCombo(keyCombo, repeated)
local hotKey = hotkeyList[keyCombo] local hotKey = hotkeyList[keyCombo]
if keyCombo:lower():find("ctrl") or not hotKey or (hotKey.itemId == nil and (not hotKey.value or #hotKey.value == 0)) then if keyCombo:lower():find("ctrl") or not hotKey or (hotKey.itemId == nil and (not hotKey.value or #hotKey.value == 0)) then
keyCombo = keyCombo:gsub("Ctrl%+", "") keyCombo = keyCombo:gsub("Ctrl%+", "")
@ -432,7 +432,11 @@ function doKeyCombo(keyCombo)
local hotKey = hotkeyList[keyCombo] local hotKey = hotkeyList[keyCombo]
if not hotKey then return end if not hotKey then return end
if hotKey.lastHotkeyTime ~= nil and g_clock.millis() - hotKey.lastHotkeyTime < 100 then local hotkeyDelay = 100
if hotKey.hotkeyDelayTo == nil or g_clock.millis() > hotKey.hotkeyDelayTo + hotkeyDelay then
hotkeyDelay = 200 -- for first use
end
if hotKey.hotkeyDelayTo ~= nil and g_clock.millis() < hotKey.hotkeyDelayTo then
return return
end end
@ -443,7 +447,7 @@ function doKeyCombo(keyCombo)
else else
modules.game_console.setTextEditText(hotKey.value) modules.game_console.setTextEditText(hotKey.value)
end end
hotKey.lastHotkeyTime = g_clock.millis() hotKey.hotkeyDelayTo = g_clock.millis() + hotkeyDelay
elseif hotKey.useType == HOTKEY_MANAGER_USE then elseif hotKey.useType == HOTKEY_MANAGER_USE then
if g_game.getClientVersion() < 740 then if g_game.getClientVersion() < 740 then
local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1) local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
@ -453,7 +457,7 @@ function doKeyCombo(keyCombo)
else else
g_game.useInventoryItem(hotKey.itemId) g_game.useInventoryItem(hotKey.itemId)
end end
hotKey.lastHotkeyTime = g_clock.millis() hotKey.hotkeyDelayTo = g_clock.millis() + hotkeyDelay
elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
if g_game.getClientVersion() < 740 then if g_game.getClientVersion() < 740 then
local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1) local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
@ -463,7 +467,7 @@ function doKeyCombo(keyCombo)
else else
g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer(), hotKey.subType or -1) g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer(), hotKey.subType or -1)
end end
hotKey.lastHotkeyTime = g_clock.millis() hotKey.hotkeyDelayTo = g_clock.millis() + hotkeyDelay
elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
local attackingCreature = g_game.getAttackingCreature() local attackingCreature = g_game.getAttackingCreature()
if not attackingCreature then if not attackingCreature then
@ -487,7 +491,7 @@ function doKeyCombo(keyCombo)
else else
g_game.useInventoryItemWith(hotKey.itemId, attackingCreature, hotKey.subType or -1) g_game.useInventoryItemWith(hotKey.itemId, attackingCreature, hotKey.subType or -1)
end end
hotKey.lastHotkeyTime = g_clock.millis() hotKey.hotkeyDelayTo = g_clock.millis() + hotkeyDelay
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
local item = Item.create(hotKey.itemId) local item = Item.create(hotKey.itemId)
if g_game.getClientVersion() < 740 then if g_game.getClientVersion() < 740 then
@ -596,7 +600,8 @@ end
function removeHotkey() function removeHotkey()
if currentHotkeyLabel == nil then return end if currentHotkeyLabel == nil then return end
g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo, boundCombosCallback[currentHotkeyLabel.keyCombo]) local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo, boundCombosCallback[currentHotkeyLabel.keyCombo], gameRootPanel)
boundCombosCallback[currentHotkeyLabel.keyCombo] = nil boundCombosCallback[currentHotkeyLabel.keyCombo] = nil
currentHotkeyLabel:destroy() currentHotkeyLabel:destroy()
currentHotkeyLabel = nil currentHotkeyLabel = nil

View File

@ -25,6 +25,13 @@ function UIItem:onDrop(widget, mousePos, forced)
local item = widget.currentDragThing local item = widget.currentDragThing
if not item or not item:isItem() then return false end if not item or not item:isItem() then return false end
if self.selectable then
if self.onItemChange then
self.onItemChange(self, item)
end
return
end
local toPos = self.position local toPos = self.position
local itemPos = item:getPosition() local itemPos = item:getPosition()
@ -93,7 +100,7 @@ function UIItem:onMouseRelease(mousePosition, mouseButton)
end end
function UIItem:canAcceptDrop(widget, mousePos) function UIItem:canAcceptDrop(widget, mousePos)
if self:isVirtual() or not self:isDraggable() then return false end if not self.selectable and (self:isVirtual() or not self:isDraggable()) then return false end
if not widget or not widget.currentDragThing then return false end if not widget or not widget.currentDragThing then return false end
local children = rootWidget:recursiveGetChildrenByPos(mousePos) local children = rootWidget:recursiveGetChildrenByPos(mousePos)