Added waypoints for bot

This commit is contained in:
OTCv8
2019-11-01 03:44:56 +01:00
parent 85a7fbf0a6
commit 62ff2b1cf5
22 changed files with 865 additions and 32 deletions

View File

@@ -26,7 +26,13 @@ function init()
dofile("defaultconfig")
dofile("executor")
connect(g_game, { onGameStart = online, onGameEnd = offline, onTalk = botOnTalk})
connect(g_game, {
onGameStart = online,
onGameEnd = offline,
onTalk = botOnTalk,
onUse = botOnUse,
onUseWith = botOnUseWith
})
connect(rootWidget, { onKeyDown = botKeyDown,
onKeyUp = botKeyUp,
@@ -56,6 +62,9 @@ function init()
else
botConfig = botDefaultConfig
end
botConfig.configs[1].name = botDefaultConfig.configs[1].name
botConfig.configs[1].script = botDefaultConfig.configs[1].script
botButton = modules.client_topmenu.addRightGameToggleButton('botButton',
tr('Bot'), '/images/topbuttons/bot', toggle)
@@ -136,7 +145,13 @@ function terminate()
onKeyUp = botKeyUp,
onKeyPress = botKeyPress })
disconnect(g_game, { onGameStart = online, onGameEnd = offline, onTalk = botOnTalk})
disconnect(g_game, {
onGameStart = online,
onGameEnd = offline,
onTalk = botOnTalk,
onUse = botOnUse,
onUseWith = botOnUseWith
})
disconnect(Tile, { onAddThing = botAddThing, onRemoveThing = botRemoveThing })
@@ -177,7 +192,7 @@ function online()
botButton:show()
updateEnabled()
if botConfig.enabled then
scheduleEvent(refreshConfig, 1)
scheduleEvent(refreshConfig, 20)
else
clearConfig()
end
@@ -337,7 +352,7 @@ function refreshConfig()
end
errorOccured = false
g_game.enableTileThingLuaCallback(false)
local status, result = pcall(function() return executeBot(config.script, config.storage, botTabs, botMsgCallback) end)
local status, result = pcall(function() return executeBot(config.script, config.storage, botTabs, botMsgCallback, saveConfig) end)
if not status then
errorOccured = true
statusLabel:setText("Error: " .. tostring(result))
@@ -454,3 +469,13 @@ function botCraetureHealthPercentChange(creature, healthPercent)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onCreatureHealthPercentChange(creature, healthPercent) end)
end
function botOnUse(pos, itemId, stackPos, subType)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onUse(pos, itemId, stackPos, subType) end)
end
function botOnUseWith(pos, itemId, target, subType)
if compiledConfig == nil then return false end
safeBotCall(function() compiledConfig.callbacks.onUseWith(pos, itemId, target, subType) end)
end