Advertisement
Guest User

jano lib

a guest
Aug 11th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.92 KB | None | 0 0
  1. local globalVariablesDir = "./files/"
  2. local HUNT_TIME = "07:15:00"
  3.  
  4. -- General useful functions
  5. function buildArea(myPos, range)
  6.     local area = {}
  7.     for i = -range, range do
  8.         for k = -range, range do
  9.             table.insert(area, {x = math.abs(i - myPos.x), y = math.abs(k - myPos.y), z = myPos.z})
  10.         end
  11.     end
  12.     return area
  13. end
  14.  
  15. function getTileItems(pos)
  16.     local ret = {}
  17.     local sqm = gettile(pos.x, pos.y, pos.z)
  18.     if (sqm.count > 0) then
  19.         local items = sqm.items
  20.         for i = 1, (sqm.count - 1) do
  21.             table.insert(ret, {id = items[i].id, count = items[i].count, stackpos = i + 1})
  22.         end
  23.     end
  24.     return ret
  25. end
  26.  
  27. function isInArray(array, value)
  28.     for _, v in pairs(array) do
  29.         if (value == v) then
  30.             return true
  31.         end
  32.     end
  33.     return false
  34. end
  35.  
  36. function getBool(str)
  37.     return ((str == "true") and true or false)
  38. end
  39.  
  40. function myPosition()
  41.     return {x = posx, y = posy, z = posz}
  42. end
  43.  
  44. function waypointPosition()
  45.     return {x = wpt.x, y = wpt.y, z = wpt.z}
  46. end
  47.  
  48. function toStamina(hours)
  49.     return (hours * 60)
  50. end
  51.  
  52. function fromStamina()
  53.     return (stamina / 60)
  54. end
  55.  
  56. function isInRange(fromPosition, toPosition)
  57.     return ((posx >= fromPosition.x and posx <= toPosition.x) and (posy >= fromPosition.y and posy <= toPosition.y))
  58. end
  59.  
  60. -- String helper
  61. string.trim = function (str)
  62.     return str:gsub("^%s*(.-)%s*$", "%1")
  63. end
  64.  
  65. string.explode = function (str, sep)
  66.     if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
  67.         return {}
  68.     end
  69.  
  70.     local i, pos, tmp, t = 0, 1, "", {}
  71.     for s, e in function() return string.find(str, sep, pos) end do
  72.         tmp = str:sub(pos, s - 1):trim()
  73.         table.insert(t, tmp)
  74.         pos = e + 1
  75.  
  76.         i = i + 1
  77.         if(limit ~= nil and i == limit) then
  78.             break
  79.         end
  80.        
  81.     end
  82.  
  83.     tmp = str:sub(pos):trim()
  84.     table.insert(t, tmp)
  85.     return t
  86. end
  87.  
  88. -- Global variables, by default iBot doesn't have support for global variables.
  89. -- There are other ways to do this, but this method has a lot of advantages IMO.
  90. function getGlobalVariable(var)
  91.     local file = globalVariablesDir .. var .. ".txt"
  92.     local value, open = nil, io.open(file, "r")
  93.     if open then
  94.         for i in io.lines(file) do
  95.             value = i
  96.         end
  97.         open:close()
  98.     else
  99.         -- Lets create it
  100.         local newFile = io.open(file, "w")
  101.         newFile:write(tostring(nil))
  102.         newFile:close()
  103.         return getGlobalVariable(var)
  104.     end
  105.    
  106.     -- Basic support for arrays.
  107.     if value and value:find("\{.*\}") then
  108.         local ret = {}
  109.         local val = ""
  110.         val = value:gsub("{", "")
  111.         val = val:gsub("}", "")
  112.         for k, v in ipairs(val:explode(",")) do
  113.             table.insert(ret, tonumber(v))
  114.         end
  115.         value = ret
  116.     end
  117.     return value
  118. end
  119.  
  120. function setGlobalVariable(var, value)
  121.     local file = globalVariablesDir .. var .. ".txt"
  122.     local open = io.open(file, "w")
  123.     if open then
  124.         if (type(value) == "table") then
  125.             -- Basic support for arrays.
  126.            
  127.             local t = "{"
  128.             for k, v in ipairs(value) do
  129.                 t = t .. v ..((k < #value) and ", " or "")
  130.             end
  131.             t = t .. "}"
  132.             open:write(t)
  133.             open:close()
  134.         else
  135.             open:write(tostring(value))
  136.             open:close()
  137.         end
  138.     end
  139. end
  140.  
  141. function getBooleanFromGlobal(name)
  142.     local status = getGlobalVariable(name)
  143.     if not status then
  144.         return false
  145.     end
  146.     return getBool(status)
  147. end
  148.  
  149. -- A lot of portection zones, used by my scripts.
  150. -- If you plan to use this system, you'll need to add posible protection zones where you could get kicked/login.
  151. local depotPosition =
  152.     {
  153.         {   -- svargrond
  154.             fromPosition = {x = 32253, y = 31138},
  155.             toPosition = {x = 32275, y = 31145}
  156.         },
  157.         {   -- edron z8
  158.             fromPosition = {x = 33161, y = 31796},
  159.             toPosition = {x = 33175, y = 31814}
  160.         },
  161.         {   -- edron z9
  162.             fromPosition = {x = 33163, y = 31803},
  163.             toPosition = {x = 33173, y = 31813}
  164.         },
  165.         {   -- port hope
  166.             fromPosition =  {x = 32620, y = 32737},
  167.             toPosition = {x = 32634, y = 32748}
  168.         },
  169.         {   -- darashia
  170.             fromPosition =  {x = 33205, y = 32456},
  171.             toPosition = {x = 33223, y = 32465}
  172.         },
  173.         {   -- Liberty bay / part 1
  174.             fromPosition =  {x = 32327, y = 32832},
  175.             toPosition = {x = 32341, y = 32839}
  176.         },
  177.         {   -- Liberty bay / part 2
  178.             fromPosition =  {x = 32332, y = 32840},
  179.             toPosition = {x = 32339, y = 32848}
  180.         }
  181.     }  
  182.    
  183. local boatPosition =
  184. {
  185.     {   -- Buddel Svargrond
  186.         fromPosition = {x = 32254, y = 31196},
  187.         toPosition = {x = 32257, y = 31198}
  188.     },
  189.     {   -- Buddel Camp
  190.         fromPosition = {x = 32019, y = 31293},
  191.         toPosition = {x = 32022, y = 31295}
  192.     },
  193.     {   -- Buddel Tyrsung
  194.         fromPosition = {x = 32331, y = 31226},
  195.         toPosition = {x = 32334, y = 31228}
  196.     },
  197.     {   -- Shaman Landing
  198.         fromPosition = {x = 32348, y = 31049},
  199.         toPosition = {x = 32354, y = 31051}
  200.     }, 
  201.     {   -- From Shaman Landing (same position from/to 1 SQM only)
  202.         fromPosition = {x = 32312, y = 31074},
  203.         toPosition = {x = 32312, y = 31074}
  204.     },
  205.     {   -- From Shaman Landing (same position from/to 1 SQM only)
  206.         fromPosition = {x = 32312, y = 31074},
  207.         toPosition = {x = 32312, y = 31074}
  208.     },
  209.     {   -- Svargrond normal boat
  210.         fromPosition = {x = 32334, y = 31105},
  211.         toPosition = {x = 32348, y = 31113}
  212.     },
  213.     {   -- Svargrond sea serpent boat
  214.         fromPosition = {x = 32339, y = 31120},
  215.         toPosition = {x = 32355, y = 31126}
  216.     },
  217.     {   -- Sea serpent landing on boat 1
  218.         fromPosition = {x = 31942, y = 31046},
  219.         toPosition = {x = 31944, y = 31047}
  220.     },
  221.     {   -- Sea serpent landing on boat 2 -- 1 SQM
  222.         fromPosition = {x = 31933, y = 31045},
  223.         toPosition = {x = 31933, y = 31045}
  224.     },
  225.     {   -- Liberty bay
  226.         fromPosition = {x = 32281, y = 32883},
  227.         toPosition = {x = 32288, y = 32899}
  228.     },
  229.     {   -- Goroma
  230.         fromPosition = {x = 32157, y = 32550},
  231.         toPosition = {x = 32164, y = 32566}
  232.     }
  233. }
  234.  
  235. local safePosition =
  236. {
  237.     {   -- Bank Svargrond
  238.         fromPosition = {x = 32297, y = 31133},
  239.         toPosition = {x = 32303, y = 31134}
  240.     },
  241.     {   -- Potion store Svargrond
  242.         fromPosition = {x = 32304, y = 31131},
  243.         toPosition = {x = 32309, y = 31134}
  244.     },
  245.     {   -- Trainers Svargrond
  246.         fromPosition = {x = 32245, y = 31064},
  247.         toPosition = {x = 32252, y = 31071}
  248.     },
  249.     {   -- edron z7
  250.         fromPosition = {x = 33165, y = 31803},
  251.         toPosition = {x = 33175, y = 31817}
  252.     },
  253.     {   -- port hope z 6
  254.         fromPosition = {x = 32619, y = 32736},
  255.         toPosition = {x = 32637, y = 32748}
  256.     },
  257.     {   -- port hope z 5
  258.         fromPosition = {x = 32621, y = 32739},
  259.         toPosition = {x = 32635, y = 32747}
  260.     },
  261.     {   -- darashia pre-depot z7
  262.         fromPosition = {x = 33212, y = 32452},
  263.         toPosition = {x = 33215, y = 32455}
  264.     },
  265.     {   -- svar pre boat
  266.         fromPosition = {x = 32329, y = 31112},
  267.         toPosition = {x = 32345, y = 31119}
  268.     },
  269.     {   -- liberty bay potions
  270.         fromPosition = {x = 32344, y = 32807},
  271.         toPosition = {x = 32348, y = 32812}
  272.     }, 
  273.     {   -- Goroma TPs 1
  274.         fromPosition = {x = 32036, y = 32558},
  275.         toPosition = {x = 32036, y = 32558}
  276.     },
  277.    
  278.     {   -- Goroma TPs 2
  279.         fromPosition = {x = 31948, y = 32554},
  280.         toPosition = {x = 31948, y = 32554}
  281.     }  
  282. }
  283.  
  284. local housePosition =
  285. {
  286.     -- House 1
  287.     {
  288.         fromPosition = {x = 32233, y = 31150},
  289.         toPosition = {x = 32238, y = 31153}
  290.     }
  291. }
  292.  
  293. -- "is in" functions.
  294. function isInDepot()
  295.     if not connected then
  296.         return false
  297.     end
  298.    
  299.     for k, v in ipairs(depotPosition) do
  300.         if isInRange(v.fromPosition, v.toPosition) then
  301.             return true
  302.         end
  303.     end
  304.     return false
  305. end
  306.  
  307. function isInBoatArea()
  308.     if not connected then
  309.         return false
  310.     end
  311.    
  312.     for k, v in ipairs(boatPosition) do
  313.         if isInRange(v.fromPosition, v.toPosition) then
  314.             return true
  315.         end
  316.     end
  317.     return false
  318. end
  319.  
  320. function isInHouse()
  321.     if not connected then
  322.         return false
  323.     end
  324.    
  325.     for k, v in ipairs(housePosition) do
  326.         if isInRange(v.fromPosition, v.toPosition) then
  327.             return true
  328.         end
  329.     end
  330.     return false
  331. end
  332.  
  333. function isInSafePosition()
  334.     if not connected then
  335.         return false
  336.     end
  337.    
  338.     if isInDepot() then
  339.         return true
  340.     end
  341.    
  342.     if isInBoatArea() then
  343.         return true
  344.     end
  345.    
  346.     if isInHouse() then
  347.         return true
  348.     end
  349.    
  350.     for k, v in ipairs(safePosition) do
  351.         if isInRange(v.fromPosition, v.toPosition) then
  352.             return true
  353.         end
  354.     end
  355.     return false
  356. end
  357.  
  358. function isInTrainers()
  359.     if not connected then
  360.         return false
  361.     end
  362.    
  363.     -- PAY ATTENTION HERE!
  364.     if isInRange({x = 32245, y = 31064}, {x = 32252, y = 31071}) then
  365.         return true
  366.     end
  367.     return false
  368. end
  369.  
  370. -- You can delete from here.
  371. -- This one is optional for the system, take it as an example.
  372. function reOpenBackpacks(backpacks, notEnable)
  373.     if not connected or (back == 0) then
  374.         return false
  375.     end
  376.    
  377.     local notEnable = notEnable or false
  378.    
  379.     pausewalking(7000)
  380.     settargeting("off")
  381.     stopattack()
  382.     closewindows()
  383.     setsettings("Settings\\CaveBot\\Settings\\OpenNextBp", "no")
  384.    
  385.     for k, v in ipairs(backpacks) do
  386.         openitem(v.name, v.parent, (k > 1))
  387.         wait(500, 900)
  388.         resizewindow(v.name, ((v.resize ~= nil) and v.resize or 1))
  389.         wait(500, 900)
  390.     end
  391.     wait(1000)
  392.    
  393.     if (windowcount() < #backpacks) then
  394.         return reOpenBackpacks(backpacks)
  395.     end
  396.     wait(1000)
  397.     settargeting("on")
  398.    
  399.     if not notEnable then
  400.         setsettings("Settings\\CaveBot\\Settings\\OpenNextBp", "if cavebot enabled")
  401.     end
  402. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement