Advertisement
Guest User

Untitled

a guest
Jun 17th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.14 KB | None | 0 0
  1. --[[
  2.  
  3. Leonardo's Library
  4. Created: 15/01/2014
  5. Version: 1.5.2
  6. Updated: 25/02/2015
  7.  
  8. Last Changelog:
  9.  
  10. Added string:parselootmessage, string:parsehealmessage, string:parseattackmessage
  11. Fixed unrust counting twice the amount of rust removers used
  12. Must add areca palm to antifurniture exceptions list
  13. Must fix randomcolor
  14. --]]
  15.  
  16.  
  17. -- GLOBALS AND LOCAL VARIABLES
  18.  
  19. LIBS = LIBS or {}
  20. LIBS.LEONARDO = "1.5.1"
  21.  
  22. POLICY_NONE = 'None'
  23. POLICY_CAVEBOT = 'Cavebot'
  24. POLICY_TARGETING = 'Targeting'
  25. POLICY_ALL = 'Cavebot & Targeting'
  26.  
  27. AREA_SQUARE_FILLED = 'Square (Filled)'
  28. AREA_SQUARE_BORDER = 'Square (Border Only)'
  29. AREA_SQUARE_DOUBLE_BORDER = 'Square (Double Border)'
  30.  
  31. local SA_POLICY = {POLICY_CAVEBOT, POLICY_TARGETING, POLICY_ALL}
  32. local SA_TYPE = {AREA_SQUARE_FILLED, AREA_SQUARE_BORDER, AREA_SQUARE_DOUBLE_BORDER}
  33.  
  34. local slotNames = {
  35. ["amulet"] = function() return {name = 'neck', obj = $neck} end,
  36. ["neck"] = function() return {name = 'neck', obj = $neck} end,
  37. ["weapon"] = function() return {name = 'rhand', obj = $rhand} end,
  38. ["rhand"] = function() return {name = 'rhand', obj = $rhand} end,
  39. ["shield"] = function() return {name = 'lhand', obj = $lhand} end,
  40. ["lhand"] = function() return {name = 'lhand', obj = $lhand} end,
  41. ["ring"] = function() return {name = 'finger', obj = $finger} end,
  42. ["finger"] = function() return {name = 'finger', obj = $finger} end,
  43. ["armor"] = function() return {name = 'chest', obj = $chest} end,
  44. ["chest"] = function() return {name = 'chest', obj = $chest} end,
  45. ["boots"] = function() return {name = 'feet', obj = $feet} end,
  46. ["feet"] = function() return {name = 'feet', obj = $feet} end,
  47. ["ammo"] = function() return {name = 'belt', obj = $belt} end,
  48. ["belt"] = function() return {name = 'belt', obj = $belt} end,
  49. ["helmet"] = function() return {name = 'head', obj = $head} end,
  50. ["head"] = function() return {name = 'head', obj = $head} end,
  51. ["legs"] = function() return {name = 'legs', obj = $legs} end,
  52. }
  53.  
  54. local cityTemples = {
  55. -- thanks @Donatello for finding the positions:
  56. --{fx, lx, fy, ly, z}
  57. {32953, 32966, 32072, 32081, 7}, -- venore
  58. {32358, 32380, 32231, 32248, 7}, -- thais
  59. {32357, 32363, 31776, 31787, 7}, -- carlin
  60. {32718, 32739, 31628, 31640, 7}, -- abdendriel
  61. {33509, 33517, 32360, 32366, 7}, -- roshaamul
  62. {33208, 33225, 31804, 31819, 8}, -- edron
  63. {33018, 33033, 31511, 31531, 11}, -- farmine
  64. {33018, 33033, 31511, 31531, 13}, -- farmine
  65. {33018, 33033, 31511, 31531, 15}, -- farmine
  66. {33210, 33218, 32450, 32457, 1}, -- darashia
  67. {32642, 32662, 31920, 31929, 11}, -- kazordoon
  68. {32093, 32101, 32216, 32222, 7}, -- rookgaard
  69. {33442, 33454, 31312, 31326, 9}, -- gray island
  70. {32208, 32217, 31128, 31138, 7}, -- svargrond
  71. {33188, 33201, 32844, 32857, 8}, -- ankrahmun
  72. {32590, 32599, 32740, 32749, 6}, -- port hope
  73. {32313, 32321, 32818, 32830, 7}, -- liberty bay
  74. {32785, 32789, 31274, 31279, 7}, -- yalahar
  75. {33586, 33602, 31896, 31903, 6}, -- oramond
  76. }
  77.  
  78. local defaultColors = {
  79. ['red'] = {0, 16},
  80. ['yellow'] = {47, 55},
  81. ['blue'] = {180, 225},
  82. ['green'] = {63, 179},
  83. ['purple'] = {240, 280},
  84. ['orange'] = {16, 43},
  85. ['pink'] = {300, 336},
  86. ['cyan'] = {168, 187},
  87. ['monochrome'] = 1,
  88. }
  89.  
  90. local lootParse_itemsExceptions = {
  91. [itemid('mana potion')] = 50,
  92. [itemid('health potion')] = 45,
  93. [itemid('strong mana potion'] = 80,
  94. [itemid('strong health potion')] = 100,
  95. [itemid('great mana potion')] = 120,
  96. [itemid('great health potion')] = 190,
  97. [itemid('great spirit potion')] = 190,
  98. [itemid('ultimate health potion')] = 310,
  99. }
  100.  
  101. local antiFurniture_itemsExceptions = {
  102.  
  103. }
  104.  
  105. -- LOCAL FUNCTIONS
  106.  
  107. LIB_CACHE = LIB_CACHE or {
  108. antifurniture = {},
  109. specialarea = {},
  110. cancast = {},
  111. isontemple = false,
  112. screentiles = math.random(10^2, 10^4)
  113. }
  114.  
  115. ORDER_RADIAL = function(a, b) return getdistancebetween(a, {$posx, $posy, $posz}) < getdistancebetween(b, {$posx, $posy, $posz}) end
  116. ORDER_RADIAL_REVERSE = function(a, b) return ORDER_RADIAL(b, a) end
  117. ORDER_EUCLIDEAN = function(a, b) return math.sqrt(math.abs(a[1] - $posx)^2 + math.abs(a[2] - $posy)^2) > math.sqrt(math.abs(b[1] - $posx)^2 + math.abs(b[2] - $posy)^2) end
  118. ORDER_EUCLIDEAN_REVERSE = function(a, b) return ORDER_EUCLIDEAN(b, a) end
  119. ORDER_REALDIST = function(a, b) return math.abs((a[1] - $posx) + (a[2] - $posy)) > math.abs((b[1] - $posx) + (b[2] - $posy)) end
  120. ORDER_REALDIST_REVERSE = function(a, b) return ORDER_REALDIST(b, a) end
  121. ORDER_RANDOM = function(a, b) return (a[1] * a[2] * a[3]) % LIB_CACHE.screentiles < (b[1] * b[2] * b[3]) % LIB_CACHE.screentiles end
  122.  
  123. local __FUNCTIONS = __FUNCTIONS or {
  124. CAST = cast,
  125. }
  126.  
  127. local function __crearoundf__callback(range, floor, list, cretype, ignore, f)
  128. local Creatures = {}
  129.  
  130. foreach creature cre cretype do
  131. if f(cre) and cre.dist <= range and (cre.posz == $posz or floor) and ((not ignore and (#list == 0 or table.find(list, cre.name:lower()))) or (ignore and not table.find(list, cre.name:lower()))) then
  132. table.insert(Creatures, cre)
  133. end
  134. end
  135.  
  136. return #Creatures
  137. end
  138.  
  139. local function getareasetting(name, setting)
  140. name = name:lower()
  141. if LIB_CACHE.specialarea[name] then
  142. return getsetting(LIB_CACHE.specialarea[name].path, setting)
  143. else
  144. foreach settingsentry e 'Cavebot/SpecialAreas' do
  145. local n = getsetting(e, 'Name')
  146. LIB_CACHE.specialarea[n:lower()] = {path = e, name = n}
  147.  
  148. if n:lower() == name then
  149. return getsetting(e, setting)
  150. end
  151. end
  152. end
  153. return nil
  154. end
  155.  
  156. local function setareasetting(name, setting, v)
  157. name = name:lower()
  158. if LIB_CACHE.specialarea[name] then
  159. return setsetting(LIB_CACHE.specialarea[name].path, setting, v)
  160. else
  161. foreach settingsentry e 'Cavebot/SpecialAreas' do
  162. local n = getsetting(e, 'Name')
  163. LIB_CACHE.specialarea[n:lower()] = {path = e, name = n}
  164.  
  165. if n:lower() == name then
  166. return setsetting(e, setting, v)
  167. end
  168. end
  169. end
  170. end
  171.  
  172. -- EXTENSION CLASS
  173.  
  174. function botversion(n)
  175. n = n or $botversion
  176.  
  177. return (tonumber(n:sub(1,1)) * 100) + (tonumber(n:sub(3,3)) * 10) + tonumber(n:sub(5,5))
  178. end
  179. BOT_VERSION = botversion()
  180.  
  181. function printf(str, ...)
  182. return print(sprintf(str, ...))
  183. end
  184.  
  185. function sprintf(str, ...)
  186. return #{...} > 0 and tostring(str):format(...) or tostring(str)
  187. end
  188.  
  189. function loadstringf(str, ...)
  190. return loadstring(sprintf(str, ...))
  191. end
  192.  
  193. function printerrorf(str, ...)
  194. return printerror(sprintf(str, ...))
  195. end
  196.  
  197. function table.search(self, value, argument, ...)
  198. local typeVal = type(value)
  199. local typeArg = type(argument)
  200. local val1, val2
  201. local args = {...}
  202.  
  203. if typeVal == 'string' then
  204. if typeArg == 'boolean' then
  205. table.insert(args, 1, argument)
  206. argument = nil
  207. end
  208.  
  209. -- string options
  210. -- disconsider case, partial match
  211. val1, val2 = unpack(args)
  212. elseif typeVal == 'number' then
  213. if typeArg == 'number' and #args == 1 then
  214. table.insert(args, 1, argument)
  215. argument = nil
  216. end
  217.  
  218. -- number options
  219. -- between min, between max
  220. val1, val2 = unpack(args)
  221. elseif typeVal == 'boolean' then
  222. if typeArg == 'boolean' then
  223. table.insert(args, 1, argument)
  224. argument = nil
  225. end
  226.  
  227. -- bool options
  228. -- convert values to bool, must have Raphael's lib
  229. val1 = args[1]
  230. end
  231.  
  232. for k, v in pairs(self) do
  233. if typeVal == 'string' and type(k[argument] or v) == 'string' then
  234. local str1, str2, str3 = v:lower(), value:lower(), (argument ~= nil and k[argument] or ''):lower()
  235.  
  236. if v == value or argument and k[argument] == value or (val1 and (str1 == str2 or (argument and str1 == str3))) or (val2 and (str1:find(str2) or str2:find(str1) or (argument and (str1:find(str3) or str3:find(str1))))) then
  237. return k
  238. end
  239. elseif typeVal == 'number' and type(k[argument] or v) == 'number' then
  240. if v == value or argument and k[argument] == value or (val1 and val2 and (v < val2 and v > val1 or argument and k[argument] < val2 and k[argument] > val1)) then
  241. return k
  242. end
  243. elseif typeVal == 'boolean' and type(k[argument] or v) == 'boolean' then
  244. if v == value or argument and k[argument] == value or (val1 and tobool(argument and k[argument] or v)) then
  245. return k
  246. end
  247. end
  248. end
  249.  
  250. return nil
  251. end
  252.  
  253. function table.tostring(self, name, sep)
  254. if name and not sep then
  255. sep = name
  256. name = nil
  257. elseif not (name or sep) then
  258. sep = ' '
  259. end
  260.  
  261. local str = ''
  262.  
  263. for k, v in pairs(self) do
  264. local t, n = type(v), type(k)
  265.  
  266. k = ((n ~= 'number' and tonumber(k) ~= nil) or tostring(k):match("[%s\'+]") ~= nil) and sprintf('[%q]', k) or k
  267.  
  268. if t == 'string' then
  269. str = str .. sprintf("%s,%s", (n == 'number' and sprintf('%q', v)) or sprintf('%s = %q', k, v), sep)
  270. elseif t == 'number' or t == 'boolean' then
  271. str = str .. sprintf("%s,%s", (n == 'number' and tostring(v)) or sprintf('%s = %s', k, tostring(v)), sep)
  272. elseif t == 'table' then
  273. str = str .. sprintf("%s,%s", (n == 'number' and table.tostring(v)) or sprintf('%s = %s', k, table.tostring(v)), sep)
  274. elseif t == 'userdata' and userdatastringformat then
  275. str = str .. sprintf("%s, %s", (n == 'number' and userdatastringformat(v)) or sprintf('%s = %s', k, userdatastringformat(v)), sep)
  276. end
  277. end
  278.  
  279. return sprintf("%s{%s}", name and sprintf('%s = ', name) or '', str:sub(1, -(2 + #sep)))
  280. end
  281.  
  282. function string:parselootmessage()
  283. local lootInfo = {name = '', items = {}, value = 0}
  284. local monsterName, lootContent = self:match(REGEX_LOOT)
  285.  
  286. if monsterName and monsterName ~= '' then
  287. lootInfo.name = monsterName:lower():gsub("^the ", "")
  288.  
  289. if not lootContent:match('^nothing') then
  290. lootContent = lootContent:token(nil, ', ')
  291. local lootItems = {}
  292.  
  293. setitemwarnings(false)
  294.  
  295. for _, lootItem in ipairs(lootContent) do
  296. local itemAmount, itemName = tonumber(lootItem:token(1, " ")) or 1, lootItem:gsub("%d+ ", ""):gsub("^an? ", "")
  297. local itemInfo = iteminfo(itemName)
  298.  
  299. if itemInfo.name ~= '' then
  300. local itemValue = lootParse_itemsExceptions[itemInfo.id] or itemInfo.sellprice
  301. lootInfo.value = lootInfo.value + (itemAmount * itemValue)
  302. local pos = table.find(lootInfo.items, itemInfo.id, 'id')
  303.  
  304. if pos then
  305. lootInfo.items[pos].amount = lootInfo.items[pos].amount + itemAmount
  306. else
  307. table.insert(lootInfo.items, {id = itemInfo.id, name = itemInfo.name, amount = itemAmount, value = itemValue})
  308. end
  309. end
  310. end
  311.  
  312. setitemwarnings(true)
  313. end
  314. end
  315.  
  316. return lootInfo
  317. end
  318.  
  319. function string:parsehealmessage()
  320. local healInfo = {amount = 0, healer = '', target = ''}
  321.  
  322. healInfo.amount = self:match('You healed yourself for (%w+) hitpoint[s]*%.')
  323. if healInfo.amount then
  324. healInfo.amount, healInfo.healer, healInfo.target = tonumber(healInfo.amount), $name, $name
  325.  
  326. return healInfo
  327. else
  328. healInfo.healer, healInfo.amount = self:match('(.+) healed h[erim]+self for (%w+) hitpoint[s]*%.')
  329. if healInfo.amount then
  330. healInfo.amount, healInfo.target = tonumber(healInfo.amount), healInfo.healer
  331.  
  332. return healInfo
  333. else
  334. healInfo.target, healInfo.amount = self:match('You heal (.+) for (%w+) hitpoint[s]*%.')
  335. if healInfo.amount then
  336. healInfo.amount, healInfo.healer = tonumber(healInfo.amount), healInfo
  337.  
  338. return healInfo
  339. else
  340. healInfo.healer, healInfo.amount= self:match('You were healed by (.+) for (%w+) hitpoint[s]*%.')
  341. if healInfo.amount then
  342. healInfo.amount, healInfo.target = tonumber(healInfo.amount), $name
  343.  
  344. return healInfo
  345. else
  346. healInfo.target, healInfo.healer, healInfo.amount = self:match('(.+) was healed by (.+) for (%w+) hitpoint[s]*%.')
  347. if healInfo.amount then
  348. healInfo.amount = tonumber(healInfo.amount)
  349.  
  350. return healInfo
  351. end
  352. end
  353. end
  354. end
  355. end
  356.  
  357. return {amount = 0, healer = '', target = ''}
  358. end
  359.  
  360. function string:parseattackmessage()
  361. local atkInfo = {amount = 0, dealer = {name = '', type = ''}, target = {name = '', type = ''}}
  362.  
  363. atkInfo.amount, atkInfo.dealer.name = self:match('You lose (%w+) .+ due to an attack by (.+)%.')
  364. if (atkInfo.amount) then
  365. atkInfo.amount = tonumber(atkInfo.amount)
  366. atkInfo.dealer = {name = atkInfo.dealer.name:gsub('^a ', '', 1):gsub('^an ', '', 1):gsub('^the ', '', 1), type = (atkInfo.dealer.name:match('^a ') or atkInfo.dealer.name:match('^an ') or atkInfo.dealer.name:match('^the ')) and 'monster' or 'player'}
  367. atkInfo.target = {name = Self.Name(), type = 'player'}
  368.  
  369. return atkInfo
  370. else
  371. atkInfo.target.name, atkInfo.amount = self:match('(.+) loses (%w+) .+ due to your attack%.')
  372. if (atkInfo.amount) then
  373. atkInfo.amount = tonumber(atkInfo.amount)
  374. atkInfo.dealer = {name = Self.Name(), type = 'player'}
  375. atkInfo.target = {name = atkInfo.target.name:gsub('^A ', '', 1):gsub('^An ', '', 1):gsub('^The ', '', 1), type = (atkInfo.target.name:match('^A ') or atkInfo.target.name:match('^An ') or atkInfo.target.name:match('^The ')) and 'monster' or 'player'}
  376.  
  377. return atkInfo
  378. else
  379. atkInfo.target.name, atkInfo.amount, atkInfo.dealer.name = self:match('(.+) loses (%w+) .+ due to an attack by (.+)%.')
  380. if (atkInfo.amount) then
  381. atkInfo.amount = tonumber(atkInfo.amount)
  382. atkInfo.dealer = {name = atkInfo.dealer.name:gsub('^a ', '', 1):gsub('^an ', '', 1):gsub('^the ', '', 1), type = (atkInfo.dealer.name:match('^a ') or atkInfo.dealer.name:match('^an ') or atkInfo.dealer.name:match('^the ')) and 'monster' or 'player'}
  383. atkInfo.target = {name = atkInfo.target.name:gsub('^A ', '', 1):gsub('^An ', '', 1):gsub('^The ', '', 1), type = (atkInfo.target.name:match('^A ') or atkInfo.target.name:match('^An ') or atkInfo.target.name:match('^The ')) and 'monster' or 'player'}
  384.  
  385. return atkInfo
  386. end
  387. end
  388. end
  389.  
  390. return {amount = 0, dealer = {name = '', type = ''}, target = {name = '', type = ''}}
  391. end
  392.  
  393. function tosec(str)
  394. local sum, time, units, index = 0, str:token(nil, ":"), {86400, 3600, 60, 1}, 1
  395.  
  396. for i = #units - #time + 1, #units do
  397. sum, index = sum + ((tonumber(time[index]) or 0) * units[i]), index + 1
  398. end
  399.  
  400. return math.max(sum, 0)
  401. end
  402.  
  403. function formatnumber(n, s)
  404. local result, sign, before, after, s = '', string.match(tostring(n), '^([%+%-]?)(%d*)(%.?.*)$'), s or ','
  405.  
  406. while #before > 3 do
  407. result = s .. string.sub(before, -3, -1) .. result
  408. before = string.sub(before, 1, -4)
  409. end
  410.  
  411. return sign .. before .. result .. after
  412. end
  413.  
  414. function formattime(n, pattern)
  415. local units = {DD = math.floor(n / 86400 % 7), HH = math.floor(n / 3600 % 24), MM = math.floor(n / 60 % 60), SS = math.floor(n % 60)}
  416.  
  417. if not pattern then
  418. if units.DD > 0 then
  419. pattern = "DD:HH:MM:SS"
  420. elseif units.HH > 0 then
  421. pattern = "HH:MM:SS"
  422. else
  423. pattern = "MM:SS"
  424. end
  425. else
  426. pattern = pattern:upper()
  427. end
  428.  
  429. return pattern:gsub("%u%u", function(str) return string.format("%02d", units[str]) end)
  430. end
  431.  
  432. function getareaposition(name)
  433. local setting = getareasetting(name, 'Coordinates')
  434.  
  435. if setting then
  436. local x, y, z = setting:match(".-(%d+).-(%d+).-(%d+)")
  437.  
  438. return {x = tonumber(x) or 0, y = tonumber(y) or 0, z = tonumber(z) or 0}
  439. end
  440.  
  441. return {x = 0, y = 0, z = 0}
  442. end
  443.  
  444. function setareaposition(name, x, y, z)
  445. x, y, z = tonumber(x) or $posx, tonumber(y) or $posy, tonumber(z) or $posz
  446.  
  447. return setareasetting(name, 'Coordinates', sprintf("x:%s, y:%s, z:%s", x, y, z))
  448. end
  449.  
  450. function getareasize(name)
  451. local setting = getareasetting(name, 'Size')
  452.  
  453. if setting then
  454. local w, h = setting:match('(%d+) to (%d+)')
  455.  
  456. return {w = tonumber(w) or 0, h = tonumber(h) or 0}
  457. end
  458.  
  459. return {w = 0, h = o}
  460. end
  461.  
  462. function setareasize(name, w, h)
  463. h, w = tonumber(h) or 1, tonumber(w) or 1
  464.  
  465. return setareasetting(name, 'Size', sprintf('%d to %d', w, h))
  466. end
  467.  
  468. function getareapolicy(name)
  469. local setting = getareasetting(name, 'Policy')
  470.  
  471. return setting or POLICY_NONE
  472. end
  473.  
  474. function setareapolicy(name, policy)
  475. local polType = type(policy)
  476.  
  477. if polType == 'string' and not table.find({"cavebot", "cavebot & targeting", "targeting", "none"}, policy:lower()) then
  478. policy = "None"
  479. elseif polType == 'number' and policy > 0 and policy <= 3 then
  480. policy = SA_POLICY[policy]
  481. else
  482. policy = "None"
  483. end
  484.  
  485. return setareasetting(name, 'Policy', policy)
  486. end
  487.  
  488. function getareaavoidance(name)
  489. local setting = getareasetting(name, 'Avoidance')
  490.  
  491. return tonumber(setting) or 0
  492. end
  493.  
  494. function setareaavoidance(name, avoid)
  495. avoid = tonumber(avoid) or 0
  496.  
  497. return setareasetting(name, 'Avoidance', avoid)
  498. end
  499.  
  500. function getareaextrapolicy(name, poltype)
  501. local t = type(poltype)
  502. poltype = t == 'string' and poltype:lower() or false
  503.  
  504. if poltype then
  505. if poltype:match('loot') then
  506. poltype = 'IgnoreWhenLooting'
  507. elseif poltype:match('luring') or poltype:match('lure') then
  508. poltype = 'IgnoreWhenLuring'
  509. else
  510. return printerrorf("bad argument #2 to 'getareaextrapolicy', ('Lure', 'Loot', 'Luring' or 'Looting' expected, got '%s')", poltype)
  511. end
  512. else
  513. return printerrorf("bad argument #2 to 'getareaextrapolicy', (string expected, got '%s')", t)
  514. end
  515.  
  516. local setting = getareasetting(name, poltype)
  517.  
  518. return setting ~= nil and setting == 'yes'
  519. end
  520.  
  521. function setareaextrapolicy(name, poltype, t)
  522. local typ = type(poltype)
  523. poltype = typ == 'string' and poltype:lower() or false
  524.  
  525. if poltype then
  526. if poltype:match('loot') then
  527. poltype = 'IgnoreWhenLooting'
  528. elseif poltype:match('luring') or poltype:match('lure') then
  529. poltype = 'IgnoreWhenLuring'
  530. else
  531. return printerrorf("bad argument #2 to 'getareaextrapolicy', ('Lure', 'Loot', 'Luring' or 'Looting' expected, got '%s')", poltype)
  532. end
  533. else
  534. return printerrorf("bad argument #2 to 'getareaextrapolicy', (string expected, got '%s')", typ)
  535. end
  536.  
  537. return setareasetting(name, poltype, t)
  538. end
  539.  
  540. function getareatype(name)
  541. return getareasetting(name, 'Type') or 'None'
  542. end
  543.  
  544. function setareatype(name, areatype)
  545. local t = type(areatype)
  546.  
  547. if t == 'string' then
  548. areatype = areatype:lower()
  549.  
  550. if areatype:match('filled') then
  551. areatype = AREA_SQUARE_FILLED
  552. elseif areatype:match('border') then
  553. areatype = AREA_SQUARE_BORDER
  554. elseif areatype:match('double') then
  555. areatype = AREA_SQUARE_DOUBLE_BORDER
  556. else
  557. return printerrorf("bad argument #2 to 'setareatype' ('Filled', 'Border', 'Double', 'Square (Filled)', 'Square (Border Only)' or 'Square (Double Border)' expected, got %s)", areatype)
  558. end
  559. elseif t == 'number' and areatype >= 1 or areatype <= 3 then
  560. areatype = SA_TYPE[areatype]
  561. else
  562. return printerrorf("bad argument #2 to 'setareatype' (string or number (1-3) expected, got %s%s)", t, not table.find({1,2,3}, areatype) and " different than the value expected" or '')
  563. end
  564.  
  565. return setareasetting(name, 'Type', areatype)
  566. end
  567.  
  568. function getareacomment(name)
  569. return getareasetting(name, 'Comment') or ''
  570. end
  571.  
  572. function setareacomment(name, comment)
  573. return setareasetting(name, 'Comment', comment or '')
  574. end
  575.  
  576. function isbinded(...)
  577. if not $fasthotkeys then
  578. local temp, i, arg, info = {}, 1, {...}
  579.  
  580. while arg[i] do
  581. if type(arg[i]) == 'table' then
  582. info = spellinfo(arg[i][1])
  583. temp[i] = {key = arg[i][1], type = #info.words > 0 and info.itemid == 0, force = arg[i][2]}
  584. else
  585. info = spellinfo(arg[i])
  586. temp[i] = {key = arg[i], type = #info.words > 0 and info.itemid == 0, force = "all"}
  587. end
  588.  
  589. i = i + 1
  590. end
  591.  
  592. for _, entry in ipairs(temp) do
  593. local func, params = clientitemhotkey, {"self", "target", "crosshair"}
  594.  
  595. if entry.type then
  596. func, params = clienttexthotkey, {"automatic", "manual"}
  597. end
  598.  
  599. if entry.force and not table.find(params, entry.force:lower()) then
  600. entry.force = 'all'
  601. end
  602.  
  603. if func(entry.key, entry.force) == 'not found' then
  604. return false
  605. end
  606. end
  607. end
  608.  
  609. return true
  610. end
  611.  
  612. function maroundfilter(range, floor, ...)
  613. local Creatures, Callback = {...}, function(c) return true end
  614.  
  615. if type(floor) == 'string' then
  616. table.insert(Creatures, floor)
  617. floor = false
  618. end
  619.  
  620. if type(range) == 'boolean' then
  621. floor = range
  622. range = 7
  623. elseif type(range) == 'string' then
  624. table.insert(Creatures, range)
  625. range = 7
  626. end
  627.  
  628. if type(Creatures[#Creatures]) == 'function' then
  629. Callback = table.remove(Creatures)
  630. end
  631.  
  632. table.lower(Creatures)
  633.  
  634. return __crearoundf__callback(range, floor, Creatures, 'mx', false, Callback)
  635. end
  636.  
  637. function maroundfilterignore(range, floor, ...)
  638. local Creatures, Callback = {...}, function(c) return true end
  639.  
  640. if type(floor) == 'string' then
  641. table.insert(Creatures, floor)
  642. floor = false
  643. end
  644.  
  645. if type(range) == 'boolean' then
  646. floor = range
  647. range = 7
  648. elseif type(range) == 'string' then
  649. table.insert(Creatures, range)
  650. range = 7
  651. end
  652.  
  653. if type(Creatures[#Creatures]) == 'function' then
  654. Callback = table.remove(Creatures)
  655. end
  656.  
  657. table.lower(Creatures)
  658.  
  659. return __crearoundf__callback(range, floor, Creatures, 'mx', true, Callback)
  660. end
  661.  
  662. function paroundfilter(range, floor, ...)
  663. local Creatures, Callback = {...}, function(c) return true end
  664.  
  665. if type(floor) == 'string' then
  666. table.insert(Creatures, floor)
  667. floor = false
  668. end
  669.  
  670. if type(range) == 'boolean' then
  671. floor = range
  672. range = 7
  673. elseif type(range) == 'string' then
  674. table.insert(Creatures, range)
  675. range = 7
  676. end
  677.  
  678. if type(Creatures[#Creatures]) == 'function' then
  679. Callback = table.remove(Creatures)
  680. end
  681.  
  682. table.lower(Creatures)
  683.  
  684. return __crearoundf__callback(range, floor, Creatures, 'px', false, Callback)
  685. end
  686.  
  687. function paroundfilterignore(range, floor, ...)
  688. local Creatures, Callback = {...}, function(c) return true end
  689.  
  690. if type(floor) == 'string' then
  691. table.insert(Creatures, floor)
  692. floor = false
  693. end
  694.  
  695. if type(range) == 'boolean' then
  696. floor = range
  697. range = 7
  698. elseif type(range) == 'string' then
  699. table.insert(Creatures, range)
  700. range = 7
  701. end
  702.  
  703. if type(Creatures[#Creatures]) == 'function' then
  704. Callback = table.remove(Creatures)
  705. end
  706.  
  707. table.lower(Creatures)
  708.  
  709. return __crearoundf__callback(range, floor, Creatures, 'px', true, Callback)
  710. end
  711.  
  712. function unrust(ignore, drop, value)
  713. local IgnoreCommon = ignore or true
  714. local DropTrash = drop or true
  715. local MinValue = math.max(value or 0, 0)
  716.  
  717. if itemcount(9016) == 0 and clientitemhotkey(9016, "crosshair") == 'not found' then
  718. return nil
  719. end
  720.  
  721. local Amount, Trash = {}, {}
  722.  
  723. for _, Item in ipairs({3357, 3358, 3359, 3360, 3362, 3364, 3370, 3371, 3372, 3377, 3381, 3382, 3557, 3558, 8063}) do
  724. if itemvalue(Item) >= MinValue then
  725. Amount[Item] = itemcount(Item)
  726. else
  727. table.insert(Trash, Item)
  728. end
  729. end
  730.  
  731. local RustyItems = IgnoreCommon and {8895, 8896, 8898, 8899} or {8894, 8895, 8896, 8897, 8898, 8899}
  732.  
  733. for _, Item in ipairs(RustyItems) do
  734. if itemcount(Item) > 0 then
  735. pausewalking(itemcount(Item) * 2000)
  736. useitemon(9016, Item, '0-15') waitping(1, 1.5)
  737. --increaseamountused(9016, 1) --bot already adds items used
  738. pausewalking(0)
  739. end
  740. end
  741.  
  742. if DropTrash then
  743. for _, Item in ipairs(Trash) do
  744. if itemcount(Item) > 0 then
  745. pausewalking(2000)
  746. moveitems(Item, "ground") waitping(1, 1.5)
  747. pausewalking(0)
  748. end
  749. end
  750. end
  751.  
  752. for Item, Count in pairs(Amount) do
  753. local Current = itemcount(Item)
  754.  
  755. if Current > Count then
  756. Amount[Item] = Current
  757.  
  758. increaseamountlooted(Item, Current - Count)
  759. end
  760. end
  761. end
  762.  
  763. local antiFurnitureException = {--[[areca palm]]}
  764.  
  765. function antifurnituretrap(weapon, stand)
  766. weapon = weapon or 'Machete'
  767. stand = (stand or 0) * 1000
  768.  
  769. if clientitemhotkey(weapon, 'crosshair') == 'not found' and itemcount(weapon) == 0 then
  770. return "AntiFurniture[Issue1]: 'Weapon' given not found on hotkeys and not visible."
  771. end
  772.  
  773. if $standtime > stand then
  774. local Furniture = {}
  775.  
  776. for x, y, z in screentiles(ORDER_RADIAL, 7) do
  777. if tilereachable(x, y, z, false) and not LIB_CACHE.antifurniture[ground(x, y, z)] then
  778. local tile = gettile(x, y, z)
  779.  
  780. for k = tile.itemcount, 1, -1 do
  781. local info = iteminfo(tile.item[k].id)
  782.  
  783. if (info.isunpass and not info.isunmove) or table.find(antiFurnitureExceptions, info.id) then
  784. table.insert(Furniture, {x = x, y = y, z = z, id = info.id, top = k == tile.itemcount})
  785. break
  786. end
  787. end
  788. end
  789. end
  790.  
  791. if #Furniture > 0 then
  792. for _, item in ipairs(Furniture) do
  793. local x, y, z, id, top = item.x, item.y, item.z, item.id, item.top
  794.  
  795. pausewalking(10000) reachlocation(x, y, z)
  796.  
  797. foreach newmessage m do
  798. if m.content:match("You are not invited") then
  799. LIB_CACHE.antifurniture[ground(x, y, z)] = true
  800. return "AntiFurniture[Issue4]: Cancelling routine due to an item inside a house. (top item)"
  801. end
  802. end
  803.  
  804. if top then
  805. while id == topitem(x, y, z).id and tilereachable(x, y, z, false) do
  806. useitemon(weapon, id, ground(x, y, z)) waitping()
  807.  
  808. foreach newmessage m do
  809. if m.content:match("You are not invited") then
  810. LIB_CACHE.antifurniture[ground(x, y, z)] = true
  811. return "AntiFurniture[Issue4]: Cancelling routine due to an item inside a house. (top item)"
  812. end
  813. end
  814. end
  815. else
  816. browsefield(x, y, z) waitcontainer("browse field", true)
  817. local cont = getcontainer('Browse Field')
  818.  
  819. for j = 1, cont.lastpage do
  820. for i = 1, cont.itemcount do
  821. local info = iteminfo(cont.item[i].id)
  822.  
  823. if info.isunpass and not info.isunmove then
  824. while itemcount(cont.item[i].id, 'Browse Field') > 0 and tilereachable(x, y, z, false) do
  825. useitemon(weapon, info.id, "Browse Field") waitping()
  826.  
  827. foreach newmessage m do
  828. if m.content:match("You are not invited") then
  829. LIB_CACHE.antifurniture[ground(x, y, z)] = true
  830. return "AntiFurniture[Issue3]: Cancelling routine due to an item inside a house. (browsing field)"
  831. end
  832. end
  833. end
  834. end
  835. end
  836.  
  837. changepage('browse field', math.min(j + 1, cont.lastpage))
  838. end
  839. end
  840.  
  841. pausewalking(0)
  842. end
  843. else
  844. return "AntiFurniture[Issue5]: Character is standing still without furnitures to break."
  845. end
  846. else
  847. return "AntiFurniture[Issue2]: Current standtime less than the required time."
  848. end
  849.  
  850. return "AntiFurniture[No Issue]"
  851. end
  852.  
  853. function getdistancebetween(x, y, z, a, b, c)
  854. if type(x) == 'table' and type(y) == 'table' and not (z and a and b and c) then
  855. if x.x and y.x then
  856. x, y, z, a, b, c = x.x, x.y, x.z, y.x, y.y, y.z
  857. elseif #x == 3 and #y == 3 then
  858. x, y, z, a, b, c = x[1], x[2], x[3], y[1], y[2], y[3]
  859. else
  860. return -1
  861. end
  862. end
  863.  
  864. return z == c and math.max(math.abs(x - a), math.abs(y - b)) or -1
  865. end
  866.  
  867. function isabletocast(spell)
  868. spell = ("userdata|table"):find(type(spell)) ~= nil and spell or spellinfo(spell)
  869.  
  870. return spell.cancast
  871. end
  872.  
  873. function cancast(spell, cre)
  874. spell = ("userdata|table"):find(type(spell)) ~= nil and spell or spellinfo(spell)
  875.  
  876. local cool, strike = LIB_CACHE.cancast[spell.name:lower()] or 0, false
  877.  
  878. if cre then
  879. cre = type(cre) == 'userdata' and cre or findcreature(cre)
  880.  
  881. if spell.castarea ~= 'None' and spell.castarea ~= '' then
  882. strike = spell.words
  883. end
  884. end
  885.  
  886. return (not strike or isonspellarea(cre, strike, $self.dir)) and $timems >= cool and $level >= spell.level and $mp >= spell.mp and $soul >= spell.soul and cooldown(spell.words) == 0
  887. end
  888.  
  889. function unequipitem(slot, bp, amount)
  890. slot = slotNames[slot:lower()]
  891.  
  892. if slot then
  893. item = slot()
  894.  
  895. if item.obj.id > 0 then
  896. if type(bp) == 'number' then
  897. amount = bp
  898. bp = '0-15'
  899. elseif not amount then
  900. amount = item.obj.count
  901. end
  902.  
  903. return moveitems(item.obj.id, bp, item.name, amount or item.obj.count)
  904. end
  905. end
  906. end
  907.  
  908. function isinsidearea(...)
  909. local SpecialAreas = {...}
  910.  
  911. if #SpecialAreas == 1 and type(SpecialAreas[1][1]) == 'table' then
  912. SpecialAreas = SpecialAreas[1]
  913. end
  914.  
  915. for i, area in ipairs(SpecialAreas) do
  916. if #area == 5 then
  917. local a,b,c,d,e = unpack(area)
  918.  
  919. if $posz == e and $posx <= b and $posx >= a and $posy <= d and $posy >= c then
  920. return true
  921. end
  922. end
  923. end
  924.  
  925. return false
  926. end
  927.  
  928. function pvpworld()
  929. return table.find({"Astera", "Calmera", "Candia", "Celesta", "Fidera", "Guardia", "Harmonia", "Honera", "Luminera", "Magera", "Menera", "Nerana", "Olympa", "Pacera", "Refugia", "Secura", "Unitera"}, $worldname) == nil
  930. end
  931.  
  932. function checklocation(dist, label, section)
  933. local t = type(dist)
  934. dist = (t == 'number' and dist > 0) and dist or false
  935.  
  936. if t == 'number' and not ($posx <= $wptx + dist and $posx >= $wptx-dist and $posy <= $wpty + dist and $posy >= $wpty - dist and $posz == $wptz) then
  937. if not (label and section) then
  938. return false
  939. else
  940. return gotolabel(label, section)
  941. end
  942. elseif t == 'boolean' and not dist then
  943. if not (label and section) then
  944. return false
  945. else
  946. return gotolabel(label, section)
  947. end
  948. end
  949.  
  950. return true
  951. end
  952.  
  953. function isontemple()
  954. local temp = isinsidearea(cityTemples)
  955.  
  956. if $connected then
  957. LIB_CACHE.isontemple = temp
  958. return $pzone and temp
  959. else
  960. return LIB_CACHE.isontemple
  961. end
  962. end
  963.  
  964. function withdrawitems(where, to, ...)
  965. local items = {...}
  966. local tempType = type(where)
  967. local waitFunc = function()
  968. return waitping(1.5, 2)
  969. end
  970.  
  971. if tempType == 'string' then
  972. where = where:lower()
  973.  
  974. if where:find('depot') or where:find('chest') then
  975. -- user input depot, but the correct name is 'Depot Chest'
  976. where = 'Depot Chest'
  977. elseif where:find('inbox') then
  978. -- used input inbox, but the correct name is 'Your Inbox'
  979. where = 'Your Inbox'
  980. else
  981. -- used input any container name
  982. where = getlootingdestination(where) or itemname(where)
  983. end
  984. elseif tempType == 'userdata' and where.objtype == 'container' then
  985. -- user input any container object, we only want the name
  986. where = where.name
  987. else
  988. return false
  989. end
  990.  
  991. tempType = type(to)
  992.  
  993. if tempType == 'table' then
  994. -- user input a table of items
  995. table.insert(items, 1, to)
  996. to = '0-15'
  997. elseif tempType == 'string' then
  998. if getcontainer(to).name == '' and tonumber(to:sub(1,1)) == nil then
  999. -- used input a invalid container and invalid index
  1000. return false
  1001. end
  1002.  
  1003. to = getlootingdestination(to) or itemname(to)
  1004. elseif tempType == 'userdata' and to.objtype == 'container' then
  1005. -- used input a container object, we only want the name
  1006. to = to.name
  1007. end
  1008.  
  1009. if type(items[#items]) == 'function' then
  1010. waitFunc = table.remove(items)
  1011. end
  1012.  
  1013. for _, item in ipairs(items) do
  1014. tempType = type(item)
  1015.  
  1016. if tempType == 'table' then
  1017. local bp, id, amount = itemname(item.backpack or item.bp or item[1]), item.name or item[2], item.amount or item.count or item[3] or 100
  1018.  
  1019. if id and bp and amount then
  1020. moveitemsupto(id, amount + itemcount(id, bp), bp, from) waitFunc()
  1021. end
  1022. elseif tempType == 'number' or tempType == 'string' then
  1023. moveitems(item, to, where) waitFunc()
  1024. end
  1025. end
  1026.  
  1027. return true
  1028. end
  1029.  
  1030. function screentiles(sortf, area, func)
  1031. local tempType, xs, ys, xe, ye, Positions, i = type(sortf), -7, -5, 7, 5, {}, 0
  1032.  
  1033. if tempType == 'table' and #sortf == 4 then
  1034. xs, xe, ys, ye = sortf[1], sortf[2], sortf[3], sortf[4]
  1035. sortf = false
  1036. elseif tempType ~= 'function' then
  1037. sortf = false
  1038. end
  1039.  
  1040. tempType = type(area)
  1041.  
  1042. if tempType == 'function' then
  1043. func = area
  1044. elseif tempType == 'table' and #area == 4 then
  1045. xs, xe, ys, ye = area[1], area[2], area[3], area[4]
  1046. elseif tempType == 'number' then
  1047. xs, xe, ys, ye = -area, area, -area, area
  1048. end
  1049.  
  1050. for x = xs, xe, xs < xe and 1 or -1 do
  1051. for y = ys, ye, ys < ye and 1 or -1 do
  1052. local _x, _y = $posx + x, $posy + y
  1053.  
  1054. if tilehasinfo(_x, _y, $posz) then
  1055. table.insert(Positions, {_x, _y, $posz})
  1056. end
  1057. end
  1058. end
  1059.  
  1060. if sortf then
  1061. table.sort(Positions, sortf)
  1062.  
  1063. if sortf == ORDER_RANDOM then
  1064. -- little trick to get random values for ORDER_RANDOM every time it is used
  1065. LIB_CACHE.screentiles = math.random(10^2, 10^4)
  1066. end
  1067. end
  1068.  
  1069. return function()
  1070. i = i + 1
  1071.  
  1072. if Positions[i] then
  1073. return func and func(Positions[i][1], Positions[i][2], Positions[i][3]) or Positions[i][1], Positions[i][2], Positions[i][3]
  1074. end
  1075.  
  1076. return
  1077. end
  1078. end
  1079.  
  1080. function drawvector(x1, y1, x2, y2) -- By Lucas Terra
  1081. drawline(x1, y1, x2-x1, y2-y1)
  1082. end
  1083.  
  1084. --[[ randomcolor, todo:
  1085. * Make colors more attractive instead of the metallic outcome
  1086. * Fix some wrong colors when selecting a X base
  1087. ]]--
  1088. function randomcolor(options)
  1089. options = options or {}
  1090. local h, s, l = math.random(0, 360), math.random(0, 100) / 100, math.random(0, 100) / 100
  1091. local monochrome = false
  1092.  
  1093. if options.hue then
  1094. local hueType = type(options.hue)
  1095.  
  1096. if hueType == 'string' then
  1097. options.hue = options.hue:lower()
  1098.  
  1099. if defaultColors[options.hue] then
  1100. if options.hue == 'monochrome' then
  1101. h, s, monochrome = 0, 0, true
  1102. else
  1103. h = math.random(defaultColors[options.hue][1], defaultColors[options.hue][2])
  1104. end
  1105. end
  1106. elseif hueType == 'number' and options.hue <= 360 and options.hue >= 0 then
  1107. h = options.hue
  1108. end
  1109. end
  1110.  
  1111. if (not monochrome) and options.saturation and options.saturation <= 100 and options.saturation >= 0 then
  1112. s = options.saturation / 100
  1113. end
  1114.  
  1115. if options.brightness then
  1116. local brightnessType = type(options.brightness)
  1117.  
  1118. if brightnessType == 'string' then
  1119. options.brightness = options.brightness:lower()
  1120.  
  1121. if options.brightness == 'dark' then
  1122. l = math.random(0, 33) / 100
  1123. elseif options.brightness == 'light' then
  1124. l = math.random(67, 100) / 100
  1125. elseif options.brightness == 'medium' then
  1126. l = math.random(34, 66) / 100
  1127. end
  1128. elseif brightnessType == 'number' and options.brightness <= 100 and options.brightness >= 0 then
  1129. l = options.brightness / 100
  1130. end
  1131. end
  1132.  
  1133. if options.amount then
  1134. local tbl, opt = {}, table.copy(options)
  1135.  
  1136. opt.amount = nil
  1137.  
  1138. for i = 0, options.amount-1 do
  1139. if options.gradient then
  1140. table.insert(tbl, (i * 100 / options.amount) / 100)
  1141. end
  1142.  
  1143. table.insert(tbl, randomcolor(opt))
  1144. end
  1145.  
  1146. return unpack(tbl)
  1147. end
  1148.  
  1149. -- the code below was basically copied from here:
  1150. -- http://stackoverflow.com/questions/10393134/converting-hsl-to-rgb
  1151.  
  1152. h = h / 60
  1153. local chroma = (1 - math.abs(2 * l - 1)) * s
  1154. local x = (1 - math.abs(h % 2 - 1)) * chroma
  1155. local r, g, b = 0, 0, 0
  1156.  
  1157. if h < 1 then
  1158. r, g, b = chroma, x, 0
  1159. elseif h < 2 then
  1160. r, b, g = x, chroma, 0
  1161. elseif h < 3 then
  1162. r, g, b = 0, chroma, x
  1163. elseif h < 4 then
  1164. r, g, b = 0, x, chroma
  1165. elseif h < 5 then
  1166. r, g, b = x, 0, chroma
  1167. else
  1168. r, g, b = chroma, 0, x
  1169. end
  1170.  
  1171. local m = l - chroma / 2
  1172.  
  1173. return color((r + m) * 256, (g + m) * 256, (b + m) * 256, options.transparency)
  1174. end
  1175.  
  1176. function rashidlocation()
  1177. local weekday = os.date("%w", os.time()-(86400-sstime()))
  1178.  
  1179. return ({"Carlin", "Svargrond", "Liberty Bay", "Port Hope", "Ankrahmun", "Darashia", "Edron"})[weekday % 7 + 1]
  1180. end
  1181.  
  1182. -- FIXES AND GENERAL EXTENSIONS
  1183.  
  1184. -- extend aliases
  1185. unequip = unequip or unequipitem
  1186. antifurniture = antifurniture or antifurnituretrap
  1187. -- this is actually the correct name, but ppl know as unequip since elfbot
  1188. dequip = dequip or unequip
  1189. dequipitem = dequipitem or dequip
  1190.  
  1191. -- enables advanced cooldown control in cancast
  1192. function cast(...)
  1193. local args = {...}
  1194. local info = ("userdata|table"):find(type(args[1])) ~= nil and args[1] or spellinfo(args[1])
  1195. LIB_CACHE.cancast[info.name:lower()] = $timems + info.duration
  1196.  
  1197. return __FUNCTIONS.CAST(...)
  1198. end
  1199.  
  1200. printf("Leonardo\'s library loaded, version: %s", LIBS.LEONARDO)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement