PDA

View Full Version : Selling Items.



Marshall011
12-17-2015, 01:08 PM
Hello,
I have a problem with one of my scripts. Bot collect few items to make my script more profitable. I want them to be sold during resuply. Everything goes fine until bot tries to sell item that was not looted in a session. It sells everything but sometimes it doesn't have a crossbow for example. Bot stays and there is an information below "You do not have this object". How to fix it?
My code:

elseif (labelName) == "Sell Items" then
Self.SayToNpc({"hi", "trade"}, 65)
wait(2000)
setWalkerEnabled(false)
Self.ShopSellAllItems(3275)
wait(1000, 1500)
Self.ShopSellAllItems(3305)
wait(1000, 1500)
Self.ShopSellAllItems(3425)
wait(1000, 1500)
Self.ShopSellAllItems(3349)
wait(1000, 1500)
Self.ShopSellAllItems(3351) -- item = ID przedmiotu, count = ile przedmiotów kupić / dokupić
wait(1000, 1500)
Self.SayToNpc({"bye"}, 65)
gotoLabel("Sold")
setWalkerEnabled(true)

shadowart
12-17-2015, 01:16 PM
That happens when you try to sell an item that you have in your equipment. If you don't have the item at all it will just be skipped.

You'll need to use a custom function (instead of Self.ShopSellAllItems) to get around this:

local function countInEquipment(item)
local count = 0

local id = Item.GetItemIDFromDualInput(item)
local slots = {Self.Head, Self.Armor, Self.Legs, Self.Feet, Self.Amulet, Self.Weapon, Self.Ring, Self.Shield, Self.Ammo}
for i = 1, #slots do
local slot = slots[i]()
if (slot.id == id) then
count = count + math.max(slot.count, 1)
end
end

return count
end

function sellAll(item)
local count = countInEquipment(item)
local sellableCount = Self.ShopGetItemSaleCount(item) - count
while sellableCount > 0 do
Self.ShopSellItem(item, sellableCount)
sellableCount = Self.ShopGetItemSaleCount(item) - count
end
end

Marshall011
12-17-2015, 01:43 PM
Good hint! I didn't know that the issue was because of my EQ. Ye that was the reason and thank you for help!