Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CHECK_TIME = 60 * 60 -- 1 hr, interval between check SAME character again.
- local MIN_STAMINA = 17 -- hours, min stamina to go hunt when checking.
- local LOG_STAMINA = 14 -- stamina to leave spawn and logout.
- -- Limit time!
- HUNT_TIME = "07:15:00"
- ACCOUNTS = {
- [1] = {acc = 'myacc1', psw = 'mypass1'}, -- my bot acc number 1
- [2] = {acc = 'myacc2', psw = 'mypass2'} -- my bot acc number 2
- }
- CHARACTERS = {
- [1] = {'Bototo', 'Botin'}, -- my characters in account 1, id should match!
- [2] = {'Botoneitor', 'Bots of haste'} -- my characters in account 2, id should match!
- }
- -- Not to edit, internal use.
- TRAINERS = {
- [1] = {name = 'sword', itemid = 16198},
- [2] = {name = 'axe', itemid = 16199},
- [3] = {name = 'club', itemid = 16200},
- [4] = {name = 'distance', itemid = 16201},
- [5] = {name = 'magic', itemid = 16202}
- }
- -- Class AccountManager
- AccountManager = {}
- AccountManager.__index = AccountManager
- function AccountManager.new(names)
- return setmetatable({names = names}, AccountManager)
- end
- function AccountManager.getAccount(name)
- for k, v in pairs(CHARACTERS) do
- if isInArray(v, name) then
- local info = ACCOUNTS[k]
- if (info ~= nil) then
- return info.acc, info.psw
- end
- end
- end
- return nil
- end
- function AccountManager.getSkill()
- local max_skill = {id = 0, value = 0}
- for id, value in pairs({sword, axe, club, distance, mlevel}) do
- if (value > max_skill.value) then
- max_skill.id = id
- max_skill.value = value
- end
- end
- -- We need a default skill to train incase we don't find our best skill.
- -- Magic level is useful no matter what vocation we are.
- if (max_skill.value == 10) and (max_skill.id ~= 5) then -- Probably new character
- max_skill.id = 5
- max_skill.value = 0 -- not really matters at this point.
- end
- return max_skill
- end
- function AccountManager.useTrainer(name)
- print('Attemping to use trainers: ' .. name)
- updateworld()
- wait(2500, 4500)
- -- Assuming we are already on the previous waypoint.
- -- This should be the central SQM in trainers.
- wait(500, 700)
- updateworld()
- -- Lets get our best skill
- local toTrain = TRAINERS[AccountManager.getSkill().id]
- local __toPos = nil
- for _, pos in pairs(buildArea(myPosition(), 6)) do
- for _, item in pairs(getTileItems(pos)) do
- if (item.id == toTrain.itemid) then
- __toPos = pos
- break
- end
- end
- end
- if (__toPos ~= nil) then
- print('Using training statue for skill: ' .. toTrain.name .. ' -> character: ' .. name)
- reachlocation(__toPos.x, __toPos.y, __toPos.z)
- wait(1000, 1500)
- useitem(toTrain.itemid, __toPos.x, __toPos.y, __toPos.z)
- else
- print('Can\'t find training statue for skill: ' .. toTrain.name)
- -- We execute a normal logout.
- logout()
- end
- end
- -- in my case I use my own functions to handle backpacks, you'll need take a look here.
- function AccountManager:setBackpacks(backpacks)
- self.backpacks = backpacks
- end
- function AccountManager:setLabel(label)
- self.label = label
- end
- function AccountManager:removeUser(name)
- local index = nil
- for k, v in pairs(self.names) do
- if (v == name) then
- index = k
- break
- end
- end
- if (index ~= nil) then
- table.remove(self.names, index)
- print('Error: removed user ' .. name .. '.')
- else
- print('Error: remove, user ' .. name .. ' not found.')
- end
- end
- function AccountManager:removeCurrentUser()
- self:removeUser(self.online)
- self.last = self.online
- self.online = nil
- end
- function AccountManager:getLastCheck(name)
- if (self.check == nil) then
- return nil
- end
- return self.check[name]
- end
- function AccountManager:setLastCheck(name)
- if (self.check == nil) then
- self.check = {}
- end
- self.check[name] = os.time()
- end
- function AccountManager:ignoreHuntingTime(bool)
- setGlobalVariable("ignoretime_" .. getscriptname(), bool)
- end
- function AccountManager:checkStamina()
- local ignore = getBooleanFromGlobal("ignoretime_" .. getscriptname())
- if (timehunt >= HUNT_TIME) and not ignore then
- return false
- end
- return (fromStamina() > LOG_STAMINA)
- end
- function AccountManager:think()
- local nextReady = getBooleanFromGlobal("next_" .. getscriptname())
- if nextReady then
- self:setLastCheck(name)
- self.last = name
- self.online = nil
- print('Moving to next user ...')
- setGlobalVariable("next_" .. getscriptname(), false)
- wait(3000)
- if isInTrainers() then
- AccountManager.useTrainer(name)
- else
- logout()
- end
- return false
- end
- if (self.online == nil) then
- if not connected then
- -- Let's decide who should login ...
- if (self.last == nil) then
- -- First login attemp?
- local newUser = self.names[1]
- local acc, pass = AccountManager.getAccount(newUser)
- if (acc == nil) then
- print('Error: no account found, removing: ' .. newUser)
- self:removeUser(newUser)
- return false
- end
- print('Attemping to connect: ' .. newUser)
- focusclient()
- connect(acc, pass, newUser)
- wait(2000)
- updateworld()
- if connected then
- if pzone and not isInSafePosition() then
- print('User ' .. newUser .. ' did die, removing from list ...')
- logout()
- self:removeUser(newUser)
- return false
- end
- -- Check stamina
- wait(1775, 2135)
- if (stamina >= toStamina(MIN_STAMINA)) then
- -- PAY ATTENTION HERE, YOU SHOULD IMPLEMENT YOUR BACKPACK HANDLER HERE.
- -- if not checkBackpacks(self.backpacks) then
- reOpenBackpacks(self.backpacks)
- -- end
- print('Character ' .. newUser .. ' is now the system\'s user :)')
- self.online = newUser
- -- -- -- --
- if not cavebot then
- setcavebot("yes")
- end
- -- Labels ~
- gotolabel(self.label)
- -- -- -- --
- else
- print('Character ' .. newUser .. ' has not enough stamina, let\'s check next ...')
- self:setLastCheck(newUser)
- self.last = newUser
- if isInTrainers() then
- AccountManager.useTrainer(newUser)
- else
- logout()
- end
- end
- end
- else
- -- Get next user ...
- local index = nil
- for k, v in pairs(self.names) do
- if (v == self.last) then
- index = k
- break
- end
- end
- if (index == nil) then
- print('Fatal error: can not find index for user: ' .. self.last .. ', set self.last to nil.')
- self.last = nil
- else
- local i = ((index < #self.names) and (index + 1) or 1)
- local newUser = self.names[i]
- local checkTime = self:getLastCheck(newUser)
- if (checkTime ~= nil) then
- if ((os.time() - checkTime) < CHECK_TIME) then
- -- print('Skip user: ' .. newUser .. ' it was checked recently.')
- self.last = newUser
- return false
- end
- end
- local acc, pass = AccountManager.getAccount(newUser)
- if (acc == nil) then
- print('Error: no account found, removing: ' .. newUser)
- self:removeUser(newUser)
- self.last = nil
- return false
- end
- print('Attemping to connect: ' .. newUser)
- focusclient()
- connect(acc, pass, newUser)
- wait(2000)
- updateworld()
- if connected then
- if pzone and not isInSafePosition() then
- print('User ' .. newUser .. ' did die, removing from list ...')
- logout()
- self:removeUser(newUser)
- self.last = nil
- return false
- end
- -- Check stamina
- wait(1775, 2135)
- if (stamina >= toStamina(MIN_STAMINA)) then
- -- PAY ATTENTION HERE, YOU SHOULD IMPLEMENT YOUR BACKPACK HANDLER HERE.
- -- if not checkBackpacks(self.backpacks) then
- reOpenBackpacks(self.backpacks)
- -- end
- print('Character ' .. newUser .. ' is now the system\'s user :)')
- self.online = newUser
- -- -- -- --
- if not cavebot then
- setcavebot("yes")
- end
- -- Labels ~
- gotolabel(self.label)
- -- -- -- --
- resethud()
- else
- print('Character ' .. newUser .. ' has not enough stamina, let\'s check next ...')
- self:setLastCheck(newUser)
- self.last = newUser
- if isInTrainers() then
- AccountManager.useTrainer(newUser)
- else
- logout()
- end
- end
- end
- end
- end
- else
- -- A character is online let's set it as current user
- if isInArray(self.names, name) then
- self.online = name
- print('A character is online let\'s set it as current user: ' .. name)
- else
- print('Error: unknown user online: ' .. name)
- end
- end
- else
- if not connected then -- user was probably kicked, server save, etc ...
- local acc, pass = AccountManager.getAccount(self.online)
- if (acc == nil) then
- print('Error: no account found, removing: ' .. self.online)
- self:removeCurrentUser()
- return false
- end
- -- print('Attemping to RE-connect: ' .. self.online)
- focusclient()
- connect(acc, pass, self.online)
- wait(2000)
- updateworld()
- if connected then
- if pzone and not isInSafePosition() then
- print('User ' .. self.online .. ' did die, removing from list ...')
- logout()
- self:removeCurrentUser()
- return false
- end
- wait(1775, 2135)
- -- PAY ATTENTION HERE, YOU SHOULD IMPLEMENT YOUR BACKPACK HANDLER HERE.
- -- if not checkBackpacks(self.backpacks) then
- reOpenBackpacks(self.backpacks)
- -- end
- print('User ' .. self.online .. ' is back online :)')
- end
- end
- end
- end
- function AccountManager:next()
- print("Finishing " .. name)
- setcavebot("no")
- setGlobalVariable("next_" .. getscriptname(), true)
- end
- -- -- -- -- -- -- --
- -- Shared set users
- -- -- -- -- -- -- --
- local SHARED_SETS = {
- -- Shared set example
- {
- users = {'Botin', 'Botoneitor'},
- set = {
- helmet = 10385, -- Zaoan Helmet
- amulet = 3055, -- Platinum Amulet
- back = 9601, -- Demon Backpack
- armor = 3366, -- Magic Plate Armor
- shield = 3414, -- Mastermind Shield
- weapon = 16160, -- Crystalline Sword
- legs = 10387, -- Zaoan Legs
- boots = 3079 -- Boots of Haste
- },
- pos = {x = 32237, y = 31150, z = 7}
- }
- }
- function isSharedSetUser()
- for k, v in pairs(SHARED_SETS) do
- if isInArray(v.users, name) then
- return v
- end
- end
- return false
- end
- function getCurrentSet()
- return {helmet = helmet, amulet = amulet, back = back, armor = armor, shield = shield, weapon = weapon, legs = legs, boots = boots}
- end
- function AccountManager.checkSet()
- local info = isSharedSetUser()
- if (info ~= false) then
- updateworld()
- local set = getCurrentSet()
- for k, v in pairs(info.set) do
- local vType = type(v)
- if (((vType == 'number') and (v ~= set[k])) or ((vType == 'table') and not isInArray(v, set[k]))) and (tostring(k) ~= "auxbp") then
- return false
- end
- end
- else
- print("Error: " .. name .. " is not shared set user.")
- end
- return true
- end
- function AccountManager.checkEmptySet_noBp()
- local info = isSharedSetUser()
- if (info ~= false) then
- updateworld()
- for k, v in pairs(getCurrentSet()) do
- if (tostring(k) ~= "back") then
- if (v ~= 0) then
- return false
- end
- end
- end
- else
- print("Error: " .. name .. " is not shared set user.")
- end
- return true
- end
- function AccountManager.checkEmptySet()
- local info = isSharedSetUser()
- if (info ~= false) then
- updateworld()
- for k, v in pairs(getCurrentSet()) do
- if (v ~= 0) then
- return false
- end
- end
- else
- print("Error: " .. name .. " is not shared set user.")
- end
- return true
- end
- function needSet()
- if not isSharedSetUser() then
- return false
- end
- return AccountManager.checkEmptySet()
- end
- function needSaveSet()
- if not isSharedSetUser() then
- return false
- end
- return AccountManager.checkSet()
- end
- function AccountManager.findSet()
- if not isInHouse() then
- return print("Error AccountManager.findSet() is not in house.")
- end
- local info = isSharedSetUser()
- if (info ~= false) then
- -- setsettings("Settings\\Actions\\List\\Open BPS\\Enabled", "no")
- updateworld()
- local set = info.set
- if (back ~= set.back) then
- print("Reach backpack position ...")
- if reachlocation(info.pos.x, info.pos.y, info.pos.z) then
- print("Attemping to get backpack ...")
- wait(2000, 3000)
- openbrowsefield(info.pos.x, info.pos.y, info.pos.z)
- wait(1000, 2000)
- moveitems(set.back, ground(info.pos.x, info.pos.y, info.pos.z), 'back', 1)
- end
- else
- if not getcontainer(set.back).open then
- print("Opening backpack ...")
- openitem(set.back, 'back', false)
- wait(500, 900)
- resizewindow(set.back, 4)
- wait(1000, 1200)
- if (set.auxbp ~= nil) then
- openitem(set.auxbp, set.back, true)
- wait(500, 900)
- resizewindow(set.auxbp, 4)
- end
- end
- local cset = getCurrentSet()
- for k, v in pairs(set) do
- if (tostring(k) ~= "back") and (tostring(k) ~= "auxbp") then
- local vType = type(v)
- if ((vType == 'number') and (v ~= cset[k])) or ((vType == 'table') and not isInArray(v, cset[k])) then
- print("Attemping to equip: " .. tostring(k))
- if (vType == 'table') then
- local toEquip = v[1]
- local vOrigin = nil
- if (itemcount(toEquip, set.auxbp) > 0) then
- vOrigin = set.auxbp
- elseif (itemcount(toEquip, set.back) > 0) then
- vOrigin = set.back
- end
- if (vOrigin ~= nil) then
- moveitems(toEquip, vOrigin, tostring(k), 1)
- else
- closetibia()
- return print("Fatal error: " .. name .. " error on equiping set, code: 256.")
- end
- else
- moveitems(v, set.back, tostring(k), 1)
- end
- wait(3000)
- end
- end
- end
- end
- else
- return print("Error: " .. name .. " is not shared set user.")
- end
- if not AccountManager.checkSet() then
- print("Checking set ...")
- wait(2000, 3000)
- AccountManager.findSet()
- return false
- else
- print("Set equiped !!")
- -- setsettings("Settings\\Actions\\List\\Open BPS\\Enabled", "yes")
- end
- return true
- end
- function AccountManager.saveSet()
- if not isInHouse() then
- return print("Error AccountManager.saveSet() is not in house.")
- end
- local info = isSharedSetUser()
- if (info ~= false) then
- -- setsettings("Settings\\Actions\\List\\Open BPS\\Enabled", "no")
- updateworld()
- closewindows()
- wait(3000)
- updateworld()
- local set = info.set
- if (back == set.back) then
- if not getcontainer(set.back).open then
- print("Attemping to open backpack ...")
- openitem(set.back, 'back', false)
- wait(500, 900)
- resizewindow(set.back, 4)
- wait(1000, 1200)
- if (set.auxbp ~= nil) then
- openitem(set.auxbp, set.back, true)
- wait(500, 900)
- resizewindow(set.auxbp, 4)
- end
- end
- if not getcontainer(set.back).open then
- return AccountManager.saveSet()
- end
- local cset = getCurrentSet()
- for k, v in pairs(set) do
- if (tostring(k) ~= "back") and (tostring(k) ~= "auxbp") then
- local vType = type(v)
- if ((vType == 'number') and (v == cset[k])) or ((vType == 'table') and isInArray(v, cset[k])) then
- print("Attemping to de-equip: " .. tostring(k))
- if (vType == 'table') then
- moveitems(cset[k], tostring(k), set.auxbp, 1)
- else
- moveitems(cset[k], tostring(k), set.back, 1)
- end
- wait(3000)
- end
- end
- end
- end
- else
- return print("Error: " .. name .. " is not shared set user.")
- end
- if not AccountManager.checkEmptySet_noBp() then
- print("Still have parts of set on ... ")
- wait(2000, 3000)
- return AccountManager.saveSet()
- else
- print("Set saved to backpack ...")
- end
- print("Attemping to save backpack ...")
- if (back == info.set.back) then
- wait(2000)
- if reachlocation(info.pos.x, info.pos.y, info.pos.z) then
- moveitems(info.set.back, "back", ground(info.pos.x, info.pos.y, info.pos.z), 1)
- wait(2000)
- end
- updateworld()
- if not AccountManager.checkEmptySet() then
- print("Failed to move backpack to save position ...")
- return AccountManager.saveSet()
- else
- print("Set saved in house :)")
- wait(3000)
- -- setsettings("Settings\\Actions\\List\\Open BPS\\Enabled", "yes")
- end
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement