• 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 -Otserv 7.4 - 7.72 - error in console

Sebastian Ching

New Member
Joined
Dec 26, 2007
Messages
314
Reaction score
4
Location
Rio grande, rs, Brazil
Greetings, i am using this script, it works perfectly in game, but it shows an error in the console that does not affect the operation, this script is to buy items by pressing the lever, can you help me?
Thank you in advance

Lua:
-- Written by Ldrozd with Tairen's advice; do not delete it, you arent the creator
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local potion = {
        [9020] = {id = 2268, bp = 2268, cost = 300, anim = 30},

    }
      
                local actuallPotion = potion[item.actionid]
        local weight = getItemWeightById(actuallPotion.id, 20) + getItemWeightById(actuallPotion.bp, 1)                   
        if(getPlayerFreeCap(cid) >= weight) then
            if getPlayerMoney(cid) >= actuallPotion.cost then
    local bp = doCreateItemEx(cid, actuallPotion.bp, 0)
                 doAddContainerItem(bp, actuallPotion.id, 20)
                    if(doPlayerAddItemEx(cid, bp) ~= RETURNVALUE_NOERROR) then
                        doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You need more space in your container.")
                    else
                        doPlayerRemoveMoney(cid, actuallPotion.cost)
                        doSendMagicEffect(toPosition, actuallPotion.anim)
                        doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You have bought a "..getItemNameById(actuallPotion.id).."s for "..actuallPotion.cost.." gold coins.")
                    end
            else
                doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You need "..actuallPotion.cost.." gold coins to buy these potions.")
            end
        else
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You need at least "..math.ceil(weight).." oz to buy this item.")
        end
          
            if item.itemid == 1945 then
                doTransformItem(item.uid, item.itemid+1)
            elseif item.itemid == 1946 then
                doTransformItem(item.uid, item.itemid-1)
            else
                return true
            end                   
return true
end
 
Test it. No Container Error!
Lua:
    local list = { {3191, 2, 10}, {3160, 1, 10}  }
    local container = player:addItem(2854, 1)

    for i = 1, #list do
        local itemid = list[i][1]
        local charge = list[i][2]
        local count = list[i][3]
        if not ItemType(itemid):isStackable() then
            for c = 1, count do
                container:addItem(itemid, charge)
            end
        else
            container:addItem(itemid, charge)
        end
    end
    return true

SERVER ID GFB 3191, UH 3160
Backpack with 10 uh 1x and 10 gfb 2x!
 
thanks for answer, but what if i need to buy any random item without backpack?
thanks in advance
Lua:
function onUse(player, item, fromPosition, target, toPosition)
   
    -- config list {0 to without container item or BackpackID, itemid, charge, count}
    -- Ex: 10 gfb 2x | backpack with 10 uh 1x | 2 royal helmet | 1 ice rapier 3x.
    -- {0, 3191, 2, 10}, {2854, 3160, 1, 10}, {0, 3392, 1, 2}, {0, 3284, 3, 1}}

    local list = { {0, 3191, 2, 10}, {2854, 3160, 1, 10}, {0, 3392, 1, 2},  {0, 3284, 3, 1}}

    for i = 1, #list do
        local container = player:addItem(list[i][1], 1)
        local itemid = list[i][2]
        local charge = list[i][3]
        local count = list[i][4]

        if container then
            if not ItemType(itemid):isStackable() then
                for c = 1, count do
                    container:addItem(itemid, charge)
                end
            else
                container:addItem(itemid, charge)
            end
        else
            for c = 1, count do
                player:addItem(itemid, charge)
            end
        end
    end
    return true
end
 
Last edited:
Back
Top