mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-10-20 06:33:26 +02:00
Version 2.0 - preys, bot updates, ui improvements
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
59
modules/game_bot/functions/script_loader.lua
Normal file
59
modules/game_bot/functions/script_loader.lua
Normal 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
|
@@ -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
|
@@ -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
|
||||
|
Reference in New Issue
Block a user