Everyone who has never used our Bots before, can test each one for 2 days without any limitation.
The trial is given automatically when you login on the Bot, but in some cases it wouldn't work (security reasons).
If this happens, send me a private message and i will be checking the failed trials manually and adding it for those who didn't get it.
We are looking for resellers who may accept payment methods different from ours, including classictibia's cash, realesta's cash, mastercores' cash, etc. Interested? Click here at anytime.



Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check if BP empty
#1
Hiya, I want to make a refiller that goes refill when it counts bps of mana vials(using itemcount(purpleBPid) for this, but for this I need it to remove empty BP's

What's the easiest way of checking for an empty BP? is there a way to check cap of an object?
Reply

#2
Hello.

You could try to use contextmenu() to use "look" then check its weight based on the message that shows up, but not easy to use because it's based on pixels and currently there's no alternative for containers, which I may add in future.
So I recommend you to use:
1. openitem() to open a backpack
2. itemcount or getcontainer() to check if there's items inside it.
3. higherwindow() to back to previous container.

Example of code that you could use if you have a single backpack with 20 bps inside:
local Backpack = 'red backpack' -- Backpack that has vial bps inside.

local flag = true
while flag do
    flag = false

    local container = getcontainer(Backpack)
    if container.usedslots > 0 then
        for _, item in ipairs(container.items) do
            if itemhasflags(item.id, 4) then
                local emptyBackpack = false
                openitemslot(item.index, container.index, false)
                wait(1000)
                container = getcontainer(container.index)
                if container.usedslots == 0 then
                    emptyBackpack = true
                end
                higherwindow(container.index)
                wait(1000)
                container = getcontainer(container.index)
                if emptyBackpack then
                    moveitemsslot(item.index, container.index, ground(posx(), posy(), posz()))
                    wait(1000)
                    flag = true
                end
                break
            end
        end
    end
end
Reply

#3
Hey, First of all thanks a lot for this.
I tried modifying the script to keep the BP open if it's not empty and wait for it to be empty by using a goto statement. I'm not familiar with LUA so I was using some guide 
|Only Registered members can see download links. | Click here to buy subscription or here to register.
. Is the version of LUA the bot uses too old? or am I doing something wrong? I get this error:

05:37:08 - LUA Script -> bpdropper: 13: '<name>' expected near ':'

local flag = true
while flag do
    flag = false

    local container = getcontainer(Backpack)
    if container.usedslots > 0 then
        for _, item in ipairs(container.items) do
            if itemhasflags(item.id, 4) then
                local emptyBackpack = false
                openitemslot(item.index, container.index, false)
                wait(1000)
                container = getcontainer(container.index)
                :: checkagain ::
                if container.usedslots == 0 then
                    emptyBackpack = true
                else
                    wait(2000)
                    goto checkagain
                end
                higherwindow(container.index)
                wait(1000)
                container = getcontainer(container.index)
                if emptyBackpack then
                    moveitemsslot(item.index, container.index, ground(posx(), posy(), posz()))
                    wait(1000)
                    flag = true
                end
                break
            end
        end
    end
end
Reply

#4
|Only Registered members can see download links. | Click here to buy subscription or here to register.

Yes, it's LUA 5.1, so "goto" statement is not available. You will need to use while loop in this case with a boolean flag for example, pretty much like i did in this same script.

Notice that ":: checkagain ::" would need to be a line above, before "container = getcontainer(container.index)"
                wait(1000)
                :: checkagain ::
                container = getcontainer(container.index)
                if container.usedslots == 0 then
                wait(1000)
                container = getcontainer(container.index)
                :: checkagain ::
                if container.usedslots == 0 then[/code]

What will you do after keeping the bp open? I mean, will the script exits when a not empty bp is found?
Reply

#5
|Only Registered members can see download links. | Click here to buy subscription or here to register.
 I basically want to wait 20-30 seconds and check again if this BP is empty. If it is, close it and drop it, if not wait 20-30 sec and return to the point it checks. I will try work something out with the while loop
Reply

#6
This is the solution I came up with for dropping empty mana and UH bp's. It checks the first of each BP. It's kinda messy and inefficient but works. I'm gonna post it here incase anyone wants to use it/modify it

It relies heavily on being able to use autoloot as the open BP's get's messed with often

local flag = true

local manaBP = "purple backpack"
local uhBP = "blue backpack"

if getcontainer("grey backpack").index == -1 then
    openitem("grey backpack",'back')
end
if getcontainer(manaBP).index ~= -1 then
    closewindow(manaBP)
end
if getcontainer(uhBP).index ~= -1 then
    closewindow(uhBP)
end


while flag do
    flag = false

    local container = getcontainer("grey backpack")
    if container.usedslots > 0 then
    local PBPChecked = false
    local BBPChecked = false
        for _, item in ipairs(container.items) do
            if PBPChecked and BBPChecked == true then
                break
            end
            print((item.name == manaBP or item.name == uhBP))
            if itemhasflags(item.id, 4) and (item.name == manaBP or item.name == uhBP) and (PBPChecked == false or item.name ~= manaBP) and (BBPChecked == false or item.name ~="blue backpack")  then
                setsettings("Persistents/refillcheck/Enabled", false)
                local emptyBackpack = false
                openitemslot(item.index, container.index, false)
                wait(1000)
                container = getcontainer(container.index)
                if container.usedslots == 0 then
                    emptyBackpack = true
                    wait(1000)
                end
                if item.name == manaBP then
                    PBPChecked = true
                elseif item.name == uhBP then
                    BBPChecked = true
                end
                higherwindow(container.index)
                wait(1000)
                container = getcontainer(container.index)

                if emptyBackpack then
                    moveitemsslot(item.index, container.index, ground(posx(), posy(), posz()))
                    wait(1000)
                    flag = true
                end
                setsettings("Persistents/refillcheck/Enabled", true)
            end
        end
    end
end
 I use this together with refillcheck which checks if there's enough UH and ManaBp's as well as keeps the loot and main BP open


local manaBP = "purple backpack"
local uhBP = "blue backpack"
local lootBP = "brown bag"
local mainBP = "grey backpack"


if getcontainer(mainBP).index == -1 then
    openitem(mainBP,'back')
end

if getcontainer(lootBP).index == -1 then
    openitem(lootBP, mainBP)
    wait(1000)
    openitem(mainBP,'back')

end

if itemcount(manaBP) < 3 or itemcount(uhBP) < 2 then
    gotolabel("refill")
    wait(60000)
end
Reply

#7
Hiya I was wondering what this line does
itemhasflags(item.id, 4)
Reply

#8
|Only Registered members can see download links. | Click here to buy subscription or here to register.
Check if item id has a specific flag. 4 is the container's flag.
You can retrieve the item flags using itemflags(number itemId) function, example with gold coin:
print(itemflags(3031))
Reply

#9
Hey I have  a problem. I modified this script to check if BPs which should only have fluids/runes have other BP's in them, and if so move it to where it should be(into mainBP, supply BP or second supplyBP).

It should only check purple or blue backpacks, since they're the ones which contain pots and runes, however sometimes if a BP closes somewhere, or it fails to open the purple/blue backpack(due to player action or something else) it starts moving BP's from a BP it shouldn't. How it is this possible if I'm using an if statement to check if the BP being moved from is either a purple BP or blue BP.

The script is a mess  and I've been trying to fix it for several hours now so I'm not sure if you'll be able to help but I would be super grateful if you did. THanks.
here's a GIF of the incorrect behaviour
|Only Registered members can see download links. | Click here to buy subscription or here to register.

here's what should happen I guess
 
|Only Registered members can see download links. | Click here to buy subscription or here to register.

local flag = true

local manaBP = "purple backpack"
local uhBP = "blue backpack"
local gfbBP = "red backpack"
local lootBP = "fur backpack"
local mainBP = "grey backpack"
local suppBP = "golden backpack"
local suppBP2 = "yellow backpack"



while flag do
    flag = false

    if getcontainer(manaBP).index ~= -1 then
        closewindow(manaBP)
        wait(200)
    end

    if getcontainer(uhBP).index ~= -1 then
        closewindow(uhBP)
        wait(200)
    end

    if getcontainer(gfbBP).index ~= -1 then
        closewindow(gfbBP)
        wait(200)
    end

    if getcontainer(mainBP).index == -1 then
        openitem(mainBP,'back')
        wait(200)
    end

    if getcontainer(suppBP).index == -1 then
        openitem(suppBP, mainBP)
        wait(300)
        if getcontainer(mainBP).index == -1 then
            openitem(mainBP,'back')
            wait(200)
        end
    end

    if getcontainer(suppBP2).index == -1 then
        openitem(suppBP2, mainBP)
        wait(300)
        if getcontainer(mainBP).index == -1 then
            openitem(mainBP,'back')
            wait(200)
        end
    end



    if getcontainer(lootBP).index == -1 then
        openitem(lootBP, mainBP)
        wait(300)
        if getcontainer(mainBP).index == -1 then
            openitem(mainBP,'back')
            wait(200)
        end
    end



    local allopenbps = getcontainers()

    setsettings("Persistents/refillcheck/Enabled", false)
    for _, openbp in ipairs(allopenbps) do
        local container = openbp
        if container.usedslots > 0 then
            local PBPChecked = false
            local BBPChecked = false
            local GFBChecked = true
            for _, item in ipairs(container.items) do

                if container.name ~= mainBP and (item.name == suppBP or item.name == suppBP2 or item.name == lootBP) then
                    moveitemsslot(item.index, container.index, mainBP)
                end

                if itemhasflags(item.id, 4) and (item.name == manaBP or item.name == uhBP or item.name == gfbBP) and (PBPChecked == false or item.name ~= manaBP) and (BBPChecked == false or item.name ~=uhBP) and (GFBChecked == false or item.name ~= gfbBP) then

                    local emptyBackpack = false
                    print("container checked for empty1:", container)
                    openitemslot(item.index, container.index, false)
                    wait(300)
                    container = getcontainer(container.index)
                    print("container checked for empty2:", container)
                    if (container.name ~= suppBP or container.name ~= suppBP2 or container.name ~= mainBP) == true then
                        for _, fluids in ipairs(container.items) do
                            if (fluids.name == manaBP or fluids.name == uhBP or fluids.name == gfbBP) == true then
                                local moved = false
                                print('moving', fluids.name, "from", container.name)
                                local mainCont = getcontainer(mainBP)
                                local suppCont = getcontainer(suppBP)
                                local suppCont2 = getcontainer(suppBP2)
                                print(mainCont.open, mainCont.usedslots)
                                print(suppCont.open, mainCont.usedslots)
                                wait(200)
                                if mainCont.open == true and mainCont.usedslots ~= 20 then
                                    print('movingtomainbp', fluids.name)
                                    moveitems(fluids.name, 'back', container.name)
                                    moved = true
                                end
                                wait(200)
                                print(suppCont.open, suppCont.usedslots, moved)
                                if suppCont.open == true and suppCont.usedslots ~= 20 and moved == false then
                                    print('movingtoSuppbp', fluids.name)   
                                    moveitems(fluids.name, suppBP, container.name)
                                    moved = true
                                end
                                wait(200)
                                if suppCont2.open == true and suppCont2.usedslots ~= 20 and moved == false then
                                    print('movingtoSuppbp2', fluids.name) 
                                    moveitems(fluids.name, suppBP2, container.name)
                                end
                                wait(500)
                            end
                            if fluids.name == "platinum coin" or fluids.name == "gold coin" then
                                moveitems(fluids.name, lootBP, container.name)
                            end
                         
                        end
                    end
                   
                   
                    if container.usedslots == 0 then
                        emptyBackpack = true
                        wait(300)
                    end
                    if item.name == manaBP then
                        PBPChecked = true
                    elseif item.name == uhBP then
                        BBPChecked = true
                    elseif item.name == gfbBP then
                        GFBChecked = true
                    end
                    higherwindow(container.index)
                    wait(300)
                    container = getcontainer(container.index)

                    if emptyBackpack then
                        moveitemsslot(item.index, container.index, ground(posx(), posy(), posz()))
                        wait(300)
                        flag = true
                    end
                end
            end
        end
    end
    setsettings("Persistents/refillcheck/Enabled", true)
end


the relevant part of the code is this I guess

                    openitemslot(item.index, container.index, false)
                    wait(300)
                    container = getcontainer(container.index)
                    print("container checked for empty2:", container)
                    if (container.name ~= suppBP or container.name ~= suppBP2 or container.name ~= mainBP) == true then
                        for _, fluids in ipairs(container.items) do
                            if (fluids.name == manaBP or fluids.name == uhBP or fluids.name == gfbBP) == true then
                                local moved = false
                                print('moving', fluids.name, "from", container.name)
                                local mainCont = getcontainer(mainBP)
                                local suppCont = getcontainer(suppBP)
                                local suppCont2 = getcontainer(suppBP2)
                                print(mainCont.open, mainCont.usedslots)
                                print(suppCont.open, mainCont.usedslots)
                                wait(200)
                                if mainCont.open == true and mainCont.usedslots ~= 20 then
                                    print('movingtomainbp', fluids.name)
                                    moveitems(fluids.name, 'back', container.name)
                                    moved = true
                                end
                                wait(200)
                                print(suppCont.open, suppCont.usedslots, moved)
                                if suppCont.open == true and suppCont.usedslots ~= 20 and moved == false then
                                    print('movingtoSuppbp', fluids.name)   
                                    moveitems(fluids.name, suppBP, container.name)
                                    moved = true
                                end
                                wait(200)
                                if suppCont2.open == true and suppCont2.usedslots ~= 20 and moved == false then
                                    print('movingtoSuppbp2', fluids.name) 
                                    moveitems(fluids.name, suppBP2, container.name)
                                end
                                wait(500)
                            end
                            if fluids.name == "platinum coin" or fluids.name == "gold coin" then
                                moveitems(fluids.name, lootBP, container.name)
                            end
                         
                        end
                    end


I just realised in my IF statement it should've been container.name ~= manaBP AND container.name ~= ... instead of an OR. Sorry for the bother
Reply

#10
Do you still need help? I'm bit confused as you edited the post and add apologizes...

Anyway... I haven't tested the code yet, but few lines caught my attention, which may cause problems but I'm not sure because I haven't tested the code.
The lines that you use moveitemsslot and openitemslot functions. Both use index for the ITEM slot, which can be changed during the iteration. For example: You have 3 items in your bp, if you move the first item (index #0), the second item (index #1) will no longer be index #1, but index #0.

So if you move an item anywhere in your code and then use moveitemsslot or openitemslot without updating the container variable (or updating the items' index manually), the index of the other items will be outdated.

To avoid problems with this, you can:
1. Update each time you move an item, so if you are in the middle of an iteration of a container's items, you should either stop iteration, update the container and run the iteration again;
2. Reverse iteration (starting from the last item and go first one). In this case, moving the last item will not affect the index of the previous one, and so on.

I don't know if it could be a problem, because I'm not an expert in LUA, but you are updating the container variable while iterating "container.items". Maybe creating a new container variable after openitemslot instead of overriding it in the middle of its iteration? (line 88 i think)
Reply



Forum Jump:



Forum software by © MyBB Theme © iAndrew 2016