Version 1.1 - crash bug fix and more advanced bot

This commit is contained in:
OTCv8
2019-11-03 19:20:48 +01:00
parent e65bdb534a
commit 6b5edaf6c8
12 changed files with 191 additions and 15 deletions

View File

@@ -31,7 +31,11 @@ function init()
onGameEnd = offline,
onTalk = botOnTalk,
onUse = botOnUse,
onUseWith = botOnUseWith
onUseWith = botOnUseWith,
onChannelList = botChannelList,
onOpenChannel = botOpenChannel,
onCloseChannel = botCloseChannel,
onChannelEvent = botChannelEvent
})
connect(rootWidget, { onKeyDown = botKeyDown,
@@ -53,6 +57,7 @@ function init()
connect(Container, { onOpen = botContainerOpen,
onClose = botContainerClose,
onUpdateItem = botContainerUpdateItem })
connect(g_map, { onMissle = botOnMissle })
botConfigFile = g_configs.create("/bot.otml")
local config = botConfigFile:get("config")
@@ -153,7 +158,11 @@ function terminate()
onGameEnd = offline,
onTalk = botOnTalk,
onUse = botOnUse,
onUseWith = botOnUseWith
onUseWith = botOnUseWith,
onChannelList = botChannelList,
onOpenChannel = botOpenChannel,
onCloseChannel = botCloseChannel,
onChannelEvent = botChannelEvent
})
disconnect(Tile, { onAddThing = botAddThing, onRemoveThing = botRemoveThing })
@@ -171,6 +180,7 @@ function terminate()
disconnect(Container, { onOpen = botContainerOpen,
onClose = botContainerClose,
onUpdateItem = botContainerUpdateItem })
disconnect(g_map, { onMissle = botOnMissle })
removeEvent(executeEvent)
removeEvent(checkMsgsEvent)
@@ -506,3 +516,33 @@ function botContainerUpdateItem(container, slot, item)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onContainerUpdateItem(container, slot, item) end)
end
function botOnMissle(missle)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onMissle(missle) end)
end
function botOnMissle(missle)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onMissle(missle) end)
end
function botChannelList(channels)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onChannelList(channels) end)
end
function botOpenChannel(channelId, name)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onOpenChannel(channelId, name) end)
end
function botCloseChannel(channelId)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onCloseChannel(channelId) end)
end
function botChannelEvent(channelId, name, event)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onChannelEvent(channelId, name, event) end)
end

View File

@@ -20,6 +20,7 @@ Panels.Health(battleTab)
Panels.HealthItem(battleTab)
Panels.ManaItem(battleTab)
Panels.AttackSpell(battleTab)
Panels.AttackItem(battleTab)
local waypoints = Panels.Waypoints(caveTab)
local attacking = Panels.Attacking(caveTab)
@@ -84,7 +85,17 @@ onPlayerPositionChange(function()
end)
--#other
macro(100, "hide useless tiles", "", function()
for i, tile in ipairs(g_map.getTiles(-1)) do
if not tile:isWalkable(true) then
tile:setFill('black')
end
end
end, toolsTab)
addLabel("mapinfo", "You can use ctrl + plus and ctrl + minus to zoom in / zoom out map", toolsTab)
]=]},
{name = "UI & Healing", script = [=[
-- UI & healing

View File

@@ -28,9 +28,14 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback)
onUseWith = {},
onContainerOpen = {},
onContainerClose = {},
onContainerUpdateItem = {}
onContainerUpdateItem = {},
onMissle = {},
onChannelList = {},
onOpenChannel = {},
onCloseChannel = {},
onChannelEvent = {}
}
-- basic functions & classes
context.print = print
context.pairs = pairs
@@ -216,7 +221,32 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback)
for i, callback in ipairs(context._callbacks.onContainerUpdateItem) do
callback(container, slot, item)
end
end
end,
onMissle = function(missle)
for i, callback in ipairs(context._callbacks.onMissle) do
callback(missle)
end
end,
onChannelList = function(channels)
for i, callback in ipairs(context._callbacks.onChannelList) do
callback(channels)
end
end,
onOpenChannel = function(channelId, channelName)
for i, callback in ipairs(context._callbacks.onOpenChannel) do
callback(channels)
end
end,
onCloseChannel = function(channelId)
for i, callback in ipairs(context._callbacks.onCloseChannel) do
callback(channelId)
end
end,
onChannelEvent = function(channelId, name, event)
for i, callback in ipairs(context._callbacks.onChannelEvent) do
callback(channelId, name, event)
end
end,
}
}
end

View File

@@ -94,6 +94,33 @@ context.onContainerUpdateItem = function(callback)
return context.callback("onContainerUpdateItem", callback)
end
-- onMissle -- callback = function(missle)
context.onMissle = function(callback)
return context.callback("onMissle", callback)
end
-- onChannelList -- callback = function(channels)
context.onChannelList = function(callback)
return context.callback("onChannelList", callback)
end
-- onOpenChannel -- callback = function(channelId, name)
context.onOpenChannel = function(callback)
return context.callback("onOpenChannel", callback)
end
-- onCloseChannel -- callback = function(channelId)
context.onCloseChannel = function(callback)
return context.callback("onCloseChannel", callback)
end
-- onChannelEvent -- callback = function(channelId, name, event)
context.onChannelEvent = function(callback)
return context.callback("onChannelEvent", callback)
end
-- CUSTOM CALLBACKS
-- listen(name, callback) -- callback = function(text, channelId, pos)

View File

@@ -58,8 +58,26 @@ context.walk = function(dir) return modules.game_walking.walk(dir) end
context.turn = function(dir) return g_game.turn(dir) end
-- game releated
context.getChannels = function()
-- return { channelId = channelName }
return modules.game_console.channels
end
context.getChannelId = function(name)
for id, channel in pairs(context.getChannels()) do
if name:lower() == channel:lower() then
return id
end
end
return nil
end
context.say = g_game.talk
context.talk = g_game.talk
context.yell = function(text) g_game.talkChannel(3, 0, text) end
context.talkChannel = function(channel, text) g_game.talkChannel(7, channel, text) end
context.sayChannel = context.talkChannel
context.talkPrivate = function(receiver, text) g_game.talkPrivate(5, receiver, text) end
context.sayPrivate = g_game.talkPrivate
context.saySpell = function(text, lastSpellTimeout)
if context.lastSpell == nil then
@@ -80,8 +98,6 @@ context.setSpellTimeout = function()
context.lastSpell = context.now
end
context.talkPrivate = g_game.talkPrivate
context.sayPrivate = g_game.talkPrivate
context.use = g_game.useInventoryItem
context.usewith = g_game.useInventoryItemWith
context.useWith = g_game.useInventoryItemWith
@@ -94,4 +110,5 @@ context.cancelFollow = g_game.cancelFollow
context.cancelAttackAndFollow = g_game.cancelAttackAndFollow
context.logout = g_game.forceLogout
context.ping = g_game.getPing
context.ping = g_game.getPing

View File

@@ -766,7 +766,7 @@ Panel
end
end
if dist <= 20 then
if dist <= 25 then
if context.player:isWalking() then
return true
end

View File

@@ -27,12 +27,12 @@ end
Panels.AntiParalyze = function(parent)
context.macro(500, "Anti Paralyze", nil, function()
if context.isParalyzed() and context.storage.autoAntiParalyzeText:len() > 0 then
if context.saySpell(context.storage.autoAntiParalyzeText, 2500) then
context.delay(5000)
if context.saySpell(context.storage.autoAntiParalyzeText, 750) then
context.delay(1000)
end
end
end, parent)
context.addTextEdit("autoHasteText", context.storage.autoAntiParalyzeText or "utani hur", function(widget, text)
context.addTextEdit("autoAntiParalyzeText", context.storage.autoAntiParalyzeText or "utani hur", function(widget, text)
context.storage.autoAntiParalyzeText = text
end, parent)
end
@@ -417,3 +417,54 @@ Panels.AttackSpell = function(parent)
context.storage.autoAttackText = text
end, parent)
end
Panels.AttackItem = function(parent)
if not parent then
parent = context.panel
end
local panelName = "autoAttackItem"
local panelId = 1
while parent:getChildById(panelName .. panelId) do
panelId = panelId + 1
end
panelName = panelName .. panelId
local ui = context.setupUI([[
Panel
height: 55
margin-top: 2
Label
id: info
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
text: Auto Attack Item
text-align: center
BotItem
id: item
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: prev.bottom
margin-top: 3
margin-left: 10
]], parent)
ui:setId(panelName)
if not context.storage["autoEating" .. panelId] then
context.storage["autoEating" .. panelId] = {}
end
ui.item.onItemChange = function(widget)
context.storage["autoAttackItem" .. panelId] = widget:getItemId()
end
ui.item:setItemId(context.storage["autoAttackItem" .. panelId] or 3155)
context.macro(500, "Auto attack with item", nil, function()
local target = g_game.getAttackingCreature()
if target and context.getCreatureById(target:getId()) and context.storage["autoAttackItem" .. panelId] >= 100 then
context.useWith(context.storage["autoAttackItem" .. panelId], target)
end
end, parent)
end