mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-04-30 03:09:20 +02:00
Version 0.996 beta, small bug fixes
This commit is contained in:
parent
c477637a46
commit
5e76deebac
@ -1,8 +1,8 @@
|
|||||||
Module
|
Module
|
||||||
name: game_bot
|
name: game_bot
|
||||||
description: Bot
|
description: Bot
|
||||||
author: otclient@otclient.ovh
|
author: otclient@otclient.ovh
|
||||||
sandboxed: true
|
sandboxed: true
|
||||||
scripts: [ bot ]
|
scripts: [ bot ]
|
||||||
@onLoad: init()
|
@onLoad: init()
|
||||||
@onUnload: terminate()
|
@onUnload: terminate()
|
||||||
|
@ -1,62 +1,62 @@
|
|||||||
botDefaultConfig = {
|
botDefaultConfig = {
|
||||||
configs = {
|
configs = {
|
||||||
{name = "Example", script = [[
|
{name = "Example", script = [[
|
||||||
--#Example config
|
--#Example config
|
||||||
|
|
||||||
--#macros
|
--#macros
|
||||||
macro(5000, "macro send link", "f5", function()
|
macro(5000, "macro send link", "f5", function()
|
||||||
g_game.talk("macro test - https://github.com/OTCv8/otclient_bot")
|
g_game.talk("macro test - https://github.com/OTCv8/otclient_bot")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
macro(1000, "flag tiles", function()
|
macro(1000, "flag tiles", function()
|
||||||
local staticText = StaticText.create()
|
local staticText = StaticText.create()
|
||||||
staticText:addMessage("t", 9, "xDDD")
|
staticText:addMessage("t", 9, "xDDD")
|
||||||
local tile = player:getTile()
|
local tile = player:getTile()
|
||||||
tile:clearTexts()
|
tile:clearTexts()
|
||||||
tile:addText(staticText)
|
tile:addText(staticText)
|
||||||
for i = 1, 10 do
|
for i = 1, 10 do
|
||||||
schedule(1000 * i, function()
|
schedule(1000 * i, function()
|
||||||
staticText:setText(i)
|
staticText:setText(i)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
schedule(11000, function()
|
schedule(11000, function()
|
||||||
tile:clearTexts()
|
tile:clearTexts()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
addSeparator("spe0")
|
addSeparator("spe0")
|
||||||
|
|
||||||
--#hotkeys
|
--#hotkeys
|
||||||
hotkey('y', 'test hotkey', function() g_game.talk('hotkey elo') end)
|
hotkey('y', 'test hotkey', function() g_game.talk('hotkey elo') end)
|
||||||
|
|
||||||
--#callbacks
|
--#callbacks
|
||||||
|
|
||||||
--#other
|
--#other
|
||||||
addLabel("label1", "Test label 1")
|
addLabel("label1", "Test label 1")
|
||||||
addSeparator("sep1")
|
addSeparator("sep1")
|
||||||
addLabel("label2", "Test label 2")
|
addLabel("label2", "Test label 2")
|
||||||
|
|
||||||
storage.clicks = 0
|
storage.clicks = 0
|
||||||
addButton("button1", "Click me", function()
|
addButton("button1", "Click me", function()
|
||||||
storage.clicks = storage.clicks + 1
|
storage.clicks = storage.clicks + 1
|
||||||
ui.button1:setText("Clicks: " .. storage.clicks)
|
ui.button1:setText("Clicks: " .. storage.clicks)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
HTTP.getJSON("https://api.ipify.org/?format=json", function(data, err)
|
HTTP.getJSON("https://api.ipify.org/?format=json", function(data, err)
|
||||||
if err then
|
if err then
|
||||||
warn("Whoops! Error occured: " .. err)
|
warn("Whoops! Error occured: " .. err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
info("HTTP: My IP is: " .. tostring(data['ip']))
|
info("HTTP: My IP is: " .. tostring(data['ip']))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
info("Bot started")
|
info("Bot started")
|
||||||
|
|
||||||
|
|
||||||
]]},
|
]]},
|
||||||
{}, {}, {}, {}
|
{}, {}, {}, {}
|
||||||
},
|
},
|
||||||
enabled = false,
|
enabled = false,
|
||||||
selectedConfig = 1
|
selectedConfig = 1
|
||||||
}
|
}
|
@ -1,247 +1,247 @@
|
|||||||
function executeBot(config, storage, panel, msg)
|
function executeBot(config, storage, panel, msg)
|
||||||
local context = {}
|
local context = {}
|
||||||
context.panel = panel
|
context.panel = panel
|
||||||
context.storage = storage
|
context.storage = storage
|
||||||
if context.storage.macros == nil then
|
if context.storage.macros == nil then
|
||||||
context.storage.macros = {} -- active macros
|
context.storage.macros = {} -- active macros
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
context.macros = {}
|
context.macros = {}
|
||||||
context.hotkeys = {}
|
context.hotkeys = {}
|
||||||
context.scheduler = {}
|
context.scheduler = {}
|
||||||
context.callbacks = {
|
context.callbacks = {
|
||||||
onKeyDown = {},
|
onKeyDown = {},
|
||||||
onKeyUp = {},
|
onKeyUp = {},
|
||||||
onKeyPress = {},
|
onKeyPress = {},
|
||||||
onTalk = {},
|
onTalk = {},
|
||||||
}
|
}
|
||||||
context.ui = {}
|
context.ui = {}
|
||||||
|
|
||||||
-- basic functions
|
-- basic functions
|
||||||
context.print = print
|
context.print = print
|
||||||
context.pairs = pairs
|
context.pairs = pairs
|
||||||
context.ipairs = ipairs
|
context.ipairs = ipairs
|
||||||
context.tostring = tostring
|
context.tostring = tostring
|
||||||
context.math = math
|
context.math = math
|
||||||
context.table = table
|
context.table = table
|
||||||
context.string = string
|
context.string = string
|
||||||
context.tr = tr
|
context.tr = tr
|
||||||
context.json = json
|
context.json = json
|
||||||
context.regexMatch = regexMatch
|
context.regexMatch = regexMatch
|
||||||
|
|
||||||
-- game functions
|
-- game functions
|
||||||
context.say = g_game.talk
|
context.say = g_game.talk
|
||||||
context.talk = g_game.talk
|
context.talk = g_game.talk
|
||||||
context.talkPrivate = context.talkPrivate
|
context.talkPrivate = context.talkPrivate
|
||||||
context.sayPrivate = context.talkPrivate
|
context.sayPrivate = context.talkPrivate
|
||||||
context.use = g_game.useInventoryItem
|
context.use = g_game.useInventoryItem
|
||||||
context.usewith = g_game.useInventoryItemWith
|
context.usewith = g_game.useInventoryItemWith
|
||||||
context.useWith = g_game.useInventoryItemWith
|
context.useWith = g_game.useInventoryItemWith
|
||||||
context.findItem = g_game.findItemInContainers
|
context.findItem = g_game.findItemInContainers
|
||||||
|
|
||||||
-- classes
|
-- classes
|
||||||
context.g_game = g_game
|
context.g_game = g_game
|
||||||
context.g_map = g_map
|
context.g_map = g_map
|
||||||
context.StaticText = StaticText
|
context.StaticText = StaticText
|
||||||
context.HTTP = HTTP
|
context.HTTP = HTTP
|
||||||
|
|
||||||
-- log functions
|
-- log functions
|
||||||
context.info = function(text) return msg("info", text) end
|
context.info = function(text) return msg("info", text) end
|
||||||
context.warn = function(text) return msg("warn", text) end
|
context.warn = function(text) return msg("warn", text) end
|
||||||
context.error = function(text) return msg("error", text) end
|
context.error = function(text) return msg("error", text) end
|
||||||
context.warning = context.warn
|
context.warning = context.warn
|
||||||
|
|
||||||
-- UI
|
-- UI
|
||||||
context.addSwitch = function(id, text, onClickCallback)
|
context.addSwitch = function(id, text, onClickCallback)
|
||||||
local switch = g_ui.createWidget('BotSwitch', context.panel)
|
local switch = g_ui.createWidget('BotSwitch', context.panel)
|
||||||
switch:setId(id)
|
switch:setId(id)
|
||||||
switch:setText(text)
|
switch:setText(text)
|
||||||
switch.onClick = onClickCallback
|
switch.onClick = onClickCallback
|
||||||
context.ui[id] = switch
|
context.ui[id] = switch
|
||||||
return switch
|
return switch
|
||||||
end
|
end
|
||||||
|
|
||||||
context.addButton = function(id, text, onClickCallback)
|
context.addButton = function(id, text, onClickCallback)
|
||||||
local button = g_ui.createWidget('BotButton', context.panel)
|
local button = g_ui.createWidget('BotButton', context.panel)
|
||||||
button:setId(id)
|
button:setId(id)
|
||||||
button:setText(text)
|
button:setText(text)
|
||||||
button.onClick = onClickCallback
|
button.onClick = onClickCallback
|
||||||
context.ui[id] = button
|
context.ui[id] = button
|
||||||
return button
|
return button
|
||||||
end
|
end
|
||||||
|
|
||||||
context.addLabel = function(id, text)
|
context.addLabel = function(id, text)
|
||||||
local label = g_ui.createWidget('BotLabel', context.panel)
|
local label = g_ui.createWidget('BotLabel', context.panel)
|
||||||
label:setId(id)
|
label:setId(id)
|
||||||
label:setText(text)
|
label:setText(text)
|
||||||
context.ui[id] = label
|
context.ui[id] = label
|
||||||
return label
|
return label
|
||||||
end
|
end
|
||||||
|
|
||||||
context.addSeparator = function(id)
|
context.addSeparator = function(id)
|
||||||
local separator = g_ui.createWidget('BotSeparator', context.panel)
|
local separator = g_ui.createWidget('BotSeparator', context.panel)
|
||||||
separator:setId(id)
|
separator:setId(id)
|
||||||
context.ui[id] = separator
|
context.ui[id] = separator
|
||||||
return separator
|
return separator
|
||||||
end
|
end
|
||||||
|
|
||||||
context.addMacroSwitch = function(name, keys)
|
context.addMacroSwitch = function(name, keys)
|
||||||
local text = name
|
local text = name
|
||||||
if keys:len() > 0 then
|
if keys:len() > 0 then
|
||||||
text = name .. " [" .. keys .. "]"
|
text = name .. " [" .. keys .. "]"
|
||||||
end
|
end
|
||||||
local switch = context.addSwitch("macro_" .. #context.macros, text, function(widget)
|
local switch = context.addSwitch("macro_" .. #context.macros, text, function(widget)
|
||||||
context.storage.macros[name] = not context.storage.macros[name]
|
context.storage.macros[name] = not context.storage.macros[name]
|
||||||
widget:setOn(context.storage.macros[name])
|
widget:setOn(context.storage.macros[name])
|
||||||
end)
|
end)
|
||||||
switch:setOn(context.storage.macros[name])
|
switch:setOn(context.storage.macros[name])
|
||||||
return switch
|
return switch
|
||||||
end
|
end
|
||||||
|
|
||||||
context.addHotkeySwitch = function(name, keys)
|
context.addHotkeySwitch = function(name, keys)
|
||||||
local text = name
|
local text = name
|
||||||
if keys:len() > 0 then
|
if keys:len() > 0 then
|
||||||
text = name .. " [" .. keys .. "]"
|
text = name .. " [" .. keys .. "]"
|
||||||
end
|
end
|
||||||
local switch = context.addSwitch("hotkey_" .. #context.hotkeys, text, nil)
|
local switch = context.addSwitch("hotkey_" .. #context.hotkeys, text, nil)
|
||||||
switch:setOn(false)
|
switch:setOn(false)
|
||||||
return switch
|
return switch
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MAIN BOT FUNCTION
|
-- MAIN BOT FUNCTION
|
||||||
-- macro(timeout, callback)
|
-- macro(timeout, callback)
|
||||||
-- macro(timeout, name, callback)
|
-- macro(timeout, name, callback)
|
||||||
-- macro(timeout, name, hotkey, callback)
|
-- macro(timeout, name, hotkey, callback)
|
||||||
context.macro = function(timeout, name, hotkey, callback)
|
context.macro = function(timeout, name, hotkey, callback)
|
||||||
if type(timeout) ~= 'number' or timeout < 1 then
|
if type(timeout) ~= 'number' or timeout < 1 then
|
||||||
error("Invalid timeout for macro: " .. tostring(timeout))
|
error("Invalid timeout for macro: " .. tostring(timeout))
|
||||||
end
|
end
|
||||||
if type(name) == 'function' then
|
if type(name) == 'function' then
|
||||||
callback = name
|
callback = name
|
||||||
name = ""
|
name = ""
|
||||||
hotkey = ""
|
hotkey = ""
|
||||||
elseif type(hotkey) == 'function' then
|
elseif type(hotkey) == 'function' then
|
||||||
callback = hotkey
|
callback = hotkey
|
||||||
hotkey = ""
|
hotkey = ""
|
||||||
elseif type(callback) ~= 'function' then
|
elseif type(callback) ~= 'function' then
|
||||||
error("Invalid callback for macro: " .. tostring(callback))
|
error("Invalid callback for macro: " .. tostring(callback))
|
||||||
end
|
end
|
||||||
if type(name) ~= 'string' or type(hotkey) ~= 'string' then
|
if type(name) ~= 'string' or type(hotkey) ~= 'string' then
|
||||||
error("Invalid name or hotkey for macro")
|
error("Invalid name or hotkey for macro")
|
||||||
end
|
end
|
||||||
if hotkey:len() > 0 then
|
if hotkey:len() > 0 then
|
||||||
hotkey = retranslateKeyComboDesc(hotkey)
|
hotkey = retranslateKeyComboDesc(hotkey)
|
||||||
end
|
end
|
||||||
|
|
||||||
local switch = nil
|
local switch = nil
|
||||||
if name:len() > 0 then
|
if name:len() > 0 then
|
||||||
if context.storage.macros[name] == nil then
|
if context.storage.macros[name] == nil then
|
||||||
context.storage.macros[name] = true
|
context.storage.macros[name] = true
|
||||||
end
|
end
|
||||||
switch = context.addMacroSwitch(name, hotkey)
|
switch = context.addMacroSwitch(name, hotkey)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(context.macros, {
|
table.insert(context.macros, {
|
||||||
timeout = timeout,
|
timeout = timeout,
|
||||||
name = name,
|
name = name,
|
||||||
callback = callback,
|
callback = callback,
|
||||||
lastExecution = context.now,
|
lastExecution = context.now,
|
||||||
hotkey = hotkey,
|
hotkey = hotkey,
|
||||||
switch = switch
|
switch = switch
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hotkey(keys, callback)
|
-- hotkey(keys, callback)
|
||||||
-- hotkey(keys, name, callback)
|
-- hotkey(keys, name, callback)
|
||||||
context.hotkey = function(keys, name, callback)
|
context.hotkey = function(keys, name, callback)
|
||||||
if type(name) == 'function' then
|
if type(name) == 'function' then
|
||||||
callback = name
|
callback = name
|
||||||
name = ""
|
name = ""
|
||||||
end
|
end
|
||||||
keys = retranslateKeyComboDesc(keys)
|
keys = retranslateKeyComboDesc(keys)
|
||||||
local switch = nil
|
local switch = nil
|
||||||
if name:len() > 0 then
|
if name:len() > 0 then
|
||||||
switch = context.addHotkeySwitch(name, keys)
|
switch = context.addHotkeySwitch(name, keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
context.hotkeys[keys] = {
|
context.hotkeys[keys] = {
|
||||||
name = name,
|
name = name,
|
||||||
callback = callback,
|
callback = callback,
|
||||||
lastExecution = context.now,
|
lastExecution = context.now,
|
||||||
switch = switch
|
switch = switch
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- schedule(timeout, callback)
|
-- schedule(timeout, callback)
|
||||||
context.schedule = function(timeout, callback)
|
context.schedule = function(timeout, callback)
|
||||||
local extecute_time = g_clock.millis() + timeout
|
local extecute_time = g_clock.millis() + timeout
|
||||||
table.insert(context.scheduler, {
|
table.insert(context.scheduler, {
|
||||||
execution = extecute_time,
|
execution = extecute_time,
|
||||||
callback = callback
|
callback = callback
|
||||||
})
|
})
|
||||||
table.sort(context.scheduler, function(a, b) return a.execution < b.execution end)
|
table.sort(context.scheduler, function(a, b) return a.execution < b.execution end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- init context
|
-- init context
|
||||||
context.now = g_clock.millis()
|
context.now = g_clock.millis()
|
||||||
context.time = g_clock.millis()
|
context.time = g_clock.millis()
|
||||||
context.player = g_game.getLocalPlayer()
|
context.player = g_game.getLocalPlayer()
|
||||||
|
|
||||||
-- run script
|
-- run script
|
||||||
assert(load(config, nil, nil, context))()
|
assert(load(config, nil, nil, context))()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
script = function()
|
script = function()
|
||||||
context.now = g_clock.millis()
|
context.now = g_clock.millis()
|
||||||
context.time = g_clock.millis()
|
context.time = g_clock.millis()
|
||||||
|
|
||||||
for i, macro in ipairs(context.macros) do
|
for i, macro in ipairs(context.macros) do
|
||||||
if macro.lastExecution + macro.timeout <= context.now and (macro.name == nil or macro.name:len() < 1 or context.storage.macros[macro.name]) then
|
if macro.lastExecution + macro.timeout <= context.now and (macro.name == nil or macro.name:len() < 1 or context.storage.macros[macro.name]) then
|
||||||
macro.lastExecution = context.now
|
macro.lastExecution = context.now
|
||||||
macro.callback()
|
macro.callback()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
while #context.scheduler > 0 and context.scheduler[1].execution <= g_clock.millis() do
|
while #context.scheduler > 0 and context.scheduler[1].execution <= g_clock.millis() do
|
||||||
context.scheduler[1].callback()
|
context.scheduler[1].callback()
|
||||||
table.remove(context.scheduler, 1)
|
table.remove(context.scheduler, 1)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
callbacks = {
|
callbacks = {
|
||||||
onKeyDown = function(keyCode, keyboardModifiers)
|
onKeyDown = function(keyCode, keyboardModifiers)
|
||||||
local keyDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
local keyDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||||
for i, macro in ipairs(context.macros) do
|
for i, macro in ipairs(context.macros) do
|
||||||
if macro.switch and macro.hotkey == keyDesc then
|
if macro.switch and macro.hotkey == keyDesc then
|
||||||
macro.switch:onClick()
|
macro.switch:onClick()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local hotkey = context.hotkeys[keyDesc]
|
local hotkey = context.hotkeys[keyDesc]
|
||||||
if hotkey and hotkey.switch then
|
if hotkey and hotkey.switch then
|
||||||
hotkey.switch:setOn(true)
|
hotkey.switch:setOn(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
onKeyUp = function(keyCode, keyboardModifiers)
|
onKeyUp = function(keyCode, keyboardModifiers)
|
||||||
local keyDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
local keyDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||||
local hotkey = context.hotkeys[keyDesc]
|
local hotkey = context.hotkeys[keyDesc]
|
||||||
if hotkey and hotkey.switch then
|
if hotkey and hotkey.switch then
|
||||||
hotkey.switch:setOn(false)
|
hotkey.switch:setOn(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
onKeyPress = function(keyCode, keyboardModifiers, autoRepeatTicks)
|
onKeyPress = function(keyCode, keyboardModifiers, autoRepeatTicks)
|
||||||
local keyDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
local keyDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||||
local hotkey = context.hotkeys[keyDesc]
|
local hotkey = context.hotkeys[keyDesc]
|
||||||
if hotkey then
|
if hotkey then
|
||||||
hotkey.lastExecution = context.now
|
hotkey.lastExecution = context.now
|
||||||
hotkey.callback()
|
hotkey.callback()
|
||||||
end
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
onTalk = function(name, level, mode, text, channelId, pos)
|
onTalk = function(name, level, mode, text, channelId, pos)
|
||||||
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
@ -402,7 +402,7 @@ end
|
|||||||
|
|
||||||
function prepareKeyCombo(keyCombo)
|
function prepareKeyCombo(keyCombo)
|
||||||
local hotKey = hotkeyList[keyCombo]
|
local hotKey = hotkeyList[keyCombo]
|
||||||
if keyCombo:lower():find("ctrl") and 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%+", "")
|
||||||
keyCombo = keyCombo:gsub("ctrl%+", "")
|
keyCombo = keyCombo:gsub("ctrl%+", "")
|
||||||
hotKey = hotkeyList[keyCombo]
|
hotKey = hotkeyList[keyCombo]
|
||||||
|
@ -334,6 +334,9 @@ end
|
|||||||
function onVipStateChange(id, state)
|
function onVipStateChange(id, state)
|
||||||
local vipList = vipWindow:getChildById('contentsPanel')
|
local vipList = vipWindow:getChildById('contentsPanel')
|
||||||
local label = vipList:getChildById('vip' .. id)
|
local label = vipList:getChildById('vip' .. id)
|
||||||
|
if not label then
|
||||||
|
return
|
||||||
|
end
|
||||||
local name = label:getText()
|
local name = label:getText()
|
||||||
local description = label:getTooltip()
|
local description = label:getTooltip()
|
||||||
local iconId = label.iconId
|
local iconId = label.iconId
|
||||||
|
BIN
otclient_dx.exe
BIN
otclient_dx.exe
Binary file not shown.
BIN
otclient_gl.exe
BIN
otclient_gl.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user