• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

What's the function to replace getContainerCap

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hello, I was trying convert a code from 0.4 to 1.2 but I got stucked with theses two lines. Don't know what function to use on it.

Code:
if(getContainerCap(cid)) then
       doAddContainerItem(doPlayerAddItem(cid, potion.backpack, 1), potion.item, potion.ammount)
end

Thanks.
 
getContainerCap(cid) <- -> what is this function supposed to do?

Tell me what is the whole function meant to do?
 
I don't know what your old function do, but I guess this may help:
Code:
local bp = Container(cid)
if bp:getCapacity() > bp:getItemHoldingCount() then --bp:getSize() will do the trick too
    --add the item
end
 
getContainerCap(cid) <- -> what is this function supposed to do?

Tell me what is the whole function meant to do?

It suppost to be if you have cap then addcontainer (potion.backpack) and in this backpack with potion.item with potion.ammount

@Colors
and which function can I use to add the items at backpack?
 
Oh... So your function is checking if the player have cap left? The coded I posted above it checks if X container have free slots...
Anyway, you can add items to a container with the following:
Code:
container:addItem(itemId[, count/subType = 1[, index = INDEX_WHEREEVER[, flags = 0]]])
 
Oh... So your function is checking if the player have cap left? The coded I posted above it checks if X container have free slots...
Anyway, you can add items to a container with the following:
Code:
container:addItem(itemId[, count/subType = 1[, index = INDEX_WHEREEVER[, flags = 0]]])

Could you give me a example to how use it? I'm trying using it:
Code:
local container = player:addItem(potion.backpack)
if not container then
   return true
end

container:addItem(potion.item, potion.ammount)

Fully script:
Code:
local POTIONS = {
   [1515] = {cost = 400, backpack = 10519, item = 8704, ammount = 20}, -- small health potion
   [1516] = {cost = 900, backpack = 2000, item = 7618, ammount = 20}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local potion = POTIONS[item.actionid]
   if not potion then
     return true
   end

   local container = player:addItem(potion.backpack)
   if not container then
     return true
   end

   if(player:removeMoney(potion.cost)) then
     container:addItem(potion.item, potion.ammount)
     player:getPosition():sendMagicEffect(39)
   else
     player:sendCancelMessage("You need "..potion.cost.." gold coins for a backpack of 100x " .. ItemType(potion.item):getName() .. ".")
   end
   return true
end
 
Last edited:
You could do something along these lines to check whether the player has enough capacity or room before adding the item.
Code:
    local tmpContainer = Game.createItem(potion.backpack)
    if not tmpContainer then
        return true
    end

    tmpContainer:addItem(potion.item, potion.ammount) -- You can check if it's possible to add this item to the container as well (there are plenty of Item & Container methods to play around with)

    if player:addItemEx(tmpContainer) ~= RETURNVALUE_NOERROR then
        player:sendCancelMessage(player:getFreeCapacity() < tmpContainer:getWeight() and RETURNVALUE_NOTENOUGHCAPACITY or RETURNVALUE_NOTENOUGHROOM)
        return true
    end

    -- do something
 
@Ninja
Didn't understand how to fit into my script. Remove the money then give a backpack of fully item with charges 100.
Code:
local POTIONS = {
    [1515] = {cost = 400, backpack = 10519, item = 8704, amount = 2000}, -- small health potion
    [1516] = {cost = 900, backpack = 2000, item = 7618, amount = 2000}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local potion = POTIONS[item.actionid]
    if not potion then
        return true
    end

    if player:getMoney() < potion.cost then
        player:sendCancelMessage("You need "..potion.cost.." gold coins for a backpack of 100x " .. ItemType(potion.potion):getName() .. ".")
        return true
    end

    local tmpContainer = Game.createItem(potion.backpack)
    if not tmpContainer or not tmpContainer:isContainer() then
        return true
    end

    for i = 1, potion.amount do
        if not tmpContainer:addItem(potion.item) then
            break
        end
    end

    if player:addItemEx(tmpContainer) ~= RETURNVALUE_NOERROR then
        player:sendCancelMessage(player:getFreeCapacity() < tmpContainer:getWeight() and RETURNVALUE_NOTENOUGHCAPACITY or RETURNVALUE_NOTENOUGHROOM)
        return true
    end

    player:removeMoney(potion.cost)
    player:getPosition():sendMagicEffect(CONST_ME_SMALLCLOUDS)
    return true
end
 
Back
Top