Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CONFIG =
- {
- WAITTIME = 500, -- miliseconds to wait between each iteration
- BACKPACKS = -- list of backpacks to search for
- {
- ["mainBp"] = "brocade backpack",
- ["goldBP"] = "blue backpack",
- ["lootBP"] = "fur backpack",
- ["wormsBP"] = "golden backpack",
- ["purseBP"] = "beach backpack"
- },
- CHECKBP = "mainBp", -- backpack name to check for moving items
- USEGOLDBP = "goldBP", -- backpack name to use gold from
- WORMSID = 3492,
- TOTALWORMS = 500,
- ITEMS = -- items to be moved
- {
- [12731] = "lootBP", [3580] = "lootBP", [12736] = "lootBP", [12732] = "lootBP", [12735] = "lootBP", [12741] = "lootBP",
- [12733] = "lootBP", [12557] = "lootBP", [12807] = "lootBP", [13992] = "lootBP", [3492] = "wormsBP", [3043] = "goldBP",
- [3035] = "goldBP", [16087] = "purseBP", [5895] = "goldBP",
- }
- }
- function showError(text)
- alert()
- error(text)
- end
- STATES =
- {
- {
- name = "Check Backpacks",
- isReached = function(state)
- -- this state is reached as long as all backpacks are open
- if (not state.backpacks) then
- return false
- end
- for title, _ in pairs(CONFIG.BACKPACKS) do
- if (not state.backpacks[title]:isOpen()) then
- return false
- end
- end
- return true
- end,
- tryToReach = function(state)
- -- to reach this state, we must look to indentify all required backpacks
- state.backpacks = {}
- for title, bpName in pairs(CONFIG.BACKPACKS) do
- state.backpacks[title] = Container.GetByName(bpName)
- if (not state.backpacks[title]:isOpen()) then
- showError("Can't locate '" .. title .. "', " .. bpName .. " is not open!")
- end
- end
- end
- },
- {
- name = "Move Items",
- isReached = function(state)
- -- this state is reached as long as our main backpack is not almost full
- return (state.backpacks[CONFIG.CHECKBP]:Capacity() - state.backpacks[CONFIG.CHECKBP]:ItemCount() > 2)
- end,
- tryToReach = function(state)
- -- to reach this state, we must move items to the correct backpacks
- function moveItemToBackpack(fromBp, fromSpot, toBp, toBpTitle)
- if (toBp:Capacity() == toBp:ItemCount()) then -- bp is full, try to cascade
- if (not Item.isContainer(self:GetItemData(spot).id)) then
- showError("Backpack '" .. toBpTitle .. "' is full and no cascaded backpacks remain!")
- end
- toBp:UseItem(toBp:ItemCount() - 1, true)
- else -- no need to cascade, lets move
- fromBp:MoveItemToContainer(fromSpot, toBp:Index(), toBp:ItemCount())
- end
- end
- local mainBp = state.backpacks[CONFIG.CHECKBP]
- for spot = mainBp:ItemCount() - 1, 0, -1 do
- local checkItem = mainBp:GetItemData(spot)
- local toBpTitle = CONFIG.ITEMS[checkItem.id]
- if (toBpTitle) then
- moveItemToBackpack(mainBp, spot, state.backpacks[toBpTitle], toBpTitle)
- return
- end
- end
- showError("Main backpack is almost full, but no items can be moved!")
- end
- },
- {
- name = "Use Plats",
- isReached = function(state)
- -- return true if no stacks of 100 exist
- return true
- end,
- tryToReach = function(state)
- -- use a stack of 100
- end
- },
- {
- name = "Buy Worms",
- isReached = function(state)
- -- this state is reached as long as we have more than 0 worms
- local complete = (Self.ItemCount(WORMSID) > 0)
- state.wormsState = complete and 0 or state.wormsState
- return complete
- end,
- tryToReach = function(state)
- -- to reach this state, we buy some worms
- if (state.wormsState == 0) then
- Self.SayToNpc({'hi', 'trade'}, 70)
- else if (state.wormsState >= 3) then
- Self.ShopBuyItemsUpTo(WORMSID, CONFIG.TOTALWORMS)
- else if (state.wormsState >= 6) then
- showError("Failed to buy worms!")
- end
- state.wormsState = state.wormsState + 1
- end
- },
- {
- name = "Fish",
- isReached = function(state)
- -- always say this state isnt reached, so we will always do it when others are reached
- return false
- end,
- tryToReach = function(state)
- -- fish here
- end
- },
- }
- local stateData = {} -- this holds variables for the state machine
- while (true) do
- local stateNum = 1
- while (STATES[stateNum] and STATES[stateNum]:isReached(stateData)) do -- this loop locates the first state that is not "reached"
- stateNum = stateNum + 1
- end
- STATES[stateNum] and STATES[stateNum]:tryToReach(stateData) -- this tries to reach the unreached state
- wait(CONFIG.WAITTIME)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement