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

Nugget Lever simple help to stack item.

rcb chief

New Member
Joined
Dec 23, 2008
Messages
53
Reaction score
0
I've got this script, which gives me a golden nugg each time I press a lever.
My question is: How can I make it so that whenever I buy a gold nugget it stacks with other gold nuggets. Simple as that.

Code:
  ----- Config -----
local config = {
        cost = 100, -- Price
        item_id = 2157, -- item

}

local name = getItemNameById(2157) -- Same as item_id above
----- End Config -----
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if doPlayerRemoveMoney(cid, config.cost) == TRUE then
                local bp = doPlayerAddItem(cid, config.item_id , 1)
                        doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
                        doSendAnimatedText(fromPosition, "Exchanged", TEXTCOLOR_RED)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You changed ".. name .."s for ".. config.cost .." gold.")
   
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. config.cost .." gold to change coins to  ".. name .."s.")
                end
        return TRUE
end
 
Lib:
Lua:
function getItemsInContainerById(container, itemid) -- Function By Kydrai
            local items = {}
            if isContainer(container) and getContainerSize(container) > 0 then
                            for slot=0, (getContainerSize(container)-1) do
                                            local item = getContainerItem(container, slot)
                                            if isContainer(item.uid) then
                                                            local itemsbag = getItemsInContainerById(item.uid, itemid)
                                                            for i=0, #itemsbag do
                                                                            table.insert(items, itemsbag[i])
                                                            end
                                            else
                                                            if itemid == item.itemid then
                                                                            table.insert(items, item.uid)
                                                            end
                                            end
                            end
            end
            return items
end
function doPlayerAddItemStacking(cid, itemid, quant) -- by mkalo
    local item = getItemsInContainerById(getPlayerSlotItem(cid, 3).uid, itemid)
    local piles = 0
    if #item > 0 then
            for i,x in pairs(item) do
                    if getThing(x).type < 100 then
                            local it = getThing(x)
                            doTransformItem(it.uid, itemid, it.type+quant)
                            if it.type+quant > 100 then
                                    doPlayerAddItem(cid, itemid, it.type+quant-100)
                            end
                    else
                           piles = piles+1
                    end
            end
    else
            return doPlayerAddItem(cid, itemid, quant)
    end
    if piles == #item then
            doPlayerAddItem(cid, itemid, quant)
    end
end


script

Lua:
  ----- Config -----
local config = {
        cost = 100, -- Price
        item_id = 2157, -- item

}

local name = getItemNameById(2157) -- Same as item_id above
----- End Config -----
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if doPlayerRemoveMoney(cid, config.cost) == TRUE then
        if isItemStackable(config.item_id) then
	doPlayerAddItemStacking(cid, config.item_id, 1)
	else
	doPlayerAddItem(cid, config.item_id,1)
	end
                        doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
                        doSendAnimatedText(fromPosition, "Exchanged", TEXTCOLOR_RED)
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You changed ".. name .."s for ".. config.cost .." gold.")
   
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. config.cost .." gold to change coins to  ".. name .."s.")
                end
        return TRUE
end
 
Back
Top