Version 1.3 - auto reconnect, better bot (with sound), animated mounts, bug fixes

This commit is contained in:
OTCv8
2019-11-11 17:10:03 +01:00
parent d78af570ea
commit 1072671986
48 changed files with 458 additions and 154 deletions

View File

@@ -82,7 +82,7 @@ function init()
botButton:setOn(false)
botButton:hide()
botWindow = g_ui.loadUI('bot', modules.game_interface.getRightPanel())
botWindow = g_ui.loadUI('bot', modules.game_interface.getLeftPanel())
botWindow:setup()
contentsPanel = botWindow.contentsPanel
@@ -353,6 +353,10 @@ function clearConfig()
if gameMapPanel then
gameMapPanel:unlockVisibleFloor()
end
if g_sounds then
local botSoundChannel = g_sounds.getChannel(SoundChannels.Bot)
botSoundChannel:stop()
end
end
function refreshConfig()

View File

@@ -5,6 +5,7 @@ MiniWindow
icon: /images/topbuttons/bot
@onClose: modules.game_bot.onMiniWindowClose()
&save: true
&autoOpen: 10
MiniWindowContents
margin-left: 5

View File

@@ -3,10 +3,11 @@ botDefaultConfig = {
{name = "Default", script = [=[
--Default
--IMPORTANT
--In this config editions are not saved
--In 1st config (default) editions are not saved, just select and edit other config
--#main
--#panels
local healTab = addTab("HP")
local attackTab = addTab("Atck")
@@ -14,6 +15,21 @@ local warTab = addTab("War")
local caveTab = addTab("Cave")
Panels.TradeMessage()
Panels.AutoStackItems()
addButton("discord", "Discord & Help", function()
g_platform.openUrl("https://discord.gg/yhqBE4A")
end)
addButton("forum", "Forum", function()
g_platform.openUrl("https://otland.net/forums/otclient.494/")
end)
addButton("github", "Documentation", function()
g_platform.openUrl("https://github.com/OTCv8/otclientv8_bot")
end)
addSeparator("sep")
Panels.Haste(healTab)
Panels.ManaShield(healTab)
@@ -45,13 +61,6 @@ end, caveTab)
--#macros
addSeparator("sep1")
local helloLabel = addLabel("helloLabel", "")
macro(1000, "example macro (time)", nil, function()
helloLabel:setText("Time from start: " .. now)
end)
macro(1000, "this macro does nothing", "f7", function()
end)
@@ -91,6 +100,14 @@ singlehotkey("ctrl+f6", "singlehotkey", function()
usewith(268, player)
end)
singlehotkey("ctrl+f8", "play alarm", function()
playAlarm()
end)
singlehotkey("ctrl+f9", "stop alarm", function()
stopSound()
end)
--#callbacks
local positionLabel = addLabel("positionLabel", "")
@@ -98,6 +115,18 @@ onPlayerPositionChange(function()
positionLabel:setText("Pos: " .. posx() .. "," .. posy() .. "," .. posz())
end)
local s = addSwitch("sdSound", "Play sound when using sd", function(widget)
storage.sdSound = not storage.sdSound
widget:setOn(storage.sdSound)
end)
s:setOn(storage.sdSound)
onUseWith(function(pos, itemId)
if storage.sdSound and itemId == 3155 then
playSound("/sounds/magnum.ogg")
end
end)
--#other
macro(100, "hide useless tiles", "", function()

View File

@@ -84,7 +84,7 @@ context.onContainerOpen = function(callback)
return context.callback("onContainerOpen", callback)
end
-- onContainerUpdateItem -- callback = function(container)
-- onContainerClose -- callback = function(container)
context.onContainerClose = function(callback)
return context.callback("onContainerClose", callback)
end

View File

@@ -0,0 +1,31 @@
local context = G.botContext
context.getSoundChannel = function()
if not g_sounds then
return
end
return g_sounds.getChannel(SoundChannels.Bot)
end
context.playSound = function(file)
local botSoundChannel = context.getSoundChannel()
if not botSoundChannel then
return
end
botSoundChannel:setEnabled(true)
botSoundChannel:stop(0)
botSoundChannel:play(file, 0, 0)
return botSoundChannel
end
context.stopSound = function()
local botSoundChannel = context.getSoundChannel()
if not botSoundChannel then
return
end
botSoundChannel:stop()
end
context.playAlarm = function()
return context.playSound("/sounds/alarm.ogg")
end

View File

@@ -2,3 +2,9 @@ local context = G.botContext
context.encode = function(data) return json.encode(data) end
context.decode = function(text) local status, result = pcall(function() return json.decode(text) end) if status then return result end return {} end
context.displayGeneralBox = function(title, message, buttons, onEnterCallback, onEscapeCallback)
local box = displayGeneralBox(title, message, buttons, onEnterCallback, onEscapeCallback)
box.botWidget = true
return box
end

View File

@@ -10,7 +10,7 @@ Panels.MonsterEditor = function(monster, config, callback, parent)
local window = context.setupUI([[
MainWindow
id: monsterEditor
size: 450 430
size: 450 450
!text: tr("Edit monster")
Label
@@ -163,12 +163,24 @@ MainWindow
maximum: 100
step: 1
Label
id: dangerText
anchors.left: parent.left
anchors.right: parent.horizontalCenter
anchors.top: prev.bottom
margin-right: 5
margin-top: 10
text: If total danger is high (>8) bot won't auto loot until it's low again and will be trying to minimize it
text-align: center
text-wrap: true
text-auto-resize: true
Label
id: attackSpellText
anchors.left: parent.left
anchors.right: parent.horizontalCenter
anchors.top: prev.bottom
margin-right: 10
margin-right: 5
margin-top: 10
text: Attack spell and attack rune are only used when you have more than 30% health
text-align: center
@@ -600,7 +612,6 @@ Panel
local status, result = pcall(function() return json.decode(command.text) end)
if not status then
context.error("Invalid monster config: " .. commands[i].command .. ", error: " .. result)
print(command.text)
else
monsters[commands[i].command] = result
table.insert(labels, commands[i].command)
@@ -634,7 +645,7 @@ Panel
ui.config:addOption(name)
end
if not context.storage.attacking.activeConfig and #context.storage.attacking.configs > 0 then
if (not context.storage.attacking.activeConfig or context.storage.attacking.activeConfig == 0) and #context.storage.attacking.configs > 0 then
context.storage.attacking.activeConfig = 1
end
@@ -687,12 +698,26 @@ Panel
if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then
return
end
context.storage.attacking.enabled = false
table.remove(context.storage.attacking.configs, context.storage.attacking.activeConfig)
context.storage.attacking.activeConfig = 0
refreshConfig()
local questionWindow = nil
local closeWindow = function()
questionWindow:destroy()
end
local removeConfig = function()
closeWindow()
if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then
return
end
context.storage.attacking.enabled = false
table.remove(context.storage.attacking.configs, context.storage.attacking.activeConfig)
context.storage.attacking.activeConfig = 0
refreshConfig()
end
questionWindow = context.displayGeneralBox(tr('Remove config'), tr('Do you want to remove current attacking config?'), {
{ text=tr('Yes'), callback=removeConfig },
{ text=tr('No'), callback=closeWindow },
anchor=AnchorHorizontalCenter}, removeConfig, closeWindow)
end
ui.mAdd.onClick = function()
if not context.storage.attacking.activeConfig or not context.storage.attacking.configs[context.storage.attacking.activeConfig] then
@@ -745,7 +770,7 @@ Panel
return false
end
if monster:isPlayer() and config.monstersOnly then
if monster:isPlayer() and (config.monstersOnly == true or config.monstersOnly == nil) then
return false
end
@@ -770,7 +795,7 @@ Panel
return false
end
local pathTo = context.findPath(context.player:getPosition(), {x=mpos.x, y=mpos.y, z=mpos.z}, maxDistance + 2, { ignoreNonPathable = true, precision=1, allowOnlyVisibleTiles = true })
local pathTo = context.findPath(context.player:getPosition(), {x=mpos.x, y=mpos.y, z=mpos.z}, maxDistance + 2, { ignoreNonPathable = true, precision=1, allowOnlyVisibleTiles = true, ignoreCost = true })
if not pathTo or #pathTo > maxDistance + 1 then
return false
end
@@ -900,7 +925,7 @@ Panel
end
local topItem = tile:getTopUseThing()
if not topItem:isContainer() then
if not topItem or not topItem:isContainer() then
table.remove(lootContainers, 1)
return true
end

View File

@@ -229,7 +229,7 @@ Panel
ui.config:addOption(name)
end
if not context.storage.looting.activeConfig and #context.storage.looting.configs > 0 then
if (not context.storage.looting.activeConfig or context.storage.looting.activeConfig == 0) and #context.storage.looting.configs > 0 then
context.storage.looting.activeConfig = 1
end
@@ -286,12 +286,25 @@ Panel
if not context.storage.looting.activeConfig or not context.storage.looting.configs[context.storage.looting.activeConfig] then
return
end
context.storage.looting.enabled = false
table.remove(context.storage.looting.configs, context.storage.looting.activeConfig)
context.storage.looting.activeConfig = 0
refreshConfig()
local questionWindow = nil
local closeWindow = function()
questionWindow:destroy()
end
local removeConfig = function()
closeWindow()
if not context.storage.looting.activeConfig or not context.storage.looting.configs[context.storage.looting.activeConfig] then
return
end
context.storage.looting.enabled = false
table.remove(context.storage.looting.configs, context.storage.looting.activeConfig)
context.storage.looting.activeConfig = 0
refreshConfig()
end
questionWindow = context.displayGeneralBox(tr('Remove config'), tr('Do you want to remove current looting config?'), {
{ text=tr('Yes'), callback=removeConfig },
{ text=tr('No'), callback=closeWindow },
anchor=AnchorHorizontalCenter}, removeConfig, closeWindow)
end
refreshConfig()
context.onContainerOpen(function(container, prevContainer)
@@ -360,7 +373,7 @@ Panel
if item:getId() == foundItem:getId() then
if foundItem:isStackable() then
if item:getCount() ~= 100 then
g_game.move(foundItem, container:getSlotPosition(j), foundItem:getCount())
g_game.move(foundItem, container:getSlotPosition(j - 1), foundItem:getCount())
return
end
else

View File

@@ -14,4 +14,23 @@ Panels.TradeMessage = function(parent)
context.addTextEdit("autoTradeMessage", context.storage.autoTradeMessage or "I'm using OTClientV8 - https://github.com/OTCv8/otclientv8", function(widget, text)
context.storage.autoTradeMessage = text
end, parent)
end
Panels.AutoStackItems = function(parent)
context.macro(500, "Auto stacking items", nil, function()
local containers = context.getContainers()
for i, container in pairs(containers) do
local toStack = {}
for j, item in ipairs(container:getItems()) do
if item:isStackable() and item:getCount() ~= 100 then
local otherItem = toStack[item:getId()]
if otherItem then
g_game.move(item, otherItem, item:getCount())
return
end
toStack[item:getId()] = container:getSlotPosition(j - 1)
end
end
end
end, parent)
end

View File

@@ -27,7 +27,7 @@ Panels.AttackLeaderTarget = function(parent)
end
end)
context.macro(50, "Attack leader's target", nil, function()
if toAttack and context.storage.attackLeader:len() > 0 then
if toAttack and context.storage.attackLeader:len() > 0 and toAttack ~= g_game.getAttackingCreature() then
g_game.attack(toAttack)
toAttack = nil
end

View File

@@ -269,7 +269,7 @@ Panel
ui.config:addOption(name)
end
if not context.storage.cavebot.activeConfig and #context.storage.cavebot.configs > 0 then
if (not context.storage.cavebot.activeConfig or context.storage.cavebot.activeConfig == 0) and #context.storage.cavebot.configs > 0 then
context.storage.cavebot.activeConfig = 1
end
@@ -331,10 +331,24 @@ Panel
if not context.storage.cavebot.activeConfig or not context.storage.cavebot.configs[context.storage.cavebot.activeConfig] then
return
end
context.storage.cavebot.enabled = false
table.remove(context.storage.cavebot.configs, context.storage.cavebot.activeConfig)
context.storage.cavebot.activeConfig = 0
refreshConfig()
local questionWindow = nil
local closeWindow = function()
questionWindow:destroy()
end
local removeConfig = function()
closeWindow()
if not context.storage.cavebot.activeConfig or not context.storage.cavebot.configs[context.storage.cavebot.activeConfig] then
return
end
context.storage.cavebot.enabled = false
table.remove(context.storage.cavebot.configs, context.storage.cavebot.activeConfig)
context.storage.cavebot.activeConfig = 0
refreshConfig()
end
questionWindow = context.displayGeneralBox(tr('Remove config'), tr('Do you want to remove current waypoints config?'), {
{ text=tr('Yes'), callback=removeConfig },
{ text=tr('No'), callback=closeWindow },
anchor=AnchorHorizontalCenter}, removeConfig, closeWindow)
end
-- waypoint editor
@@ -733,7 +747,7 @@ Panel
ui.list:focusChild(nextChild)
commandExecutionNo = 0
end
end)
end)
return functions
end