Advertisement
Guest User

sayildlib

a guest
Aug 13th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 30.75 KB | None | 0 0
  1. -- Sayild Library 12/08/2012 --
  2.  
  3. function qs1(tablename, left, right)
  4.     if type(tablename) == 'table' then
  5.         left = left or 1
  6.         right = right or #tablename
  7.         local i,j,x
  8.         if right-left+1 <= 25 then
  9.             for i=left+1, right do
  10.                 x=tablename[i]
  11.                 j=i-1
  12.                 while j>=left and x<tablename[j] do
  13.                     tablename[j+1]=tablename[j]
  14.                     j=j-1
  15.                 end
  16.                 tablename[j+1]=x
  17.             end
  18.         else
  19.             i,j,x = left, right, tablename[math.floor((left+right)/2)]
  20.             local temp
  21.             repeat
  22.                 while tablename[i]<x and i < right do
  23.                     i = i+1
  24.                 end
  25.                 while tablename[j]>x and j > left do
  26.                     j = j-1
  27.                 end
  28.                 if (i <= j) then
  29.                     temp = tablename[i]
  30.                     tablename[i] = tablename[j]
  31.                     tablename[j] = temp
  32.                     i = i+1
  33.                     j = j-1
  34.                 end
  35.             until i > j
  36.             if (left < j) then
  37.                 qs1(tablename, left, j)
  38.             end
  39.             if (right > i) then
  40.                 qs1(tablename, i, right)
  41.             end
  42.         end
  43.     end
  44. end
  45.  
  46. function qs2(tablename, left, right, argument)
  47.     if type(tablename) == 'table' then
  48.         left = left or 1
  49.         right = right or #tablename
  50.         local i,j,x
  51.         if right-left+1 <= 25 then
  52.             for i=left+1, right do
  53.                 x=tablename[i]
  54.                 j=i-1
  55.                 while j>=left and x[argument] < tablename[j][argument] do
  56.                     tablename[j+1]=tablename[j]
  57.                     j=j-1
  58.                 end
  59.                 tablename[j+1]=x
  60.             end
  61.         else
  62.             i,j,x = left, right, tablename[math.floor((left+right)/2)][argument]
  63.             local temp
  64.             repeat
  65.                 while tablename[i][argument]<x and i < right do
  66.                     i = i+1
  67.                 end
  68.                 while tablename[j][argument]>x and j > left do
  69.                     j = j-1
  70.                 end
  71.                 if (i <= j) then
  72.                     temp = tablename[i]
  73.                     tablename[i] = tablename[j]
  74.                     tablename[j] = temp
  75.                     i = i+1
  76.                     j = j-1
  77.                 end
  78.             until i > j
  79.             if (left < j) then
  80.                 qs2(tablename, left, j, argument)
  81.             end
  82.             if (right > i) then
  83.                 qs2(tablename, i, right, argument)
  84.             end
  85.         end
  86.     end
  87. end
  88.  
  89. function qs3(tablename, left, right)
  90.     if type(tablename) == 'table' then
  91.         left = left or 1
  92.         right = right or #tablename
  93.         local i,j,x
  94.         if right-left+1 <= 25 then
  95.             for i=left+1, right do
  96.                 x=tablename[i]
  97.                 j=i-1
  98.                 while j>=left and x>tablename[j] do
  99.                     tablename[j+1]=tablename[j]
  100.                     j=j-1
  101.                 end
  102.                 tablename[j+1]=x
  103.             end
  104.         else
  105.             i,j,x = left, right, tablename[math.floor((left+right)/2)]
  106.             local temp
  107.             repeat
  108.                 while tablename[i]>x and i < right do
  109.                     i = i+1
  110.                 end
  111.                 while tablename[j]<x and j > left do
  112.                     j = j-1
  113.                 end
  114.                 if (i <= j) then
  115.                     temp = tablename[i]
  116.                     tablename[i] = tablename[j]
  117.                     tablename[j] = temp
  118.                     i = i+1
  119.                     j = j-1
  120.                 end
  121.             until i > j
  122.             if (left < j) then
  123.                 qs3(tablename, left, j)
  124.             end
  125.             if (right > i) then
  126.                 qs3(tablename, i, right)
  127.             end
  128.         end
  129.     end
  130. end
  131.  
  132. function qs4(tablename, left, right, argument)
  133.     if type(tablename) == 'table' then
  134.         left = left or 1
  135.         right = right or #tablename
  136.         local i,j,x
  137.         if right-left+1 <= 25 then
  138.             for i=left+1, right do
  139.                 x=tablename[i]
  140.                 j=i-1
  141.                 while j>=left and x[argument]>tablename[j][argument] do
  142.                     tablename[j+1]=tablename[j]
  143.                     j=j-1
  144.                 end
  145.                 tablename[j+1]=x
  146.             end
  147.         else
  148.             i,j,x = left, right, tablename[math.floor((left+right)/2)][argument]
  149.             local temp
  150.             repeat
  151.                 while tablename[i][argument]>x and i < right do
  152.                     i = i+1
  153.                 end
  154.                 while tablename[j][argument]<x and j > left do
  155.                     j = j-1
  156.                 end
  157.                 if (i <= j) then
  158.                     temp = tablename[i]
  159.                     tablename[i] = tablename[j]
  160.                     tablename[j] = temp
  161.                     i = i+1
  162.                     j = j-1
  163.                 end
  164.             until i > j
  165.             if (left < j) then
  166.                 qs4(tablename, left, j, argument)
  167.             end
  168.             if (right > i) then
  169.                 qs4(tablename, i, right, argument)
  170.             end
  171.         end
  172.     end
  173. end
  174.  
  175.  
  176. function seq1(tablename,value)
  177.    if type(tablename) == 'table' then
  178.       for i,j in ipairs(tablename) do
  179.          if j == value then
  180.             return i
  181.          end
  182.       end
  183.    end
  184.    return
  185. end
  186.  
  187. function seq2(tablename,value,argument)
  188.    if type(tablename) == 'table' then
  189.       for i,j in ipairs(tablename) do
  190.          if j[argument] == value then
  191.             return i
  192.          end
  193.       end
  194.    end
  195.    return
  196. end
  197.  
  198. function bin1(tablename,value)
  199.    if type(tablename) == 'table' then
  200.       local left,right = 1, #tablename
  201.       while left <= right do
  202.          local mid = math.floor((right+left)/2)
  203.          if tablename[mid] == value then
  204.             return mid
  205.          end
  206.          if tablename[mid] > value then
  207.             right = mid-1
  208.          else
  209.             left = mid+1
  210.          end
  211.       end
  212.    end
  213.    return
  214. end
  215.  
  216. function bin2(tablename,value,argument)
  217.    if type(tablename) == 'table' then
  218.       local left,right = 1, #tablename
  219.       while left <= right do
  220.          local mid = math.floor((right+left)/2)
  221.          if tablename[mid][argument] == value then
  222.             return mid
  223.          end
  224.          if tablename[mid][argument] > value then
  225.             right = mid-1
  226.          else
  227.             left = mid+1
  228.          end
  229.       end
  230.    end
  231.    return
  232. end
  233.  
  234. function table:find(value,argument) --Working
  235.    if argument then
  236.       return seq2(self,value,argument)
  237.    end
  238.    return seq1(self,value)
  239. end
  240.  
  241. function table:newsort(argument, order) --Working
  242.     if argument == 'asc' or argument == 'desc' then
  243.         order = argument
  244.         argument = false
  245.     end
  246.     order = order or 'asc'
  247.     if order == 'asc' then
  248.         if argument then
  249.             qs2(self,1,#self,argument)
  250.         else
  251.             qs1(self,1,#self)
  252.         end
  253.     else
  254.         if argument then
  255.             qs4(self,1,#self,argument)
  256.         else
  257.             qs3(self,1,#self)
  258.         end
  259.     end
  260. end
  261.  
  262. function table:binaryfind(value,argument) --Working
  263.    if argument then
  264.       return bin2(self,value,argument)
  265.    end
  266.    return bin1(self,value)
  267. end
  268.  
  269. function dropflask()
  270.    dropitems(283,284,285)
  271. end
  272.  
  273. function depositall()
  274.    say("Hi")
  275.    wait(1500,2500)
  276.    npcsay("Deposit all")
  277.    wait(300,500)
  278.    npcsay("yes")
  279.    wait(200,300)
  280. end
  281.  
  282. function travelabdendriel()
  283.    say("Hi")
  284.    wait(1500,2500)
  285.    npcsay("A'bdendriel")
  286.    wait(300,500)
  287.    npcsay("yes")
  288.    wait(200,300)
  289. end
  290.  
  291. function travelvenore()
  292.    say("Hi")
  293.    wait(1500,2500)
  294.    npcsay("Venore")
  295.    wait(300,500)
  296.    npcsay("yes")
  297.    wait(200,300)
  298. end
  299.  
  300. function travelsvargrond()
  301.    say("Hi")
  302.    wait(1500,2500)
  303.    npcsay("Svargrond")
  304.    wait(300,500)
  305.    npcsay("yes")
  306.    wait(200,300)
  307. end
  308.  
  309. function traveledron()
  310.    say("Hi")
  311.    wait(1500,2500)
  312.    npcsay("Edron")
  313.    wait(300,500)
  314.    npcsay("yes")
  315.    wait(200,300)
  316. end
  317.  
  318. function travelcarlin()
  319.    say("Hi")
  320.    wait(1500,2500)
  321.    npcsay("Carlin")
  322.    wait(300,500)
  323.    npcsay("yes")
  324.    wait(200,300)
  325. end
  326.  
  327. function travelthais()
  328.    say("Hi")
  329.    wait(1500,2500)
  330.    npcsay("Thais")
  331.    wait(300,500)
  332.    npcsay("yes")
  333.    wait(200,300)
  334. end
  335.  
  336. function traveldarashia()
  337.    say("Hi")
  338.    wait(1500,2500)
  339.    npcsay("Darashia")
  340.    wait(300,500)
  341.    npcsay("yes")
  342.    wait(200,300)
  343.     npcsay("yes")
  344.    wait(200,300)
  345. end
  346.  
  347. function travelankrahmun()
  348.    say("Hi")
  349.    wait(1500,2500)
  350.    npcsay("Ankrahmun")
  351.    wait(300,500)
  352.    npcsay("yes")
  353.    wait(200,300)
  354. end
  355.  
  356. function travellibertybay()
  357.    say("Hi")
  358.    wait(1500,2500)
  359.    npcsay("Liberty Bay")
  360.    wait(300,500)
  361.    npcsay("yes")
  362.    wait(200,300)
  363. end
  364.  
  365. function travelyalahar()
  366.    say("Hi")
  367.    wait(1500,2500)
  368.    npcsay("Yalahar")
  369.    wait(300,500)
  370.    npcsay("yes")
  371.    wait(200,300)
  372. end
  373.  
  374. function travelporthope()
  375.    say("Hi")
  376.    wait(1500,2500)
  377.    npcsay("Port Hope")
  378.    wait(300,500)
  379.    npcsay("yes")
  380.    wait(200,300)
  381. end
  382.  
  383. function travelfarmine()
  384.    say("Hi")
  385.    wait(1500,2500)
  386.    npcsay("Farmine")
  387.    wait(300,500)
  388.    npcsay("yes")
  389.    wait(200,300)
  390. end
  391.  
  392. function travelgoroma()
  393.    say("Hi")
  394.    wait(1500,2500)
  395.    npcsay("Goroma")
  396.    wait(300,500)
  397.    npcsay("yes")
  398.    wait(200,300)
  399. end
  400.  
  401. function opentrade()
  402.    if not tradeopen then
  403.       say("Hi")
  404.       wait(1500,2500)
  405.       npcsay("Trade")
  406.       wait(600,800)
  407.       updateworld()
  408.    end
  409. end
  410.  
  411. function softequip()
  412.    if boots ~= 6529 then
  413.       if itemcount("soft boots") < 0 then
  414.          moveitems("soft boots","all","boots",1)
  415.       end
  416.    end
  417. end
  418.  
  419. function ssondeath()
  420. local takess = true
  421.     if hppc == 0 then
  422.     if takess then
  423.         screenshot()
  424.     end
  425.         takess = false
  426.     else
  427.         takess = true
  428.     end
  429. end
  430.  
  431. function lifering()
  432. if itemcount('life ring') < 0 then
  433.         moveitem('life ring', 'all', 'ring', 1)
  434.     end
  435. end
  436.  
  437. function sdalert()
  438.  if itemcount(3155) <= 10 then
  439.     playsound ('alert.wav')
  440.         end
  441. end
  442.  
  443. function getbpindex(bpcolor) --by golfinhu
  444.     local bpcolors = {'beach', 'blue', 'brocade', 'brown', 'camouflage', 'crown', 'demon', 'dragon', 'expedition', 'fur', 'golden', 'green', 'grey', 'heart', 'holding', 'minotaur', 'moon', 'orange', 'pirate', 'purple', 'red', 'santa', 'yellow', 'jewelled'}
  445.     local bpcolor = bpcolor:lower()
  446.     if bpcolor:find('holding') then
  447.         bpcolor = 'holding'
  448.     elseif bpcolor:token(1) == 'backpack' then
  449.         bpcolor = 'brown'
  450.     end
  451.     local color = bpcolor:token(1)
  452.     if not table.find(bpcolors, color) then
  453.         printerror('Bp color not valid')
  454.         return false
  455.     end
  456.     local bps = {}
  457.     for i = 0, windowcount() - 1 do
  458.         local bpname = getcontainer(i).name:lower()
  459.         if bpname == 'backpack of holding' then
  460.             bpname = 'holding backpack'
  461.         elseif bpname == 'backpack' then
  462.             bpname = 'brown backpack'
  463.         end
  464.         if bpname == color..' backpack' then
  465.             if color == 'holding' then
  466.                 table.insert(bps, 'backpack of holding '..i)
  467.             else
  468.                 table.insert(bps, color..' backpack '..i)
  469.             end
  470.         end
  471.     end
  472.     return bps
  473. end
  474.  
  475. function closebpcolor(bpcolor, indexs, indexe)  --by golfinhu
  476.     if not bpcolor then
  477.         return false
  478.     elseif not indexs then
  479.         if bpcolor:find('holding') then
  480.             return closewindows('backpack of holding')
  481.         else
  482.             return closewindows(bpcolor:token(1)..' backpack')
  483.         end
  484.     end
  485.     local indexe = indexe or indexs
  486.     local indexs, indexe = tonumber(indexs) + 1, tonumber(indexe) + 1
  487.     local index = getbpindex(bpcolor)
  488.     if table.isempty(index) or #index < indexs then return false end
  489.     for i = indexs, math.lowest(indexe,#index) do
  490.         closewindows(index[i])
  491.     end
  492. end
  493.  
  494. function arguments(function_name, function_arguments) -- Working
  495.     for i = 1, #function_arguments, 2 do
  496.         if (type(function_arguments[i + 1]) ~= function_arguments[i]) then
  497.             return false, error('bad argument #' .. math.ceil(i / 2)  .. ' to \'' .. function_name .. '\' (' .. function_arguments[i] .. ' expected, got ' .. type(function_arguments[i + 1]) .. ')', 3)
  498.         end
  499.     end
  500. end
  501.  
  502. _PRINT = _PRINT or print
  503. function print(...)
  504.     local msgs = {...}
  505.     local toprint = ''
  506.     for i,j in ipairs(msgs) do
  507.         if type(j) == 'table' then
  508.             toprint = toprint..table.stringformat(j)..' '
  509.         else
  510.             toprint = toprint..tostring(j)..' '
  511.         end
  512.     end
  513.     _PRINT(toprint:sub(1, #toprint-1))
  514. end
  515.  
  516. _PRINTERROR = _PRINTERROR or printerror
  517. function printerror(...)
  518.     local msgs = {...}
  519.     local toprint = ''
  520.     for i,j in ipairs(msgs) do
  521.         if type(j) == 'table' then
  522.             toprint = toprint..table.stringformat(j)..' '
  523.         else
  524.             toprint = toprint..tostring(j)..' '
  525.         end
  526.     end
  527.     _PRINTERROR(toprint:sub(1, #toprint-1))
  528. end
  529.  
  530. function opengrounditem(id)
  531.     if id then
  532.         id = itemid(id)
  533.     end
  534.     for i=SCREEN_LEFT, SCREEN_RIGHT do
  535.         for j=SCREEN_TOP, SCREEN_BOTTOM do
  536.             local x,y,z = posx+i, posy+j, posz
  537.             local topid = topitem(x,y,z).id
  538.             if tilereachable(x,y,z) and (not id and itemproperty(topid, ITEM_ISCONTAINER)) or topid == id then
  539.                 reachlocation(x,y,z)
  540.                 openitem(topid, ground(x,y,z)) waitcontainer() return true
  541.             end
  542.         end
  543.     end
  544.     return false
  545. end
  546.  
  547. function eatfood(location, ...)
  548.     location = location or ''
  549.     local foodtable = {3583, 3731, 3726, 3582, 3725, 3593, 3589, 12310, 3580, 3594, 3577, 3586, 3729, 3578, 8010, 3579, 3600, 3727, 3592, 3597, 3723, 3607, 5678, 3587, 3602, 3728, 3606, 3596, 3585, 3595, 3732, 3584, 3724, 3581, 3601, 3730, 3599, 3598, 3591, 3590, 3588}
  550.     if (type(location) == 'number') then
  551.         if location <= 15 then
  552.             location = tostring(location)
  553.         else
  554.             foodtable = {location, ...}
  555.             location = ''
  556.         end
  557.     elseif select("#", ...) > 0 then
  558.         foodtable = {...}
  559.     end
  560.     if location == 'ground' then
  561.         local foundfood = false
  562.         for j=-1, 1 do
  563.             for i=-1, 1 do
  564.                 local topid = topitem(posx+i, posy+j, posz).id
  565.                 local foodtime = getfoodtime(topid)
  566.                 if isfood(topid) and foodtime+gethungrytime() <= 1200000 then
  567.                     useitem(topid, ground(posx+i, posy+j, posz)) wait(100) increasehungrytime(foodtime) return true
  568.                 end
  569.             end
  570.         end
  571.     elseif location:sub(1,6) == 'ground' then
  572.         local coord = (location:sub(8)):token()
  573.         coord[1],coord[2],coord[3] = tonumber(coord[1]),tonumber(coord[2]),tonumber(coord[3])
  574.         local topid = topitem(table.unpack(coord)).id
  575.         local foodtime = getfoodtime(topid)
  576.         if isfood(topid) and foodtime+gethungrytime() <= 1200000 then
  577.             useitem(topid, ground(table.unpack(coord))) increasehungrytime(foodtime) wait(100) return true
  578.         end
  579.     else
  580.         for i,j in ipairs(foodtable) do
  581.             local foodtime = getfoodtime(j)
  582.             if itemcount(j, location) > 0 and foodtime+gethungrytime() <= 1200000 then
  583.                 useitem(j, location) increasehungrytime(foodtime) wait(100) return true
  584.             end
  585.         end
  586.     end
  587.     return false
  588. end
  589.  
  590. function firewalkerequip()
  591. if itemcount("firewalker boots") > 0 then
  592.          moveitems("firewalker boots","all","boots",1)
  593.          end
  594. end
  595.  
  596.  
  597. function cursorinfo() -- Credits to Anonymickey, for doing the calculations.
  598.     local temp = {x,y,z,id,msg}
  599.     if cursor.x >= worldwin.left and cursor.x <= worldwin.right and cursor.y <= worldwin.bottom and cursor.y >= worldwin.top then
  600.         local sqmWidth = (worldwin.bottom - worldwin.top)/11
  601.         temp.x, temp.y, temp.z =  posx - 8 + math.ceil((cursor.x - worldwin.left)/sqmWidth), posy - 6 + math.ceil((cursor.y - worldwin.top)/sqmWidth), posz
  602.         temp.id = topitem(temp.x, temp.y, temp.z).id
  603.         temp.msg = temp.x..', '..temp.y..', '..temp.z..' / '..temp.id
  604.     else
  605.         temp.x, temp.y, temp.z, temp.id, temp.msg = 0,0,0,0,'dontlist'
  606.     end
  607.     return temp
  608. end
  609.  
  610. function press(keys) -- Working
  611.     local i = 1
  612.     while i <= #keys do
  613.         local key = ''
  614.         if string.sub(keys, i, i) == '[' then
  615.             i2 = i + string.find(string.sub(keys, i), ']')
  616.             key = string.sub(keys, i+1, i2-2)
  617.             keyevent(keyid(key))
  618.             i = i2
  619.         elseif string.sub(keys, i, i) ~= ']' then
  620.             keyevent(keyid(string.sub(keys, i, i)))
  621.             i = i + 1
  622.         end
  623.     end
  624. end
  625.  
  626. function pm(message, ...) -- Working
  627.     local players = {...}
  628.     if #players > 1 then
  629.         for k, v in ipairs(players) do
  630.             pm(message, v)
  631.         end
  632.     elseif #players == 1 then
  633.         local player = players[1]
  634.         if ischannel(player) then
  635.             say(player, message)
  636.         else
  637.             for i = 1, #player-1 do
  638.                 if ischannel(string.sub(player, 1, i) .. "...") then
  639.                     say(string.sub(player, 1, i) .. "...", message)
  640.                     return
  641.                 end
  642.             end
  643.             say('*' .. player .. '* ' .. message)
  644.         end
  645.     end
  646. end
  647.  
  648. function time(secs, pattern) -- Working
  649.     local times = {dd = math.floor(secs / 86400), hh = math.floor(secs / 3600) % 24, mm = math.floor(secs / 60) % 60, ss = secs % 60}
  650.     if not pattern then
  651.         if times.dd > 0 then
  652.             pattern = 'dd:hh:mm:ss'
  653.         elseif times.hh > 0 then
  654.             pattern = 'hh:mm:ss'
  655.         else
  656.             pattern = 'mm:ss'
  657.         end
  658.     end
  659.     pattern = pattern:lower()
  660.     for k, v in pairs(times) do
  661.         pattern = string.gsub(pattern, k, math.format(v, "00"))
  662.     end
  663.     return pattern
  664. end
  665.  
  666. function keyid(key) -- Working -- Find full list at: http://api.farmanager.com/en/winapi/virtualkeycodes.html
  667.     local keys = {MOUSELEFT = 0x01, MOUSERIGHT = 0x02, MOUSEMIDDLE = 0x04, BACKSPACE = 0x08, TAB = 0x09, CLEAR = 0x0C, ENTER = 0x0D, SHIFT = 0x10, CTRL = 0x11, ALT = 0x12, PAUSE = 0x13, CAPSLOCK = 0x14, ESC = 0x1B, SPACE = 0x20, PAGEUP = 0x21, PAGEDOWN = 0x22, END = 0x25, HOME = 0x24, LEFTARROW = 0x25, UPARROW = 0x26, RIGHTARROW = 0x27, DOWNARROW = 0x28, SELECT = 0x29, PRINT = 0x2A, ExECUTE = 0x2B, PRINTSCREEN =0x2C, INSERT = 0x2D, DELETE = 0x2E, HELP = 0x2F, A = 0x41, B = 0x42, C = 0x43, D = 0x44, E = 0x45, F = 0x46, G = 0x47, H = 0x48, I = 0x49, J = 0x4A, K = 0x4B, L = 0x4C, M = 0x4D, N = 0x4E, O = 0x4F, P = 0x50, Q = 0x51, R = 0x52, S = 0x53, T = 0x54, U = 0x55, V = 0x56, W = 0x57, x = 0x58, Y = 0x59, Z = 0x5A, SLEEP = 0x5F, NUM0 = 0x60, NUM1 = 0x61, NUM2 = 0x62, NUM3 = 0x63, NUM4 = 0x64, NUM5 = 0x65, NUM6 = 0x66, NUM7 = 0x67, NUM8 = 0x68, NUM9 = 0x69, MULTIPLY = 0x6A, ADD = 0x6B, SEPARATOR = 0x6C, SUBTRACT = 0x6D, DECIMAL = 0x6E, DIVIDE = 0x6F, F1 = 0x70, F2 = 0x71, F3 = 0x72, F4 = 0x73, F5 = 0x74, F6 = 0x75, F7 = 0x76, F8 = 0x77, F9 = 0x78, F10 = 0x89, F11 = 0x7A, F12 = 0x7B, F13 = 0x7C, F14 = 0x7D, F15 = 0x7E, F16 = 0x7F, F17 = 0x80, F18 = 0x81, F19 = 0x82, F20 = 0x83, F21 = 0x84, F22 = 0x85, F23 = 0x86, F24 = 0x87, NUMLOCK = 0x90, SCROLLLOCK = 0x91, COMMA = 0xBC, HIFFEN = 0xBD, DOT = 0xBE, BAR = 0xBF, SINGLEQUOTE = 0xD3}
  668.     local numberkeys = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39}
  669.  
  670.     if tonumber(key) then
  671.         return numberkeys[key + 1]
  672.     end
  673.     return keys[string.upper(key)]
  674. end
  675.  
  676. function dropvials()
  677. if itemcount(284)+itemcount(283)+itemcount(285) > 50 then
  678.     moveitems(284,'ground')
  679.         moveitems(283,'ground')
  680.             moveitems(285,'ground')
  681.     end
  682. end
  683.  
  684. function flasks() -- By Raphael
  685.     return itemcount(283) +  itemcount(284) + itemcount(285)
  686. end
  687.    
  688. function sellflasks()
  689.    opentrade()
  690.    if tradeopen then
  691.       for i=283,285 do
  692.          local count = countitem(i)
  693.          while count > 0 do
  694.             sellitems(i,count)
  695.             wait(200,300)
  696.             count = countitem(i)
  697.          end
  698.       end
  699.    end
  700. end
  701.  
  702. function staminalow()
  703.     while stamina < 60*16 do
  704.     if battlesigned then
  705.       pausewalking(500)
  706.    else
  707.      closeclient()
  708.    end
  709.    wait(100)
  710. end
  711.  
  712. function repairsoft()
  713.   say('hi')
  714.     wait(2000, 3000)
  715.         while itemcount(6530) > 0 do
  716.             npcsay('repair')
  717.                 wait(500, 1500)
  718.             npcsay('yes')
  719.                 wait(500, 1500)
  720. end
  721.  
  722. function windowcount(item)
  723.    item = item or "all"
  724.    return wincount(item)
  725. end
  726.  
  727. function openitem(item, origem, next, index)
  728.    index = index or 0
  729.    next = next or false
  730.    return openitemindex(item, origem, next, index)
  731. end
  732.  
  733. function wait(time1, time2)
  734.    time2 = time1 or time2
  735.    sleep(time1, time2)
  736. end
  737.  
  738. function islocation(value)
  739.    value = value or 0
  740.    return isloc(value)
  741. end
  742.  
  743. function islocationxyz(x,y,z,distance)
  744.    distance= distance or 0
  745.    return _islocationxyz(x,y,z,distance)
  746. end
  747.  
  748. function moveitems(item, origem, destino, count)
  749.    if destino == nil and count == nil then
  750.       moveitemsb(item, origem, 100)
  751.       return
  752.    end
  753.    if count == nil then
  754.       moveitemsb(item, origem, destino)
  755.       return
  756.    end
  757.    moveitemsa(item, origem, destino, count)
  758. end
  759.  
  760. function buyitemsupto(itemname, amount, currentamount)
  761.    currentamount = currentamount or itemcount(itemname)
  762.    amount = amount-currentamount
  763.    while amount > 0 do
  764.       buyitems(itemname, amount)
  765.       wait(200,300)
  766.       amount = amount-100
  767.    end
  768. end
  769.  
  770. function sellitemsupto(itemname, amount, currentamount)
  771.    currentamount = currentamount or itemcount(itemname)
  772.    amount = amount-currentamount
  773.    while amount > 0 do
  774.       sellitems(itemname, amount)
  775.       wait(200,300)
  776.       amount = amount-100
  777.    end
  778. end
  779.  
  780. function entermachine(item)
  781.   local currentamount = itemcount(item)
  782.   amount = currentamount - 20
  783.   count = 0
  784.   maxtry = 50
  785.   while itemcount(item) > amount and count < maxtry do
  786.       count = count + 1
  787.       if islocationxyz(33268, 31830, 10, 5) then
  788.          if toptileitem(33268, 31830, 10) == 846 then
  789.             useitem(846, 33268, 31830, 10)
  790.             wait(400,600)
  791.          end
  792.    
  793.          useitemon(item, 33268, 31830, 10)
  794.          wait(500,600)
  795.  
  796.          if(currentamount == itemcount(item)) then
  797.            if toptileitem(33268, 31830, 10) == 842 then
  798.               useitem(842, 33268, 31830, 10)
  799.               wait(400,600)
  800.            end
  801.          else
  802.             currentamount = itemcount(item)
  803.          end
  804.       else
  805.          break
  806.       end
  807.    end
  808.    if toptileitem(33268, 31830, 10) == 842 then
  809.       useitem(842, 33268, 31830, 10)
  810.       wait(400,600)
  811.    end
  812. end
  813.  
  814. function printonadvance()
  815. local ss = {Level = true,
  816. magic = true,
  817. fist = false,
  818. axe = false,
  819. club = false,
  820. sword = false,
  821. distance = false,
  822. shielding = false,
  823. fishing = false}
  824. foreach newmessage m do
  825.     if m.type == 16 then
  826.     local c = m.content
  827.     local adv = string.match(c, 'You advanced .- (.-)[%s%.].-')
  828.     if adv then
  829.     if ss[adv] then
  830.     if $minimized then
  831.         restoreclient()
  832.             wait(400, 600)
  833.         screenshot()
  834.             wait(400, 600)
  835.         minimizeclient()
  836.         else
  837.             wait(400, 600)
  838.         screenshot()
  839.                 end
  840.             end
  841.         end
  842.     end
  843. end  
  844.  
  845. function waitandlogout()
  846.     while connected do
  847.         while battlesigned do
  848.             foreach creature m 'ms' do
  849.                 if iscreaturereachable(m) then
  850.                     setattackmode('none', 'chase')
  851.                     attack(m)
  852.                     break
  853.                 end
  854.             end
  855.             pausewalking(300)
  856.             wait(100)
  857.         end
  858.         logout()
  859.         wait(100)
  860.     end
  861. end
  862.  
  863. function randomize(ttable)
  864.     local value = 0
  865.     if type(ttable) == 'table' then
  866.         value = math.random(table.unpack(ttable))
  867.     end
  868.     return value
  869. end
  870.  
  871. function dropitems(pos,...)
  872.    local items = {...}
  873.    if type(pos) == 'number' then
  874.       table.insert(items,pos)
  875.       pos = 'ground'
  876.    end
  877.    for i,j in ipairs(items) do
  878.       while itemcount(j) > 0 do
  879.          moveitemsb(j,pos,100)
  880.       end
  881.    end
  882. end
  883.  
  884. function levitate(direction,updown)
  885.    local dir = {x = {n = 0, s = 0, w = -1, e = 1}, y = {n = -1, s = 1, w = 0, e = 0}}
  886.    if direction == 'w' or direction == 'e' or direction == 'n' or direction == 's' then
  887.       local startposz,tries,maxtries = posz,0,math.random(4,6)
  888.  
  889.       if not updown or (updown ~= 'up' and updown ~= 'down') then
  890.          local toptileid = toptileitem(posx+dir.x[direction],posy+dir.y[direction],posz)
  891.  
  892.          updown = 'up'
  893.          if toptileid == 0 or itemproperty(toptileid).isUnpassable == true then
  894.             updown = 'down'
  895.          end
  896.       end
  897.  
  898.       while mp >= 50 and level >= 12 and posz == startposz and tries < maxtries do
  899.          turn(direction)           
  900.          cast('exani hur '..updown)
  901.          wait(1000,1500)
  902.          tries=tries+1
  903.          if posz ~= startz then
  904.             return true
  905.          end
  906.       end
  907.    end
  908.    return false
  909. end
  910.  
  911. function depotdeposit(bptomove,...)
  912.    lastonto = 0
  913.    local items = {...}
  914.    local _nexti = true
  915.    for i,j in pairs(items) do
  916.       _nexti = true
  917.       while itemcount(items[i]) > 0 and _nexti do
  918.          _nexti = moveitemsonto(items[i], "all", bptomove, 100, lastonto)
  919.          wait(400,500)
  920.       end
  921.    end
  922. end
  923.  
  924. function itemcount(item, origem)
  925.    origem = origem or "all"
  926.    return _itemcount(item, origem)
  927. end
  928.  
  929. function countitem(item, origem)
  930.    origem = origem or "all"
  931.    return _itemcount(item, origem)
  932. end
  933.  
  934. function higherwindows(name)
  935.    name = name or "all"
  936.    _controlwindows(name, true)
  937. end
  938.  
  939. function minimizeequip()
  940.     minimizewindows(equip)
  941. end
  942.  
  943. function minimizewindows(name)
  944.    name = name or "all"
  945.    _controlwindows(name, false)
  946. end
  947.  
  948. function haste()
  949.    if not hasted then
  950.     cast("utani hur")
  951. end
  952. end
  953.  
  954. function antiidle()
  955.     turn("n")
  956.     turn("e")
  957.     turn("s")
  958.     turn("w")
  959. end
  960.  
  961. function manashield()
  962.    if not manashielded then
  963.     cast("utamo vita")
  964. end
  965. end
  966.  
  967. function charge()
  968.    if not hasted then
  969.     cast("utani tempo hur")
  970. end
  971. end
  972.  
  973. function stronghaste()
  974.    if not hasted then
  975.     cast("utani gran hur")
  976. end
  977. end
  978.  
  979. function maround(range,allfloors,...)
  980.    local names = {...}
  981.    range = range or 7
  982.    allfloors = allfloors or false
  983.  
  984.    if type(range) == 'string' then
  985.       table.insert(names,range)
  986.       range = 7
  987.    end
  988.    if type(allfloors) == 'string' then
  989.       table.insert(names,allfloors)
  990.       allfloors = false
  991.    end
  992.  
  993.    local name = ''
  994.    for i,j in pairs(names) do
  995.       name = name..names[i]..';'
  996.    end
  997.  
  998.    return _maround(range,allfloors,name)
  999. end
  1000.  
  1001. function paround(range,allfloors,...)
  1002.    local names = {...}
  1003.    range = range or 7
  1004.    allfloors = allfloors or false
  1005.  
  1006.    if type(range) == 'string' then
  1007.       table.insert(names,range)
  1008.       range = 7
  1009.    end
  1010.    if type(allfloors) == 'string' then
  1011.       table.insert(names,allfloors)
  1012.       allfloors = false
  1013.    end
  1014.  
  1015.    local name = ''
  1016.    for i,j in pairs(names) do
  1017.       name = name..names[i]..';'
  1018.    end
  1019.  
  1020.    return _paround(range,allfloors,name)
  1021. end
  1022.  
  1023. function pickupitems(dir,...)
  1024.    local items = {...}
  1025.    local dire = {dirs = {'c', 'n', 's', 'w', 'e', 'nw', 'ne', 'sw', 'se'},
  1026.          x = {c = 0, n = 0, s = 0, w = -1, e = 1, nw = -1, ne = 1, sw = -1, se = 1},
  1027.          y = {c = 0, n = -1, s = 1, w = 0, e = 0, nw = -1, ne = -1, sw = 1, se = 1}}
  1028.  
  1029.    if not dir or not table.find(dire.dirs,dir) then
  1030.       if dir ~= nil then
  1031.          table.insert(items,dir)
  1032.       end
  1033.       dir = 'c'
  1034.    end
  1035.    
  1036.    local pos = {x = posx+dire.x[dir], y = posy+dire.y[dir], z = posz}  
  1037.    local topid = toptileitem(pos.x,pos.y,pos.z)
  1038.    local id = topid
  1039.    local item = itemproperty(topid)
  1040.    
  1041.    if #items == 0 then
  1042.       if topid ~= 0 and item.isTakeable then
  1043.          moveitems(topid,ground(pos.x,pos.y,pos.z),'all',100)
  1044.       end
  1045.    else
  1046.       for i,j in pairs(items) do
  1047.          if type(j) == 'number' then
  1048.             id = j
  1049.          else
  1050.             id = itemid(j)
  1051.          end
  1052.  
  1053.          if topid == id and item.isTakeable then
  1054.             moveitems(topid,ground(pos.x,pos.y,pos.z),'all',100)
  1055.             break
  1056.          end
  1057.       end
  1058.    end
  1059. end
  1060.  
  1061. function gotolabel(label)
  1062.    if type(label) == 'number' then
  1063.       _gotolabeln(label)
  1064.    else
  1065.       _gotolabels(label)
  1066.    end
  1067. end
  1068.  
  1069. function useitem(item, x, y, z)
  1070.    x = x or 'all'
  1071.    if type(x) == 'number' then
  1072.       _useitemxyz(item, x, y, z)
  1073.    else
  1074.       _useitem(item, x)
  1075.    end
  1076. end
  1077.  
  1078. function useitemon(item, x, y, z)
  1079.    if z == nil then
  1080.       y = y or 'all'
  1081.       useitemonitem(item, x, y)
  1082.    else
  1083.       _useitemon(item, x, y, z)
  1084.    end
  1085. end
  1086.  
  1087. function say(text, channel)
  1088.    if channel == nil then
  1089.       _say(text)
  1090.    else
  1091.       anysay(text, channel)
  1092.    end
  1093. end
  1094.  
  1095. function underattack(type)
  1096.    type = type or 'all'
  1097.    return _underattack(type)
  1098. end
  1099.  
  1100. function gold()
  1101.    return itemcount(3031) + (itemcount(3035) * 100) + (itemcount(3043) * 10000)
  1102. end
  1103.  
  1104. function waitping(base)
  1105.     local base = base or 200
  1106.     if ping == 0 then ping = base end
  1107.     wait(2 * ping, 4 * ping)
  1108. end
  1109.  
  1110. _LISTAS = _LISTAS or listas
  1111. function listas(...)
  1112.     local msgs = {...}
  1113.     local toprint = ''
  1114.     for i,j in ipairs(msgs) do
  1115.         if type(j) == 'table' then
  1116.             toprint = toprint..table.stringformat(j)..' '
  1117.         else
  1118.             toprint = toprint..tostring(j)..' '
  1119.         end
  1120.     end
  1121.     _LISTAS(toprint:sub(1, #toprint-1))
  1122. end
  1123.  
  1124. function dontlist()
  1125.     listas('dontlist')
  1126. end
  1127.  
  1128. function withdraw(amount, npc, sayhi)
  1129.     if not amount or amount == 0 then
  1130.         return true
  1131.     end
  1132.  
  1133.     if say('hi') == true then
  1134.         npcsay('hi', 'withdraw ' .. amount, 'yes')
  1135.     else
  1136.         npcsay('withdraw ' .. amount, 'yes')
  1137.     end
  1138.  
  1139.     waitping()
  1140.     foreach newmessage m do
  1141.         if m.content == 'There is not enough gold on your account.' then
  1142.             if (not npc) or (npc == '') or (m.sender == npc) then
  1143.                 return false
  1144.             end
  1145.         end
  1146.     end
  1147.  
  1148.     return true
  1149. end
  1150.  
  1151. function antifurnituretrap(weapontouse)
  1152.    weapontouse = weapontouse or 3308 -- machete
  1153.    local blockwalkids = {2025, 2029, 2030, 2043, 2044, 2045, 2046, 2047, 2048, 2059, 2060, 2061, 2445, 2446, 2447, 2448, 2449, 2450, 2451, 2452, 2453, 2454, 2465, 2466, 2467, 2468, 2524, 2904, 2959, 2960, 2961, 2962, 2963, 2964, 2975, 2976, 2979, 2982, 2986, 2997, 2998, 2999, 3000, 3484, 3485, 3486, 3487, 3510, 3511, 3512, 3513, 5046, 5055, 5056, 6109, 6110, 6111, 6112, 6367, 6368, 6369, 6370, 7860, 7861, 7862, 7863, 9132, 9141, 10208, 10210, 10211, 10212, 10213, 10214, 10215}
  1154.  
  1155.    for i=-7,7 do
  1156.       for j=-5,5 do
  1157.          local x,y,z = posx+i,posy+j,posz
  1158.          if table.binaryfind(blockwalkids,toptileitem(x,y,z)) then
  1159.             if tilereachable(x,y,z) then
  1160.                pausewalking(10000)
  1161.                local topid = toptileitem(x,y,z)
  1162.                while tilereachable(x,y,z) and (math.abs(posx-x) > 1 or math.abs(posy-y) > 1) do
  1163.                   reachlocation(x,y,z)
  1164.                   wait(100,200)
  1165.                   updateworld()
  1166.                end        
  1167.                while toptileitem(x,y,z) == topid and posz == z and (math.abs(posx-x) <= 1 and math.abs(posy-y) <= 1) do
  1168.                   useitemon(weapontouse,toptileitem(x,y,z),ground(x,y,z))
  1169.                   pausewalking(5000)
  1170.                   wait(400,500)
  1171.                   updateworld()
  1172.                end
  1173.                pausewalking(0)
  1174.             end
  1175.          end
  1176.       end
  1177.    end
  1178. end
  1179.  
  1180. function getcreatures(filter)
  1181.    filter = filter or 'pmfs'
  1182.    return _getcreatures(filter)
  1183. end
  1184.  
  1185. function openhole(x,y,z,holes)
  1186.     x,y,z = x or wptx, y or wpty, z or wptz
  1187.     holes = holes or {{593,594}, {606, 607}, {608, 609}, {867, 868}}
  1188.     reachlocation(x,y,z)
  1189.     if x and y and z and math.abs(posx-x) <= 7 and math.abs(posy-y) <= 5 and posz == z then
  1190.         local v = 1
  1191.         while v <= #holes and not isitemontile(holes[v][1],x,y,z) do
  1192.             v = v+1
  1193.         end
  1194.         if v <= #holes then
  1195.             local id = toptileitem(x,y,z)
  1196.             while id ~= holes[v][2] do
  1197.                 if id == holes[v][1] then
  1198.                     if iscreatureontile(x,y,z) then
  1199.                         local dir = wheretomove(x,y,z)
  1200.                         moveitems(99,ground(x,y,z),ground(dir.x,dir.y,z),100)
  1201.                                                 wait(1400,1600)
  1202.                     else
  1203.                         useitemon(shovel,x,y,z)
  1204.                                             wait(900,1100)
  1205.                     end
  1206.                 else
  1207.                                         local dir = wheretomove(x,y,z)
  1208.                     moveitems(id,ground(x,y,z),ground(dir.x,dir.y,z),100)
  1209.                     wait(500,700)
  1210.                 end
  1211.                 id = topitem(x,y,z)
  1212.             end
  1213.             return true
  1214.         end
  1215.     end
  1216.     return false
  1217. end
  1218.  
  1219. function opensand(x,y,z)
  1220.    return openhole(x,y,z, {{231,615}})
  1221. end
  1222.  
  1223. function uselever(x,y,z,id)
  1224.     x,y,z = x or wptx, y or wpty, z or wptz
  1225.     local levers = {2771, 2772}
  1226.     if id then
  1227.         levers = {id}
  1228.     end
  1229.     reachlocation(x,y,z)
  1230.     if x and y and z and math.abs(posx-x) <= 7 and math.abs(posy-y) <= 5 and posz == z then
  1231.         local v = 1
  1232.         while v <= #levers and not isitemontile(levers[v],x,y,z) do
  1233.             v = v+1
  1234.         end
  1235.         if v <= #levers then
  1236.             local id = toptileitem(x,y,z)
  1237.             while isitemontile(levers[v],x,y,z) do
  1238.                 if id == levers[v] then
  1239.                     if iscreatureontile(x,y,z) then
  1240.                         local dir = wheretomove(x,y,z)
  1241.                         moveitems(99,ground(x,y,z),ground(dir.x,dir.y,z),100)
  1242.                                                 wait(1400,1600)
  1243.                     else
  1244.                         useitem(levers[v],ground(x,y,z))
  1245.                                             wait(500,700)
  1246.                     end
  1247.                 else
  1248.                     local dir = wheretomove(x,y,z)
  1249.                     moveitems(id,ground(x,y,z),ground(dir.x,dir.y,z),100)
  1250.                     wait(500,700)
  1251.                 end
  1252.                 id = toptileitem(x,y,z)
  1253.             end
  1254.             return true
  1255.         end
  1256.     end
  1257.     return false
  1258. end
  1259.  
  1260. function getitems(...)
  1261.    local items = {...}
  1262.  
  1263.    local item = ''
  1264.    for i,j in pairs(items) do
  1265.       item = item..items[i]..';'
  1266.    end
  1267.  
  1268.    return _getitems(item)
  1269. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement