Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function closeBackpacks(...)
- local backpacks = {...}
- local indexes = Container.GetIndexes()
- if #backpacks > 0 then
- for i = #backpacks, 1, -1 do
- if type(backpacks[i]) == "string" then
- tmpBP = Container.GetByName(backpacks[i])
- elseif backpacks[i] < 18 then
- tmpBP = Container.GetFromIndex(backpacks[i])
- else
- tmpBP = Container.GetByName(Item.GetName(backpacks[i]))
- end
- tmpBP:Close()
- wait(200, 500)
- end
- else
- Self.CloseContainers()
- end
- end
- function openBackpacks(...)
- local backpacks = {...} -- List of backpacks to open.
- local open = Container.GetIndexes() -- List of already open backpacks.
- local main = Container.GetFirst() -- First open container is assumed to be main backpack (will be 0 if no container is open).
- local toOpen = #backpacks -- Number of backpacks we need to open (used to check success).
- local bps = {} -- A place to store the backpacks to open by container:UseItem(), if any. Why not always use :OpenChildren()? This way I can open bps by their relative position instead of id, so you don't have to worry about colours anymore.
- if main:ID() == 0 then -- If no backpack is open, we need to open main.
- if backpacks[1] ~= Self.Backpack().id then
- toOpen = toOpen + 1
- end
- repeat -- Open main backpack.
- wait(200, 600)
- until Self.OpenMainBackpack() > 0
- wait(500)
- main = Container.GetFirst()
- end
- if #backpacks > 0 then
- if type(backpacks[1]) == "table" then
- local bp, minimize = backpacks[1][1], backpacks[1][2]
- else
- local bp, minimize = backpacks[1], false
- end
- if type(bp) == "number" then
- if bp <= 20 then
- openByIndex(main, unpack(backpacks))
- else
- main:OpenChildren(unpack(backpacks))
- end
- else
- main:OpenChildren(unpack(backpacks))
- end
- end
- wait(400)
- if #open + toOpen == #Container.GetIndexes() then
- return true
- end
- return false
- end
- function openByIndex(parent, ...)
- local bps = {}
- -- Look for containers in main backpack.
- for i = 0, parent:ItemCount() do
- local thing = parent:GetItemData(i)
- if Item.isContainer(thing.id) then
- table.insert(bps, i)
- end
- end
- for index, bp in pairs({...}) do
- if type(bp) == "table" then
- local spot, minimize = bps[bp[1]], bp[2]
- else
- local spot, minimize = bps[bp], false
- end
- parent:UseItem(spot)
- if minimize then
- wait(200)
- Container.GetLast():Minimize()
- end
- end
- end
- function getOpenBackpacks()
- local indexes = Container.GetIndexes() -- Find index for all open backpacks
- local open = {} -- Create a place to store our open backpacks
- for i = 1, #indexes do -- Search all open backpacks
- tmpBP = Container.GetFromIndex(indexes[i])
- table.insert(open, tmpBP:ID()) -- Store this backpack
- end
- return open -- Return found backpacks
- end
- --[[
- resetBackpacks(reset)
- If reset is specified it will reset the number of backpacks specified. resetBackpacks(1) will reset the last opened backpack, resetBackpacks(2) the last 2 etc.
- Empty argument resets all open backpacks.
- Checks if all backpacks were reopened correctly. If not it will start over up to 3 times. If it failed after 3 tries it returns false (true if it succeeds).
- ]]
- function resetBackpacks(reset, minimize)
- Walker.Stop()
- local open = {} -- Create a table to hold backpack list
- local indexes = Container.GetIndexes() -- Get indexes of open backpacks.
- if reset then
- if reset > 0 and reset < #indexes then
- for i = (#indexes-reset)+1, #indexes do
- table.insert(open, indexes[i])
- end
- else
- for i = 2, #indexes do -- If 'reset' is above the number of open backpacks we should reset all.
- table.insert(open, indexes[i])
- end
- end
- else
- for i = 2, #indexes do -- If 'reset' is nil (empty argument) we should reset all backpacks.
- table.insert(open, indexes[i])
- end
- end
- local tries = 3 -- Give the script 3 tries to achieve a successful reset.
- local close = open
- if minimize then
- for i = 1, #open do
- open[i] = {open[i], true}
- end
- end
- repeat
- if reset then
- if type(reset) == "number" then
- if reset > 0 and reset < #indexes then
- closeBackpacks(unpack(close)) -- Close selected backpacks
- else
- Self.CloseContainers() -- Close all backpacks.
- end
- elseif type(reset) == "boolean" then
- minimize = reset
- end
- else
- Self.CloseContainers() -- Close all backpacks
- end
- wait(600, 800) -- Wait a little while
- local reopen = openBackpacks(unpack(open)) -- I store the return from openBackpacks, true if successfull, false otherwise
- if tries == 0 then -- Check how many tries the function has left
- print("BackpackReset failed!") -- Tell the user that reset has failed
- return false
- end
- tries = tries - 1 -- One try has been spent
- wait(100,200)
- until reopen -- If reopen is true it means all backpacks were opened successfully and function is done
- Walker.Start()
- return true
- end
- resetBackpacks(1, true)
Advertisement
Add Comment
Please, Sign In to add comment