• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Npc buy with backpack

-vG

New Member
Joined
Oct 18, 2018
Messages
39
Solutions
1
Reaction score
4
Location
Brazil
Hello people,
when buying rune pack he buys only 20
each packet being 100 runes how can I fix it?

TFS 0.3.7
version 8.60

lib -> npc.lua
Lua:
function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount, subType, ignoreCap, inBackpacks, backpack  = amount or 1, subType or 0, ignoreCap or false, inBackpacks or false, backpack or 1988

    local exhaustionInSeconds = 1
    local storage = 45814
    if(exhaustion.check(cid, storage) == true) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You cant buy it so fast.")
        return 0
    end
    exhaustion.set(cid, storage, exhaustionInSeconds)

    local ignoreCap = false
    local item, a = nil, 0
    if(inBackpacks) then
        local custom, stackable = 1, isItemStackable(itemid)
        if(stackable) then
            custom = math.max(1, subType)
            subType = amount
            amount = math.max(1, math.floor(amount / 100))
        end

        local container, b = doCreateItemEx(backpack, 1), 1
        for i = 1, amount * custom 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

                a = i
                if(amount > i) then
                    container = doCreateItemEx(backpack, 1)
                    b = b + 1
                end
            end
        end

        if(not stackable) then
            return a, b
        end

        return (a * subType / custom), b
    end

    if(isItemStackable(itemid)) then
        a = amount * math.max(1, subType)
        repeat
            local tmp = math.min(100, a)
            item = doCreateItemEx(itemid, tmp)
            if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
                return 0, 0
            end

            a = a - tmp
        until a == 0
        return amount, 0
    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
 
Back
Top