Npc selling items/runes in backpack doesn't work

dami1310

◄ Me ►
Joined
Jan 27, 2013
Messages
398
Reaction score
300
Location
Poland
As in the title. I want to make npc sell potions and runes in backpacks possible.
Im using tfs 0.4, to be specific:
this one.
Here is my npc.lua:
Npc:
Npc script:

I tried different kind of solutions and files, but couldnt find the right one.

I somehow managed to get the right amounts of stackable and nonstackable items, but it's "fake" and for stackable items the price for bp is the same as for 100 :v
PHP:
function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount = amount or 1
    local subType = subType or 1
    local ignoreCap = ignoreCap and true or false
 
    local a = 0
    if(inBackpacks) then
        if(isItemStackable(itemid)) then
            amount = amount * 20
        end
        local container = doCreateItemEx(backpack, 1)
        local b = 1
        for i = 1, amount do
            item = doAddContainerItem(container, itemid, subType)
            if(itemid == ITEM_PARCEL) then
                doAddContainerItem(item, ITEM_LABEL)
            end
 
            if(isInArray({(getContainerCapById(backpack) * b), amount}, i)) then
                if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
                    b = b - 1
                    break
                end
 
                if(isItemStackable(itemid)) then
                    i = i * 100
                end
                a = i
                if(amount > i) then
                    container = doCreateItemEx(backpack, 1)
                    b = b + 1
                end
            end
        end
 
        return a, b
    end
 
    for i = 1, amount do
        item = doCreateItemEx(itemid, subType)
        if(itemid == ITEM_PARCEL) then
            doAddContainerItem(item, ITEM_LABEL)
        end
 
        if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
            break
        end
 
        a = i
    end
 
    return a, 0
end
 
Last edited:
Top