mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-10-20 06:33:26 +02:00
Version 1.2 - more advanced bot, new hotkeys, bug fixes
This commit is contained in:
116
modules/game_hotkeys/hotkeys_extra.lua
Normal file
116
modules/game_hotkeys/hotkeys_extra.lua
Normal file
@@ -0,0 +1,116 @@
|
||||
extraHotkeys = {}
|
||||
|
||||
function addExtraHotkey(name, description, callback)
|
||||
table.insert(extraHotkeys, {
|
||||
name = name:lower(),
|
||||
description = tr(description),
|
||||
callback = callback
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
function setupExtraHotkeys(combobox)
|
||||
addExtraHotkey("none", "None", nil)
|
||||
addExtraHotkey("cancelAttack", "Stop attacking", function(repeated)
|
||||
if not repeated then
|
||||
g_game.attack(nil)
|
||||
end
|
||||
end)
|
||||
addExtraHotkey("attackNext", "Attack next target from battle list", function(repeated)
|
||||
if repeated or not modules.game_battle then
|
||||
return
|
||||
end
|
||||
local battlePanel = modules.game_battle.battlePanel
|
||||
local attackedCreature = g_game.getAttackingCreature()
|
||||
local nextChild = nil
|
||||
local breakNext = false
|
||||
for i, child in ipairs(battlePanel:getChildren()) do
|
||||
if not child.creature or child:isDisabled() then
|
||||
break
|
||||
end
|
||||
nextChild = child
|
||||
if breakNext then
|
||||
break
|
||||
end
|
||||
if child.creature == attackedCreature then
|
||||
breakNext = true
|
||||
nextChild = battlePanel:getFirstChild()
|
||||
end
|
||||
end
|
||||
if nextChild and nextChild.creature ~= attackedCreature then
|
||||
g_game.attack(nextChild.creature)
|
||||
end
|
||||
end)
|
||||
|
||||
addExtraHotkey("attackPrevious", "Attack previous target from battle list", function(repeated)
|
||||
if repeated or not modules.game_battle then
|
||||
return
|
||||
end
|
||||
local battlePanel = modules.game_battle.battlePanel
|
||||
local attackedCreature = g_game.getAttackingCreature()
|
||||
local prevChild = battlePanel:getLastChild()
|
||||
for i, child in ipairs(battlePanel:getChildren()) do
|
||||
if not child.creature or child:isDisabled() then
|
||||
break
|
||||
end
|
||||
if child.creature == attackedCreature then
|
||||
break
|
||||
end
|
||||
prevChild = child
|
||||
end
|
||||
if prevChild and prevChild.creature ~= attackedCreature then
|
||||
g_game.attack(prevChild.creature)
|
||||
end
|
||||
end)
|
||||
|
||||
addExtraHotkey("toogleWsad", "Enable/disable wsad walking", function(repeated)
|
||||
if repeated or not modules.game_console then
|
||||
return
|
||||
end
|
||||
if not modules.game_console.consoleToggleChat:isChecked() then
|
||||
modules.game_console.disableChat(true)
|
||||
else
|
||||
modules.game_console.enableChat(true)
|
||||
end
|
||||
end)
|
||||
|
||||
for index, actionDetails in ipairs(extraHotkeys) do
|
||||
combobox:addOption(actionDetails.description)
|
||||
end
|
||||
end
|
||||
|
||||
function executeExtraHotkey(action, repeated)
|
||||
action = action:lower()
|
||||
for index, actionDetails in ipairs(extraHotkeys) do
|
||||
if actionDetails.name == action and actionDetails.callback then
|
||||
actionDetails.callback(repeated)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function translateActionToActionComboboxIndex(action)
|
||||
action = action:lower()
|
||||
for index, actionDetails in ipairs(extraHotkeys) do
|
||||
if actionDetails.name == action then
|
||||
return index
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function translateActionComboboxIndexToAction(index)
|
||||
if index > 1 and index <= #extraHotkeys then
|
||||
return extraHotkeys[index].name
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function getActionDescription(action)
|
||||
action = action:lower()
|
||||
for index, actionDetails in ipairs(extraHotkeys) do
|
||||
if actionDetails.name == action then
|
||||
return actionDetails.description
|
||||
end
|
||||
end
|
||||
return "invalid action"
|
||||
end
|
@@ -10,6 +10,7 @@ HotkeyColors = {
|
||||
itemUseSelf = '#00FF00',
|
||||
itemUseTarget = '#FF0000',
|
||||
itemUseWith = '#F5B325',
|
||||
extraAction = '#FFAA00'
|
||||
}
|
||||
|
||||
hotkeysManagerLoaded = false
|
||||
@@ -76,10 +77,14 @@ function init()
|
||||
g_keyboard.bindKeyPress('Down', function() currentHotkeys:focusNextChild(KeyboardFocusReason) end, hotkeysWindow)
|
||||
g_keyboard.bindKeyPress('Up', function() currentHotkeys:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow)
|
||||
|
||||
if hotkeysWindow.action and setupExtraHotkeys then
|
||||
setupExtraHotkeys(hotkeysWindow.action)
|
||||
end
|
||||
|
||||
connect(g_game, {
|
||||
onGameStart = online,
|
||||
onGameEnd = offline
|
||||
})
|
||||
})
|
||||
|
||||
for i = 1, configSelector:getOptionsCount() do
|
||||
hotkeyConfigs[i] = g_configs.create("/hotkeys_" .. i .. ".otml")
|
||||
@@ -217,7 +222,8 @@ function save()
|
||||
itemId = child.itemId,
|
||||
subType = child.subType,
|
||||
useType = child.useType,
|
||||
value = child.value
|
||||
value = child.value,
|
||||
action = child.action
|
||||
}
|
||||
end
|
||||
|
||||
@@ -310,6 +316,7 @@ function startChooseItem()
|
||||
end
|
||||
|
||||
function clearObject()
|
||||
currentHotkeyLabel.action = nil
|
||||
currentHotkeyLabel.itemId = nil
|
||||
currentHotkeyLabel.subType = nil
|
||||
currentHotkeyLabel.useType = nil
|
||||
@@ -358,6 +365,7 @@ function addKeyCombo(keyCombo, keySettings, focus)
|
||||
currentHotkeyLabel = hotkeyLabel
|
||||
hotkeyLabel.keyCombo = keyCombo
|
||||
hotkeyLabel.autoSend = toboolean(keySettings.autoSend)
|
||||
hotkeyLabel.action = keySettings.action
|
||||
hotkeyLabel.itemId = tonumber(keySettings.itemId)
|
||||
hotkeyLabel.subType = tonumber(keySettings.subType)
|
||||
hotkeyLabel.useType = tonumber(keySettings.useType)
|
||||
@@ -368,6 +376,7 @@ function addKeyCombo(keyCombo, keySettings, focus)
|
||||
hotkeyLabel.itemId = nil
|
||||
hotkeyLabel.subType = nil
|
||||
hotkeyLabel.useType = nil
|
||||
hotkeyLabel.action = nil
|
||||
hotkeyLabel.value = ''
|
||||
end
|
||||
|
||||
@@ -380,13 +389,13 @@ function addKeyCombo(keyCombo, keySettings, focus)
|
||||
end
|
||||
end
|
||||
|
||||
boundCombosCallback[keyCombo] = function() prepareKeyCombo(keyCombo) end
|
||||
boundCombosCallback[keyCombo] = function(k, c, ticks) prepareKeyCombo(keyCombo, ticks) end
|
||||
g_keyboard.bindKeyPress(keyCombo, boundCombosCallback[keyCombo], gameRootPanel)
|
||||
|
||||
if not keyCombo:lower():find("ctrl") then
|
||||
local keyComboCtrl = "Ctrl+" .. keyCombo
|
||||
if not boundCombosCallback[keyComboCtrl] then
|
||||
boundCombosCallback[keyComboCtrl] = function() prepareKeyCombo(keyComboCtrl) end
|
||||
boundCombosCallback[keyComboCtrl] = function(k, c, ticks) prepareKeyCombo(keyComboCtrl, ticks) end
|
||||
g_keyboard.bindKeyPress(keyComboCtrl, boundCombosCallback[keyComboCtrl], gameRootPanel)
|
||||
end
|
||||
end
|
||||
@@ -400,9 +409,9 @@ function addKeyCombo(keyCombo, keySettings, focus)
|
||||
configValueChanged = true
|
||||
end
|
||||
|
||||
function prepareKeyCombo(keyCombo, repeated)
|
||||
function prepareKeyCombo(keyCombo, ticks)
|
||||
local hotKey = hotkeyList[keyCombo]
|
||||
if (keyCombo:lower():find("ctrl") and not hotKey) or (hotKey and hotKey.itemId == nil and (not hotKey.value or #hotKey.value == 0)) then
|
||||
if (keyCombo:lower():find("ctrl") and not hotKey) or (hotKey and hotKey.itemId == nil and (not hotKey.value or #hotKey.value == 0) and not hotKey.action) then
|
||||
keyCombo = keyCombo:gsub("Ctrl%+", "")
|
||||
keyCombo = keyCombo:gsub("ctrl%+", "")
|
||||
hotKey = hotkeyList[keyCombo]
|
||||
@@ -411,14 +420,14 @@ function prepareKeyCombo(keyCombo, repeated)
|
||||
return
|
||||
end
|
||||
|
||||
if hotKey.itemId == nil then -- say
|
||||
scheduleEvent(function() doKeyCombo(keyCombo) end, g_settings.getNumber('hotkeyDelay'))
|
||||
if hotKey.itemId == nil and hotKey.action == nil then -- say
|
||||
scheduleEvent(function() doKeyCombo(keyCombom, ticks >= 5) end, g_settings.getNumber('hotkeyDelay'))
|
||||
else
|
||||
doKeyCombo(keyCombo)
|
||||
doKeyCombo(keyCombo, ticks >= 5)
|
||||
end
|
||||
end
|
||||
|
||||
function doKeyCombo(keyCombo)
|
||||
function doKeyCombo(keyCombo, repeated)
|
||||
if not g_game.isOnline() then return end
|
||||
if modules.game_console and modules.game_console.isChatEnabled() then
|
||||
if keyCombo:len() == 1 then
|
||||
@@ -439,8 +448,10 @@ function doKeyCombo(keyCombo)
|
||||
if hotKey.hotkeyDelayTo ~= nil and g_clock.millis() < hotKey.hotkeyDelayTo then
|
||||
return
|
||||
end
|
||||
|
||||
if hotKey.itemId == nil then
|
||||
|
||||
if hotKey.action then
|
||||
executeExtraHotkey(hotKey.action, repeated)
|
||||
elseif hotKey.itemId == nil then
|
||||
if not hotKey.value or #hotKey.value == 0 then return end
|
||||
if hotKey.autoSend then
|
||||
modules.game_console.sendMessage(hotKey.value)
|
||||
@@ -505,7 +516,10 @@ end
|
||||
|
||||
function updateHotkeyLabel(hotkeyLabel)
|
||||
if not hotkeyLabel then return end
|
||||
if hotkeyLabel.useType == HOTKEY_MANAGER_USEONSELF then
|
||||
if hotkeyLabel.action ~= nil then
|
||||
hotkeyLabel:setText(tr('%s: (Action: %s)', hotkeyLabel.keyCombo, getActionDescription(hotkeyLabel.action)))
|
||||
hotkeyLabel:setColor(HotkeyColors.extraAction)
|
||||
elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEONSELF then
|
||||
hotkeyLabel:setText(tr('%s: (use object on yourself)', hotkeyLabel.keyCombo))
|
||||
hotkeyLabel:setColor(HotkeyColors.itemUseSelf)
|
||||
elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEONTARGET then
|
||||
@@ -532,8 +546,22 @@ function updateHotkeyLabel(hotkeyLabel)
|
||||
end
|
||||
|
||||
function updateHotkeyForm(reset)
|
||||
local hasCustomAction = hotkeysWindow.action and hotkeysWindow.action.currentIndex > 1
|
||||
configValueChanged = true
|
||||
if currentHotkeyLabel then
|
||||
if hotkeysWindow.action then
|
||||
if currentHotkeyLabel then
|
||||
hotkeysWindow.action:enable()
|
||||
if currentHotkeyLabel.action then
|
||||
hotkeysWindow.action:setCurrentIndex(translateActionToActionComboboxIndex(currentHotkeyLabel.action), true)
|
||||
else
|
||||
hotkeysWindow.action:setCurrentIndex(1, true)
|
||||
end
|
||||
else
|
||||
hotkeysWindow.action:disable()
|
||||
hotkeysWindow.action:setCurrentIndex(1, true)
|
||||
end
|
||||
end
|
||||
if currentHotkeyLabel and not hasCustomAction then
|
||||
removeHotkeyButton:enable()
|
||||
if currentHotkeyLabel.itemId ~= nil then
|
||||
hotkeyText:clearText()
|
||||
@@ -601,12 +629,22 @@ end
|
||||
function removeHotkey()
|
||||
if currentHotkeyLabel == nil then return end
|
||||
local gameRootPanel = modules.game_interface.getRootPanel()
|
||||
configValueChanged = true
|
||||
g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo, boundCombosCallback[currentHotkeyLabel.keyCombo], gameRootPanel)
|
||||
boundCombosCallback[currentHotkeyLabel.keyCombo] = nil
|
||||
currentHotkeyLabel:destroy()
|
||||
currentHotkeyLabel = nil
|
||||
end
|
||||
|
||||
function updateHotkeyAction()
|
||||
if not hotkeysManagerLoaded then return end
|
||||
if currentHotkeyLabel == nil then return end
|
||||
configValueChanged = true
|
||||
currentHotkeyLabel.action = translateActionComboboxIndexToAction(hotkeysWindow.action.currentIndex)
|
||||
updateHotkeyLabel(currentHotkeyLabel)
|
||||
updateHotkeyForm()
|
||||
end
|
||||
|
||||
function onHotkeyTextChange(value)
|
||||
if not hotkeysManagerLoaded then return end
|
||||
if currentHotkeyLabel == nil then return end
|
||||
@@ -614,6 +652,7 @@ function onHotkeyTextChange(value)
|
||||
if value == '' then
|
||||
currentHotkeyLabel.autoSend = false
|
||||
end
|
||||
configValueChanged = true
|
||||
updateHotkeyLabel(currentHotkeyLabel)
|
||||
updateHotkeyForm()
|
||||
end
|
||||
@@ -622,6 +661,7 @@ function onSendAutomaticallyChange(autoSend)
|
||||
if not hotkeysManagerLoaded then return end
|
||||
if currentHotkeyLabel == nil then return end
|
||||
if not currentHotkeyLabel.value or #currentHotkeyLabel.value == 0 then return end
|
||||
configValueChanged = true
|
||||
currentHotkeyLabel.autoSend = autoSend
|
||||
updateHotkeyLabel(currentHotkeyLabel)
|
||||
updateHotkeyForm()
|
||||
@@ -630,6 +670,7 @@ end
|
||||
function onChangeUseType(useTypeWidget)
|
||||
if not hotkeysManagerLoaded then return end
|
||||
if currentHotkeyLabel == nil then return end
|
||||
configValueChanged = true
|
||||
if useTypeWidget == useOnSelf then
|
||||
currentHotkeyLabel.useType = HOTKEY_MANAGER_USEONSELF
|
||||
elseif useTypeWidget == useOnTarget then
|
||||
|
@@ -4,6 +4,6 @@ Module
|
||||
author: andrefaramir, BeniS
|
||||
website: https://github.com/edubart/otclient
|
||||
sandboxed: true
|
||||
scripts: [ hotkeys_manager ]
|
||||
scripts: [ hotkeys_extra, hotkeys_manager ]
|
||||
@onLoad: init()
|
||||
@onUnload: terminate()
|
||||
|
@@ -11,7 +11,7 @@ HotkeyListLabel < UILabel
|
||||
MainWindow
|
||||
id: hotkeysWindow
|
||||
!text: tr('Hotkeys')
|
||||
size: 340 445
|
||||
size: 370 475
|
||||
|
||||
@onEnter: modules.game_hotkeys.ok()
|
||||
@onEscape: modules.game_hotkeys.cancel()
|
||||
@@ -80,6 +80,34 @@ MainWindow
|
||||
margin-top: 8
|
||||
@onClick: modules.game_hotkeys.removeHotkey()
|
||||
|
||||
HorizontalSeparator
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 5
|
||||
|
||||
Label
|
||||
anchors.left: parent.left
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 10
|
||||
!text: tr('Extra action:')
|
||||
|
||||
ComboBox
|
||||
id: action
|
||||
anchors.left: prev.right
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.top
|
||||
margin-left: 5
|
||||
margin-top: -4
|
||||
enabled: false
|
||||
@onOptionChange: modules.game_hotkeys.updateHotkeyAction()
|
||||
|
||||
HorizontalSeparator
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 5
|
||||
|
||||
Label
|
||||
id: hotKeyTextLabel
|
||||
!text: tr('Edit hotkey text:')
|
||||
@@ -87,7 +115,7 @@ MainWindow
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 10
|
||||
margin-top: 6
|
||||
|
||||
TextEdit
|
||||
id: hotkeyText
|
||||
@@ -174,7 +202,7 @@ MainWindow
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: next.top
|
||||
margin-bottom: 10
|
||||
margin-bottom: 5
|
||||
|
||||
Button
|
||||
id: okButton
|
||||
|
Reference in New Issue
Block a user