Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local globalVariablesDir = "./files/"
- local HUNT_TIME = "07:15:00"
- -- General useful functions
- function buildArea(myPos, range)
- local area = {}
- for i = -range, range do
- for k = -range, range do
- table.insert(area, {x = math.abs(i - myPos.x), y = math.abs(k - myPos.y), z = myPos.z})
- end
- end
- return area
- end
- function getTileItems(pos)
- local ret = {}
- local sqm = gettile(pos.x, pos.y, pos.z)
- if (sqm.count > 0) then
- local items = sqm.items
- for i = 1, (sqm.count - 1) do
- table.insert(ret, {id = items[i].id, count = items[i].count, stackpos = i + 1})
- end
- end
- return ret
- end
- function isInArray(array, value)
- for _, v in pairs(array) do
- if (value == v) then
- return true
- end
- end
- return false
- end
- function getBool(str)
- return ((str == "true") and true or false)
- end
- function myPosition()
- return {x = posx, y = posy, z = posz}
- end
- function waypointPosition()
- return {x = wpt.x, y = wpt.y, z = wpt.z}
- end
- function toStamina(hours)
- return (hours * 60)
- end
- function fromStamina()
- return (stamina / 60)
- end
- function isInRange(fromPosition, toPosition)
- return ((posx >= fromPosition.x and posx <= toPosition.x) and (posy >= fromPosition.y and posy <= toPosition.y))
- end
- -- String helper
- string.trim = function (str)
- return str:gsub("^%s*(.-)%s*$", "%1")
- end
- string.explode = function (str, sep)
- if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
- return {}
- end
- local i, pos, tmp, t = 0, 1, "", {}
- for s, e in function() return string.find(str, sep, pos) end do
- tmp = str:sub(pos, s - 1):trim()
- table.insert(t, tmp)
- pos = e + 1
- i = i + 1
- if(limit ~= nil and i == limit) then
- break
- end
- end
- tmp = str:sub(pos):trim()
- table.insert(t, tmp)
- return t
- end
- -- Global variables, by default iBot doesn't have support for global variables.
- -- There are other ways to do this, but this method has a lot of advantages IMO.
- function getGlobalVariable(var)
- local file = globalVariablesDir .. var .. ".txt"
- local value, open = nil, io.open(file, "r")
- if open then
- for i in io.lines(file) do
- value = i
- end
- open:close()
- else
- -- Lets create it
- local newFile = io.open(file, "w")
- newFile:write(tostring(nil))
- newFile:close()
- return getGlobalVariable(var)
- end
- -- Basic support for arrays.
- if value and value:find("\{.*\}") then
- local ret = {}
- local val = ""
- val = value:gsub("{", "")
- val = val:gsub("}", "")
- for k, v in ipairs(val:explode(",")) do
- table.insert(ret, tonumber(v))
- end
- value = ret
- end
- return value
- end
- function setGlobalVariable(var, value)
- local file = globalVariablesDir .. var .. ".txt"
- local open = io.open(file, "w")
- if open then
- if (type(value) == "table") then
- -- Basic support for arrays.
- local t = "{"
- for k, v in ipairs(value) do
- t = t .. v ..((k < #value) and ", " or "")
- end
- t = t .. "}"
- open:write(t)
- open:close()
- else
- open:write(tostring(value))
- open:close()
- end
- end
- end
- function getBooleanFromGlobal(name)
- local status = getGlobalVariable(name)
- if not status then
- return false
- end
- return getBool(status)
- end
- -- A lot of portection zones, used by my scripts.
- -- If you plan to use this system, you'll need to add posible protection zones where you could get kicked/login.
- local depotPosition =
- {
- { -- svargrond
- fromPosition = {x = 32253, y = 31138},
- toPosition = {x = 32275, y = 31145}
- },
- { -- edron z8
- fromPosition = {x = 33161, y = 31796},
- toPosition = {x = 33175, y = 31814}
- },
- { -- edron z9
- fromPosition = {x = 33163, y = 31803},
- toPosition = {x = 33173, y = 31813}
- },
- { -- port hope
- fromPosition = {x = 32620, y = 32737},
- toPosition = {x = 32634, y = 32748}
- },
- { -- darashia
- fromPosition = {x = 33205, y = 32456},
- toPosition = {x = 33223, y = 32465}
- },
- { -- Liberty bay / part 1
- fromPosition = {x = 32327, y = 32832},
- toPosition = {x = 32341, y = 32839}
- },
- { -- Liberty bay / part 2
- fromPosition = {x = 32332, y = 32840},
- toPosition = {x = 32339, y = 32848}
- }
- }
- local boatPosition =
- {
- { -- Buddel Svargrond
- fromPosition = {x = 32254, y = 31196},
- toPosition = {x = 32257, y = 31198}
- },
- { -- Buddel Camp
- fromPosition = {x = 32019, y = 31293},
- toPosition = {x = 32022, y = 31295}
- },
- { -- Buddel Tyrsung
- fromPosition = {x = 32331, y = 31226},
- toPosition = {x = 32334, y = 31228}
- },
- { -- Shaman Landing
- fromPosition = {x = 32348, y = 31049},
- toPosition = {x = 32354, y = 31051}
- },
- { -- From Shaman Landing (same position from/to 1 SQM only)
- fromPosition = {x = 32312, y = 31074},
- toPosition = {x = 32312, y = 31074}
- },
- { -- From Shaman Landing (same position from/to 1 SQM only)
- fromPosition = {x = 32312, y = 31074},
- toPosition = {x = 32312, y = 31074}
- },
- { -- Svargrond normal boat
- fromPosition = {x = 32334, y = 31105},
- toPosition = {x = 32348, y = 31113}
- },
- { -- Svargrond sea serpent boat
- fromPosition = {x = 32339, y = 31120},
- toPosition = {x = 32355, y = 31126}
- },
- { -- Sea serpent landing on boat 1
- fromPosition = {x = 31942, y = 31046},
- toPosition = {x = 31944, y = 31047}
- },
- { -- Sea serpent landing on boat 2 -- 1 SQM
- fromPosition = {x = 31933, y = 31045},
- toPosition = {x = 31933, y = 31045}
- },
- { -- Liberty bay
- fromPosition = {x = 32281, y = 32883},
- toPosition = {x = 32288, y = 32899}
- },
- { -- Goroma
- fromPosition = {x = 32157, y = 32550},
- toPosition = {x = 32164, y = 32566}
- }
- }
- local safePosition =
- {
- { -- Bank Svargrond
- fromPosition = {x = 32297, y = 31133},
- toPosition = {x = 32303, y = 31134}
- },
- { -- Potion store Svargrond
- fromPosition = {x = 32304, y = 31131},
- toPosition = {x = 32309, y = 31134}
- },
- { -- Trainers Svargrond
- fromPosition = {x = 32245, y = 31064},
- toPosition = {x = 32252, y = 31071}
- },
- { -- edron z7
- fromPosition = {x = 33165, y = 31803},
- toPosition = {x = 33175, y = 31817}
- },
- { -- port hope z 6
- fromPosition = {x = 32619, y = 32736},
- toPosition = {x = 32637, y = 32748}
- },
- { -- port hope z 5
- fromPosition = {x = 32621, y = 32739},
- toPosition = {x = 32635, y = 32747}
- },
- { -- darashia pre-depot z7
- fromPosition = {x = 33212, y = 32452},
- toPosition = {x = 33215, y = 32455}
- },
- { -- svar pre boat
- fromPosition = {x = 32329, y = 31112},
- toPosition = {x = 32345, y = 31119}
- },
- { -- liberty bay potions
- fromPosition = {x = 32344, y = 32807},
- toPosition = {x = 32348, y = 32812}
- },
- { -- Goroma TPs 1
- fromPosition = {x = 32036, y = 32558},
- toPosition = {x = 32036, y = 32558}
- },
- { -- Goroma TPs 2
- fromPosition = {x = 31948, y = 32554},
- toPosition = {x = 31948, y = 32554}
- }
- }
- local housePosition =
- {
- -- House 1
- {
- fromPosition = {x = 32233, y = 31150},
- toPosition = {x = 32238, y = 31153}
- }
- }
- -- "is in" functions.
- function isInDepot()
- if not connected then
- return false
- end
- for k, v in ipairs(depotPosition) do
- if isInRange(v.fromPosition, v.toPosition) then
- return true
- end
- end
- return false
- end
- function isInBoatArea()
- if not connected then
- return false
- end
- for k, v in ipairs(boatPosition) do
- if isInRange(v.fromPosition, v.toPosition) then
- return true
- end
- end
- return false
- end
- function isInHouse()
- if not connected then
- return false
- end
- for k, v in ipairs(housePosition) do
- if isInRange(v.fromPosition, v.toPosition) then
- return true
- end
- end
- return false
- end
- function isInSafePosition()
- if not connected then
- return false
- end
- if isInDepot() then
- return true
- end
- if isInBoatArea() then
- return true
- end
- if isInHouse() then
- return true
- end
- for k, v in ipairs(safePosition) do
- if isInRange(v.fromPosition, v.toPosition) then
- return true
- end
- end
- return false
- end
- function isInTrainers()
- if not connected then
- return false
- end
- -- PAY ATTENTION HERE!
- if isInRange({x = 32245, y = 31064}, {x = 32252, y = 31071}) then
- return true
- end
- return false
- end
- -- You can delete from here.
- -- This one is optional for the system, take it as an example.
- function reOpenBackpacks(backpacks, notEnable)
- if not connected or (back == 0) then
- return false
- end
- local notEnable = notEnable or false
- pausewalking(7000)
- settargeting("off")
- stopattack()
- closewindows()
- setsettings("Settings\\CaveBot\\Settings\\OpenNextBp", "no")
- for k, v in ipairs(backpacks) do
- openitem(v.name, v.parent, (k > 1))
- wait(500, 900)
- resizewindow(v.name, ((v.resize ~= nil) and v.resize or 1))
- wait(500, 900)
- end
- wait(1000)
- if (windowcount() < #backpacks) then
- return reOpenBackpacks(backpacks)
- end
- wait(1000)
- settargeting("on")
- if not notEnable then
- setsettings("Settings\\CaveBot\\Settings\\OpenNextBp", "if cavebot enabled")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement