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

This spits out "cannot find container" [OTHire] 7.72

Xapafe

Member
Joined
Jul 22, 2013
Messages
83
Reaction score
6
Code:
-- Code structured by ***MatheusMkalo***, Emky, and Unlimited
function onUse(cid, item, fromPosition, itemEx, toPosition)

local unique = 9500 --Unique ID
local quest = 9500 --Usually same as unique or action.. but I added space for univerial creation
local action = 0 --Action ID

local bp = 1987 -- Backpack or bag id

local reward = 2175
local rewardAmount = 1

local reward2 = 2145
local reward2Amount = 2

local reward3 = 2148
local reward3Amount = 100

local rewardContainer = 1740 --something like chest(1740), box(1741 or other), or dead human(2317)




    if item.uid == (unique) then
        queststatus = getPlayerStorageValue(cid,quest)
        if queststatus == -1 then
            local item = doCreateItemEx(bp, 1)
            item_uid = doAddContainerItem(bag, reward, rewardAmount)
            item_uid = doAddContainerItem(bag, reward2, reward2Amount)
            item_uid = doAddContainerItem(bag, reward3, reward3Amount)
            if item then
                local ret = doPlayerAddItemEx(cid, item, false)
                if ret == RETURNVALUE_NOERROR then
                    setPlayerStorageValue(cid,quest, 1)
                    doPlayerSendTextMessage(cid,22,"You have found a "  .. getItemNameById(bp, 1) .. ".")
                elseif ret == RETURNVALUE_NOTENOUGHCAPACITY then
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have found a reward weighing " .. getItemWeightById(bp) + (getItemWeightById(reward) * rewardAmount) + (getItemWeightById(reward2) * reward2Amount) + (getItemWeightById(reward3) * reward3Amount) .. " oz. It is too heavy.")
                elseif ret == RETURNVALUE_NOTENOUGHROOM or ret == RETURNVALUE_CONTAINERNOTENOUGHROOM then
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You do not have enough space.')
                else
                    doPlayerSendDefaultCancel(cid, ret)
                end
            end
        else
            doPlayerSendTextMessage(cid,22,"The " .. getItemNameById(rewardContainer) .. " is empty.")
        end
    end
    return true
end

This is the part that's tossing the error.

Code:
local item = doCreateItemEx(bp, 1)
            item_uid = doAddContainerItem(bag, reward, rewardAmount)
            item_uid = doAddContainerItem(bag, reward2, reward2Amount)
            item_uid = doAddContainerItem(bag, reward3, reward3Amount)

I'm trying to attempt to put these items INTO this container then give it to the player, which will do one of three things. Give it to them, toss a cap error, or toss a space error.

Problem is, I can't get the multiple items in a container to work correctly at all. I'm just getting a empty bag.

Thanks guys!
 
Code:
-- Code structured by ***MatheusMkalo***, Emky, and Unlimited
function onUse(cid, item, fromPosition, itemEx, toPosition)

local unique = 9500 --Unique ID
local quest = 9500 --Usually same as unique or action.. but I added space for univerial creation
local action = 0 --Action ID

local bp = 1987 -- Backpack or bag id
local rewards = {
    {reward = 2175, rewardAmount = 1},
    {reward = 2145, rewardAmount = 2},
    {reward = 2148, rewardAmount = 100}
    }

local rewardContainer = 1740 --something like chest(1740), box(1741 or other), or dead human(2317)




    if item.uid == (unique) then
        queststatus = getPlayerStorageValue(cid,quest)
        if queststatus == -1 then
            local item = doCreateItemEx(bp, 1)
            local weight = getItemWeightById(bp)
            for i=1,#rewards,1 do
                doAddContainerItem(item, rewards[i].reward, rewards[i].rewardAmount)
                weight = weight + (getItemWeightById(rewards[i].reward) * rewards[i].rewardAmount)
            end
            weight = math.floor(weight*10)/10
            if item then
                local ret = doPlayerAddItemEx(cid, item, false)
                if ret == RETURNVALUE_NOERROR then
                    setPlayerStorageValue(cid,quest, 1)
                    doPlayerSendTextMessage(cid,22,"You have found a "  .. getItemNameById(bp, 1) .. ".")
                elseif ret == RETURNVALUE_NOTENOUGHCAPACITY then
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have found a reward weighing " ..weight.. " oz. It is too heavy.")
                elseif ret == RETURNVALUE_NOTENOUGHROOM or ret == RETURNVALUE_CONTAINERNOTENOUGHROOM then
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You do not have enough space.')
                else
                    doPlayerSendDefaultCancel(cid, ret)
                end
            end
        else
            doPlayerSendTextMessage(cid,22,"The " .. getItemNameById(rewardContainer) .. " is empty.")
        end
    end
    return true
end
 
Last edited:
Ohh does this line

for i=1,#rewards,1 do
doAddContainerItem(item, rewards.reward, rewards.rewardAmount)

cause it to keep adding until finished???
 
Thanks! I've been asking a ton of questions lately and I'm really trying to learn to script better. Thank you so much!!
 
Back
Top Bottom