-- Sayild Library 10/08/2012 --
function qs1(tablename, left, right)
if type(tablename) == 'table' then
left = left or 1
right = right or #tablename
local i,j,x
if right-left+1 <= 25 then
for i=left+1, right do
x=tablename[i]
j=i-1
while j>=left and x<tablename[j] do
tablename[j+1]=tablename[j]
j=j-1
end
tablename[j+1]=x
end
else
i,j,x = left, right, tablename[math.floor((left+right)/2)]
local temp
repeat
while tablename[i]<x and i < right do
i = i+1
end
while tablename[j]>x and j > left do
j = j-1
end
if (i <= j) then
temp = tablename[i]
tablename[i] = tablename[j]
tablename[j] = temp
i = i+1
j = j-1
end
until i > j
if (left < j) then
qs1(tablename, left, j)
end
if (right > i) then
qs1(tablename, i, right)
end
end
end
end
function qs2(tablename, left, right, argument)
if type(tablename) == 'table' then
left = left or 1
right = right or #tablename
local i,j,x
if right-left+1 <= 25 then
for i=left+1, right do
x=tablename[i]
j=i-1
while j>=left and x[argument] < tablename[j][argument] do
tablename[j+1]=tablename[j]
j=j-1
end
tablename[j+1]=x
end
else
i,j,x = left, right, tablename[math.floor((left+right)/2)][argument]
local temp
repeat
while tablename[i][argument]<x and i < right do
i = i+1
end
while tablename[j][argument]>x and j > left do
j = j-1
end
if (i <= j) then
temp = tablename[i]
tablename[i] = tablename[j]
tablename[j] = temp
i = i+1
j = j-1
end
until i > j
if (left < j) then
qs2(tablename, left, j, argument)
end
if (right > i) then
qs2(tablename, i, right, argument)
end
end
end
end
function qs3(tablename, left, right)
if type(tablename) == 'table' then
left = left or 1
right = right or #tablename
local i,j,x
if right-left+1 <= 25 then
for i=left+1, right do
x=tablename[i]
j=i-1
while j>=left and x>tablename[j] do
tablename[j+1]=tablename[j]
j=j-1
end
tablename[j+1]=x
end
else
i,j,x = left, right, tablename[math.floor((left+right)/2)]
local temp
repeat
while tablename[i]>x and i < right do
i = i+1
end
while tablename[j]<x and j > left do
j = j-1
end
if (i <= j) then
temp = tablename[i]
tablename[i] = tablename[j]
tablename[j] = temp
i = i+1
j = j-1
end
until i > j
if (left < j) then
qs3(tablename, left, j)
end
if (right > i) then
qs3(tablename, i, right)
end
end
end
end
function qs4(tablename, left, right, argument)
if type(tablename) == 'table' then
left = left or 1
right = right or #tablename
local i,j,x
if right-left+1 <= 25 then
for i=left+1, right do
x=tablename[i]
j=i-1
while j>=left and x[argument]>tablename[j][argument] do
tablename[j+1]=tablename[j]
j=j-1
end
tablename[j+1]=x
end
else
i,j,x = left, right, tablename[math.floor((left+right)/2)][argument]
local temp
repeat
while tablename[i][argument]>x and i < right do
i = i+1
end
while tablename[j][argument]<x and j > left do
j = j-1
end
if (i <= j) then
temp = tablename[i]
tablename[i] = tablename[j]
tablename[j] = temp
i = i+1
j = j-1
end
until i > j
if (left < j) then
qs4(tablename, left, j, argument)
end
if (right > i) then
qs4(tablename, i, right, argument)
end
end
end
end
function seq1(tablename,value)
if type(tablename) == 'table' then
for i,j in ipairs(tablename) do
if j == value then
return i
end
end
end
return
end
function seq2(tablename,value,argument)
if type(tablename) == 'table' then
for i,j in ipairs(tablename) do
if j[argument] == value then
return i
end
end
end
return
end
function bin1(tablename,value)
if type(tablename) == 'table' then
local left,right = 1, #tablename
while left <= right do
local mid = math.floor((right+left)/2)
if tablename[mid] == value then
return mid
end
if tablename[mid] > value then
right = mid-1
else
left = mid+1
end
end
end
return
end
function bin2(tablename,value,argument)
if type(tablename) == 'table' then
local left,right = 1, #tablename
while left <= right do
local mid = math.floor((right+left)/2)
if tablename[mid][argument] == value then
return mid
end
if tablename[mid][argument] > value then
right = mid-1
else
left = mid+1
end
end
end
return
end
function table:find(value,argument) --Working
if argument then
return seq2(self,value,argument)
end
return seq1(self,value)
end
function table:newsort(argument, order) --Working
if argument == 'asc' or argument == 'desc' then
order = argument
argument = false
end
order = order or 'asc'
if order == 'asc' then
if argument then
qs2(self,1,#self,argument)
else
qs1(self,1,#self)
end
else
if argument then
qs4(self,1,#self,argument)
else
qs3(self,1,#self)
end
end
end
function table:binaryfind(value,argument) --Working
if argument then
return bin2(self,value,argument)
end
return bin1(self,value)
end
function dropflask()
dropitems(283,284,285)
end
function depositall()
say("Hi")
wait(1500,2500)
npcsay("Deposit all")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function travelvenore()
say("Hi")
wait(1500,2500)
npcsay("Venore")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function traveledron()
say("Hi")
wait(1500,2500)
npcsay("Edron")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function travelcarlin()
say("Hi")
wait(1500,2500)
npcsay("Carlin")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function travelthais()
say("Hi")
wait(1500,2500)
npcsay("Thais")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function traveldarashia()
say("Hi")
wait(1500,2500)
npcsay("Darashia")
wait(300,500)
npcsay("yes")
wait(200,300)
npcsay("yes")
wait(200,300)
end
function travelankrahmun()
say("Hi")
wait(1500,2500)
npcsay("Ankrahmun")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function travellibertybay()
say("Hi")
wait(1500,2500)
npcsay("Liberty Bay")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function travelyalahar()
say("Hi")
wait(1500,2500)
npcsay("Yalahar")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function travelporthope()
say("Hi")
wait(1500,2500)
npcsay("Port Hope")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function travelfarmine()
say("Hi")
wait(1500,2500)
npcsay("Farmine")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function travelgoroma()
say("Hi")
wait(1500,2500)
npcsay("Goroma")
wait(300,500)
npcsay("yes")
wait(200,300)
end
function opentrade()
if not tradeopen then
say("Hi")
wait(1500,2500)
npcsay("Trade")
wait(600,800)
updateworld()
end
end
function sellflasks()
opentrade()
if tradeopen then
for i=283,285 do
local count = countitem(i)
while count > 0 do
sellitems(i,count)
wait(200,300)
count = countitem(i)
end
end
end
end
function staminalow()
while $stamina < 60*16 do
if $battlesigned then
pausewalking(500)
else
closeclient()
end
wait(100)
end
function repairsoft()
say('hi')
wait(2000, 3000)
while itemcount(6530) > 0 do
npcsay('repair')
wait(500, 1500)
npcsay('yes')
wait(500, 1500)
end
function windowcount(item)
item = item or "all"
return wincount(item)
end
function openitem(item, origem, next, index)
index = index or 0
next = next or false
return openitemindex(item, origem, next, index)
end
function wait(time1, time2)
time2 = time1 or time2
sleep(time1, time2)
end
function islocation(value)
value = value or 0
return isloc(value)
end
function islocationxyz(x,y,z,distance)
distance= distance or 0
return _islocationxyz(x,y,z,distance)
end
function moveitems(item, origem, destino, count)
if destino == nil and count == nil then
moveitemsb(item, origem, 100)
return
end
if count == nil then
moveitemsb(item, origem, destino)
return
end
moveitemsa(item, origem, destino, count)
end
function buyitemsupto(itemname, amount, currentamount)
currentamount = currentamount or itemcount(itemname)
amount = amount-currentamount
while amount > 0 do
buyitems(itemname, amount)
wait(200,300)
amount = amount-100
end
end
function sellitemsupto(itemname, amount, currentamount)
currentamount = currentamount or itemcount(itemname)
amount = amount-currentamount
while amount > 0 do
sellitems(itemname, amount)
wait(200,300)
amount = amount-100
end
end
function entermachine(item)
local currentamount = itemcount(item)
amount = currentamount - 20
count = 0
maxtry = 50
while itemcount(item) > amount and count < maxtry do
count = count + 1
if islocationxyz(33268, 31830, 10, 5) then
if toptileitem(33268, 31830, 10) == 846 then
useitem(846, 33268, 31830, 10)
wait(400,600)
end
useitemon(item, 33268, 31830, 10)
wait(500,600)
if(currentamount == itemcount(item)) then
if toptileitem(33268, 31830, 10) == 842 then
useitem(842, 33268, 31830, 10)
wait(400,600)
end
else
currentamount = itemcount(item)
end
else
break
end
end
if toptileitem(33268, 31830, 10) == 842 then
useitem(842, 33268, 31830, 10)
wait(400,600)
end
end
function dropitems(pos,...)
local items = {...}
if type(pos) == 'number' then
table.insert(items,pos)
pos = 'ground'
end
for i,j in ipairs(items) do
while itemcount(j) > 0 do
moveitemsb(j,pos,100)
end
end
end
function levitate(direction,updown)
local dir = {x = {n = 0, s = 0, w = -1, e = 1}, y = {n = -1, s = 1, w = 0, e = 0}}
if direction == 'w' or direction == 'e' or direction == 'n' or direction == 's' then
local startposz,tries,maxtries = posz,0,math.random(4,6)
if not updown or (updown ~= 'up' and updown ~= 'down') then
local toptileid = toptileitem(posx+dir.x[direction],posy+dir.y[direction],posz)
updown = 'up'
if toptileid == 0 or itemproperty(toptileid).isUnpassable == true then
updown = 'down'
end
end
while mp >= 50 and level >= 12 and posz == startposz and tries < maxtries do
turn(direction)
cast('exani hur '..updown)
wait(1000,1500)
tries=tries+1
if posz ~= startz then
return true
end
end
end
return false
end
function depotdeposit(bptomove,...)
lastonto = 0
local items = {...}
local _nexti = true
for i,j in pairs(items) do
_nexti = true
while itemcount(items[i]) > 0 and _nexti do
_nexti = moveitemsonto(items[i], "all", bptomove, 100, lastonto)
wait(400,500)
end
end
end
function itemcount(item, origem)
origem = origem or "all"
return _itemcount(item, origem)
end
function countitem(item, origem)
origem = origem or "all"
return _itemcount(item, origem)
end
function higherwindows(name)
name = name or "all"
_controlwindows(name, true)
end
function minimizewindows(name)
name = name or "all"
_controlwindows(name, false)
end
function haste()
if not hasted then
cast("utani hur")
end
end
function antiidle()
turn("n")
turn("e")
turn("s")
turn("w")
end
function manashield()
if not manashielded then
cast("utamo vita")
end
end
function charge()
if not hasted then
cast("utani tempo hur")
end
end
function stronghaste()
if not hasted then
cast("utani gran hur")
end
end
function maround(range,allfloors,...)
local names = {...}
range = range or 7
allfloors = allfloors or false
if type(range) == 'string' then
table.insert(names,range)
range = 7
end
if type(allfloors) == 'string' then
table.insert(names,allfloors)
allfloors = false
end
local name = ''
for i,j in pairs(names) do
name = name..names[i]..';'
end
return _maround(range,allfloors,name)
end
function paround(range,allfloors,...)
local names = {...}
range = range or 7
allfloors = allfloors or false
if type(range) == 'string' then
table.insert(names,range)
range = 7
end
if type(allfloors) == 'string' then
table.insert(names,allfloors)
allfloors = false
end
local name = ''
for i,j in pairs(names) do
name = name..names[i]..';'
end
return _paround(range,allfloors,name)
end
function pickupitems(dir,...)
local items = {...}
local dire = {dirs = {'c', 'n', 's', 'w', 'e', 'nw', 'ne', 'sw', 'se'},
x = {c = 0, n = 0, s = 0, w = -1, e = 1, nw = -1, ne = 1, sw = -1, se = 1},
y = {c = 0, n = -1, s = 1, w = 0, e = 0, nw = -1, ne = -1, sw = 1, se = 1}}
if not dir or not table.find(dire.dirs,dir) then
if dir ~= nil then
table.insert(items,dir)
end
dir = 'c'
end
local pos = {x = posx+dire.x[dir], y = posy+dire.y[dir], z = posz}
local topid = toptileitem(pos.x,pos.y,pos.z)
local id = topid
local item = itemproperty(topid)
if #items == 0 then
if topid ~= 0 and item.isTakeable then
moveitems(topid,ground(pos.x,pos.y,pos.z),'all',100)
end
else
for i,j in pairs(items) do
if type(j) == 'number' then
id = j
else
id = itemid(j)
end
if topid == id and item.isTakeable then
moveitems(topid,ground(pos.x,pos.y,pos.z),'all',100)
break
end
end
end
end
function gotolabel(label)
if type(label) == 'number' then
_gotolabeln(label)
else
_gotolabels(label)
end
end
function useitem(item, x, y, z)
x = x or 'all'
if type(x) == 'number' then
_useitemxyz(item, x, y, z)
else
_useitem(item, x)
end
end
function useitemon(item, x, y, z)
if z == nil then
y = y or 'all'
useitemonitem(item, x, y)
else
_useitemon(item, x, y, z)
end
end
function say(text, channel)
if channel == nil then
_say(text)
else
anysay(text, channel)
end
end
function underattack(type)
type = type or 'all'
return _underattack(type)
end
function gold()
return itemcount(3031) + (itemcount(3035) * 100) + (itemcount(3043) * 10000)
end
function antifurnituretrap(weapontouse)
weapontouse = weapontouse or 3308 -- machete
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}
for i=-7,7 do
for j=-5,5 do
local x,y,z = posx+i,posy+j,posz
if table.binaryfind(blockwalkids,toptileitem(x,y,z)) then
if tilereachable(x,y,z) then
pausewalking(10000)
local topid = toptileitem(x,y,z)
while tilereachable(x,y,z) and (math.abs(posx-x) > 1 or math.abs(posy-y) > 1) do
reachlocation(x,y,z)
wait(100,200)
updateworld()
end
while toptileitem(x,y,z) == topid and posz == z and (math.abs(posx-x) <= 1 and math.abs(posy-y) <= 1) do
useitemon(weapontouse,toptileitem(x,y,z),ground(x,y,z))
pausewalking(5000)
wait(400,500)
updateworld()
end
pausewalking(0)
end
end
end
end
end
function getcreatures(filter)
filter = filter or 'pmfs'
return _getcreatures(filter)
end
function openhole(x,y,z,holes)
x,y,z = x or wptx, y or wpty, z or wptz
holes = holes or {{593,594}, {606, 607}, {608, 609}, {867, 868}}
reachlocation(x,y,z)
if x and y and z and math.abs(posx-x) <= 7 and math.abs(posy-y) <= 5 and posz == z then
local v = 1
while v <= #holes and not isitemontile(holes[v][1],x,y,z) do
v = v+1
end
if v <= #holes then
local id = toptileitem(x,y,z)
while id ~= holes[v][2] do
if id == holes[v][1] then
if iscreatureontile(x,y,z) then
local dir = wheretomove(x,y,z)
moveitems(99,ground(x,y,z),ground(dir.x,dir.y,z),100)
wait(1400,1600)
else
useitemon(shovel,x,y,z)
wait(900,1100)
end
else
local dir = wheretomove(x,y,z)
moveitems(id,ground(x,y,z),ground(dir.x,dir.y,z),100)
wait(500,700)
end
id = topitem(x,y,z)
end
return true
end
end
return false
end
function opensand(x,y,z)
return openhole(x,y,z, {{231,615}})
end
function uselever(x,y,z,id)
x,y,z = x or wptx, y or wpty, z or wptz
local levers = {2771, 2772}
if id then
levers = {id}
end
reachlocation(x,y,z)
if x and y and z and math.abs(posx-x) <= 7 and math.abs(posy-y) <= 5 and posz == z then
local v = 1
while v <= #levers and not isitemontile(levers[v],x,y,z) do
v = v+1
end
if v <= #levers then
local id = toptileitem(x,y,z)
while isitemontile(levers[v],x,y,z) do
if id == levers[v] then
if iscreatureontile(x,y,z) then
local dir = wheretomove(x,y,z)
moveitems(99,ground(x,y,z),ground(dir.x,dir.y,z),100)
wait(1400,1600)
else
useitem(levers[v],ground(x,y,z))
wait(500,700)
end
else
local dir = wheretomove(x,y,z)
moveitems(id,ground(x,y,z),ground(dir.x,dir.y,z),100)
wait(500,700)
end
id = toptileitem(x,y,z)
end
return true
end
end
return false
end
function getitems(...)
local items = {...}
local item = ''
for i,j in pairs(items) do
item = item..items[i]..';'
end
return _getitems(item)
end