Log in

View Full Version : XenoBot Bug - Open [Windows 7 x86] Self.DropItem return value



damii211
09-09-2015, 08:01 PM
Bug ReportOperating System:
Windows 7 x86 Short Description:
Self.DropItem return value Behaviors: Loss of or impaired functionality

Indepth Description:
Function Self.DropItem should return true or false as comment above this function says:
-- @return boolean true or false
However, this function never returns false and it returns true only if we specify an amount of items to drop and this amount is lower than items count. Otherwise it doesn't return anything at all.

Things to do to reproduce this behaviour:
I have a backpack with 4 gp and nothing else inside it. I execute this script:
print(type(Self.DropItem(Self.Position().x + 1, Self.Position().y, Self.Position().z, 3031, 1)))
It drops 1 gold coin and prints "boolean". Then I execute this script:
print(type(Self.DropItem(Self.Position().x + 1, Self.Position().y, Self.Position().z, 3031)))
It drops all the gold coins I have and then an error occurs because "type" expects a value and function doesn't return anything

Forgive me if I misunderstood the function's code and it works as expected

anoyn
09-09-2015, 09:37 PM
Yup


function Self.DropItem(x, y, z, itemid, count)
itemid = Item.GetItemIDFromDualInput(itemid)
local cont = Container.GetFirst()
count = count or -1 -- either all or some
while (cont:isOpen() and (count > 0 or count == -1)) do
local offset = 0
for spot = 0, cont:ItemCount() do
local item = cont:GetItemData(spot - offset)
if (item.id == itemid) then
local compareCount = cont:CountItemsOfID(itemid) -- save the current count of this itemid to compare later
local toMove = math.min((count ~= -1) and count or 100, item.count) -- move either the count or the itemcount whichever is lower (if count is -1 then try 100)
cont:MoveItemToGround(spot - offset, x, y, z, toMove)
wait(300) -- this is different
if (compareCount > cont:CountItemsOfID(itemid)) then -- previous count was higher, that means we were successful
if(toMove == item.count)then -- if the full stack was moved, offset
offset = offset + 1
else
return true -- only part of the stack was needed, we're done.
end
if (count ~= -1) then -- if there was a specified limit, we need to honor it.
count = (count - toMove)
end
end
end
end
cont = cont:GetNext()
end
end