hotkeys_extra.lua

main 116 lines · 3.1 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1extraHotkeys = {}
2
3function addExtraHotkey(name, description, callback)
4 table.insert(extraHotkeys, {
5 name = name:lower(),
6 description = tr(description),
7 callback = callback
8 })
9
10end
11
12function setupExtraHotkeys(combobox)
13 addExtraHotkey("none", "None", nil)
14 addExtraHotkey("cancelAttack", "Stop attacking", function(repeated)
15 if not repeated then
16 g_game.attack(nil)
17 end
18 end)
19 if combobox == 01 then
20 --addExtraHotkey("attackNext", "Attack next target from battle list", function(repeated)
21 if repeated or not modules.game_battle then
22 return
23 end
24 local battlePanel = modules.game_battle.battlePanel
25 local attackedCreature = g_game.getAttackingCreature()
26 local nextChild = nil
27 for i, child in ipairs(battlePanel:getChildren()) do
28 if not child.creature or not child:isOn() then
29 break
30 end
31 if child.creature ~= attackedCreature then
32 nextChild = child
33 nextChild = battlePanel:getFirstChild()
34 g_game.attack(nextChild.creature)
35 break
36 else
37 g_game.attack(nil)
38 break
39 end
40 end
41 return
42 end
43 --end)
44
45 addExtraHotkey("attackPrevious", "Attack previous target from battle list", function(repeated)
46 if repeated or not modules.game_battle then
47 return
48 end
49 local battlePanel = modules.game_battle.battlePanel
50 local attackedCreature = g_game.getAttackingCreature()
51 local prevChild = nil
52 for i, child in ipairs(battlePanel:getChildren()) do
53 if not child.creature or not child:isOn() then
54 break
55 end
56 if child.creature == attackedCreature then
57 break
58 end
59 prevChild = child
60 end
61 if prevChild and prevChild.creature ~= attackedCreature then
62 g_game.attack(prevChild.creature)
63 end
64 end)
65
66 addExtraHotkey("toogleWsad", "Enable/disable wsad walking", function(repeated)
67 if repeated or not modules.game_console then
68 return
69 end
70 if not modules.game_console.consoleToggleChat:isChecked() then
71 modules.game_console.disableChat(true)
72 else
73 modules.game_console.enableChat(true)
74 end
75 end)
76
77 for index, actionDetails in ipairs(extraHotkeys) do
78 --combobox:addOption(actionDetails.description)
79 end
80end
81
82function executeExtraHotkey(action, repeated)
83 action = action:lower()
84 for index, actionDetails in ipairs(extraHotkeys) do
85 if actionDetails.name == action and actionDetails.callback then
86 actionDetails.callback(repeated)
87 end
88 end
89end
90
91function translateActionToActionComboboxIndex(action)
92 action = action:lower()
93 for index, actionDetails in ipairs(extraHotkeys) do
94 if actionDetails.name == action then
95 return index
96 end
97 end
98 return 1
99end
100
101function translateActionComboboxIndexToAction(index)
102 if index > 1 and index <= #extraHotkeys then
103 return extraHotkeys[index].name
104 end
105 return nil
106end
107
108function getActionDescription(action)
109 action = action:lower()
110 for index, actionDetails in ipairs(extraHotkeys) do
111 if actionDetails.name == action then
112 return actionDetails.description
113 end
114 end
115 return "invalid action"
116end
Top