Version 2.0 - preys, bot updates, ui improvements

This commit is contained in:
OTCv8
2020-01-31 18:01:42 +01:00
parent 48d7eb810d
commit 6bc4188d7a
40 changed files with 737 additions and 72 deletions

View File

@@ -128,11 +128,8 @@ function refresh()
end
-- get list of configs
createDefaultConfigs()
local configs = g_resources.listDirectoryFiles("/bot", false, false)
if #configs == 0 then
createDefaultConfig()
configs = g_resources.listDirectoryFiles("/bot", false, false)
end
-- clean
configList.onOptionChange = nil
@@ -272,22 +269,25 @@ function edit()
editWindow:raise()
end
function createDefaultConfig()
if not g_resources.directoryExists("/bot/default_config") then
g_resources.makeDir("/bot/default_config")
if not g_resources.directoryExists("/bot/default_config") then
return onError("Can't create default_config directory in " .. g_resources.getWriteDir())
function createDefaultConfigs()
local defaultConfigFiles = g_resources.listDirectoryFiles("default_configs", false, false)
for i, config_name in ipairs(defaultConfigFiles) do
if not g_resources.directoryExists("/bot/" .. config_name) then
g_resources.makeDir("/bot/" .. config_name)
if not g_resources.directoryExists("/bot/" .. config_name) then
return onError("Can't create /bot/" .. config_name .. " directory in " .. g_resources.getWriteDir())
end
end
end
local defaultConfigFiles = g_resources.listDirectoryFiles("default_config", true, false)
for i, file in ipairs(defaultConfigFiles) do
local baseName = file:split("/")
baseName = baseName[#baseName]
local contents = g_resources.readFileContents(file)
if contents:len() > 0 then
g_resources.writeFileContents("/bot/default_config/" .. baseName, contents)
end
local defaultConfigFiles = g_resources.listDirectoryFiles("default_configs/" .. config_name, true, false)
for i, file in ipairs(defaultConfigFiles) do
local baseName = file:split("/")
baseName = baseName[#baseName]
local contents = g_resources.readFileContents(file)
if contents:len() > 0 then
g_resources.writeFileContents("/bot/" .. config_name .. "/" .. baseName, contents)
end
end
end
end

View File

@@ -0,0 +1,4 @@
-- to keep it up to date, config is loaded from remote server
loadScript("http://otclient.ovh/bot/default.php?version=" .. getVersion())
-- if you want add custom scripts, just add them bellow or create new lua file

View File

@@ -1,8 +1,25 @@
North = 0
East = 1
South = 2
West = 3
NorthEast = 4
SouthEast = 5
SouthWest = 6
NorthWest = 7
local context = G.botContext
context.North = 0
context.East = 1
context.South = 2
context.West = 3
context.NorthEast = 4
context.SouthEast = 5
context.SouthWest = 6
context.NorthWest = 7
context.InventorySlotOther = 0
context.InventorySlotHead = 1
context.InventorySlotNeck = 2
context.InventorySlotBack = 3
context.InventorySlotBody = 4
context.InventorySlotRight = 5
context.InventorySlotLeft = 6
context.InventorySlotLeg = 7
context.InventorySlotFeet = 8
context.InventorySlotFinger = 9
context.InventorySlotAmmo = 10
context.InventorySlotPurse = 11
context.InventorySlotFirst = 1
context.InventorySlotLast = 10

View File

@@ -78,7 +78,7 @@ 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.sayPrivate = context.talkPrivate
context.talkNpc = function(text)
if g_game.getClientVersion() >= 810 then

View File

@@ -0,0 +1,59 @@
local context = G.botContext
context.loadScript = function(path, onLoadCallback)
if type(path) ~= 'string' then
return context.error("Invalid path for loadScript: " .. tostring(path))
end
if path:lower():find("http") == 1 then
return context.loadRemoteScript(path)
end
if not g_resources.fileExists(path) then
return context.error("File " .. path .. " doesn't exist")
end
local status, result = pcall(function()
assert(load(g_resources.readFileContents(path), path, nil, context))()
end)
if not status then
return context.error("Error while loading script from: " .. path .. ":\n" .. result)
end
if onLoadCallback then
onLoadCallback()
end
end
context.loadRemoteScript = function(url, onLoadCallback)
if type(url) ~= 'string' or url:lower():find("http") ~= 1 then
return context.error("Invalid url for loadRemoteScript: " .. tostring(url))
end
HTTP.get(url, function(data, err)
if err or data:len() == 0 then
-- try to load from cache
if type(context.storage.scriptsCache) ~= 'table' then
context.storage.scriptsCache = {}
end
local cache = context.storage.scriptsCache[url]
if cache and type(cache) == 'string' and cache:len() > 0 then
data = cache
else
return context.error("Can't load script from: " .. url .. ", error: " .. err)
end
end
local status, result = pcall(function()
assert(load(data, url, nil, context))()
end)
if not status then
return context.error("Error while loading script from: " .. url .. ":\n" .. result)
end
-- cache script
if type(context.storage.scriptsCache) ~= 'table' then
context.storage.scriptsCache = {}
end
context.storage.scriptsCache[url] = data
if onLoadCallback then
onLoadCallback()
end
end)
end

View File

@@ -13,3 +13,7 @@ context.doScreenshot = function(filename)
g_app.doScreenshot(filename)
end
context.screenshot = context.doScreenshot
context.getVersion = function()
return g_app.getVersion()
end

View File

@@ -9,6 +9,10 @@ context.setupUI = function(otml, parent)
return widget
end
context.importStyle = function(otml)
return g_ui.importStyleFromString(otml)
end
context.addTab = function(name)
local tab = context.tabs:getTab(name)
if tab then -- return existing tab