• 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!

TFS 0.X Check Backpack slots and player capacity (Already have working script)

Loiz

New Member
Joined
Jul 25, 2018
Messages
7
Solutions
1
Reaction score
0
I have this working action script, when i click the corpse on the ground it gives me an obsidian lance, and starts a quest on it.


Lua:
function onUse(cid)

       local queststatus = getPlayerStorageValue(cid,50125)
        if queststatus == -1 then
            local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
            if getContainerSize(bp.uid) == getContainerCap(bp.uid) then
                doPlayerSendTextMessage(cid,22,"You have no room")
            else
                if (getPlayerFreeCap(cid) >= 80) then
                doPlayerSendTextMessage(cid,22,"You have found a obsidian lance in the human hands.")
                doPlayerAddItem(cid, 2425, 1)
                setPlayerStorageValue(cid,50125,1)
                else
                doPlayerSendTextMessage(cid,22,"You have found a obsidian lance. Weighing 80.00 oz it is too heavy.")
                end
            end
        else
            doPlayerSendTextMessage(cid,22,"The dead human has nothing on.")
        end
    end


But when i have another bag inside, it keeps saying that i have no room avaible, what can i do? i need this working even if the bag are full, to put the item in the other bag.
 
Essentially, you want to check the cap first, then check if the item can be added to the player.

You can see me doing that here..

It boils down to this, for single items, like your script is doing.
Lua:
local reward = {
    itemid = 1111,
    amount = 1
}

if getPlayerFreeCap(cid) < getItemWeightById(reward.itemid, reward.amount) then
    -- no player capacity
    return true
end

local item = doCreateItemEx(reward.itemid, reward.amount)

if doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR then
    -- no player inventory space
    return true
end

-- item added successfully.
-- set storage value
 
Back
Top