• 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 Send item to Player DP

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,857
Reaction score
96
Location
Brazil
Code:
doPlayerSendMailByName(getCreatureName(cid), new_item, getPlayerTown(cid))
This part of code is sending a letter instead of sending item, why?

Code:
local lettersUsedToGenerateHash = "AaBbCcDdEeFfGgHhIiJjKkLlMmOoPpQqRrSsTtUuVvWwXxYyZz"
math.randomseed(os.time()) -- required!
function generateSerial()
    local newSerial = "!"
    for k = 1, 10 do
        local l = math.random(1, string.len(lettersUsedToGenerateHash))
        newSerial = newSerial .. string.sub(lettersUsedToGenerateHash, l, l)
    end
    local newSerialInt  = math.random(899999) + 100000 -- this will return always same lenght
    newSerial = newSerial .. "-" .. os.time() .. "-" .. newSerialInt
    -- length: ![10 letters]-[10 numbers (unix date)]-[6 numbers]
    -- length = 29 [always!]
    return newSerial
end

local function doPlayerAddDepotItems(cid, items, town)
    if (not isPlayer(cid)) then
        error("Player not found")
    end
    local town = town or getPlayerTown(cid)

    local attritemid = doCreateItemEx(2596, 1)
    for item, count in pairs(items) do
        if (type(item) == "number") then
            local thing = doAddContainerItem(attritemid, item, count)
            doItemSetAttribute(thing, "description", "This item belongs to " .. getPlayerName(cid) .. ".")
            doItemSetAttribute(thing, "owner", getPlayerGUID(cid))
            doItemSetAttribute(thing, "aid", getPlayerGUID(cid)+10000)
            doItemSetAttribute(thing, "serial", generateSerial())
        elseif (type(item) == "string") then
            if getItemIdByName(item) then
                local thing = doAddContainerItem(attritemid, item, count)
                doItemSetAttribute(thing, "description", "This item belongs to " .. getPlayerName(cid) .. ".")
                doItemSetAttribute(thing, "owner", getPlayerGUID(cid))
                doItemSetAttribute(thing, "aid", getPlayerGUID(cid)+10000)
                doItemSetAttribute(thing, "serial", generateSerial())
            end
        else
            error("Undefinied type of item name")
        end
    end

    return doPlayerSendMailByName(getCreatureName(cid), attritemid, getPlayerTown(cid))
end

function onThink(interval, lastExecution, thinkInterval)

    local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")

        if(result:getID() ~= -1) then
            while(true) do
                cid = getCreatureByName(tostring(result:getDataString("player")))
                product = tonumber(result:getDataInt("product"))
                itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
                    if isPlayer(cid) then
                        local id = tonumber(itemr:getDataInt("item"))
                        local tid = tonumber(result:getDataInt("id"))
                        local count = tonumber(itemr:getDataInt("count"))
                        local tipe = tonumber(itemr:getDataInt("type"))
                        local productn = tostring(itemr:getDataString("name"))
                            if isInArray({5,8},tipe) then
                                if isPlayer(cid) then
                                    local received = doPlayerAddDepotItems(cid, {[id]=count})
                                    if received then
                                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
                                        db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
                                        doPlayerSave(cid)
                                    else
                                        doPlayerSendTextMessage(cid,19, "Report to a gamemaster..")
                                    end
                                else
                                    doPlayerSendTextMessage(cid,19, "Report to a gamemaster.")
                                end
                            elseif isInArray({6,7},tipe) then
                                    if tipe == 6 then
                                        bcap = 8
                                        bid = 1987
                                    elseif tipe == 7 then
                                        bcap = 20
                                        bid = 1988
                                    end
                                    if isItemRune(id) then
                                        count = 1
                                    end
                                    if isPlayer(cid) then
                                        local bag = doCreateItemEx(bid, 1)
                                            for i = 1,bcap do
                                                doAddContainerItem(bag, id, count)
                                            end
                                        received = doPlayerAddItemEx(cid, bag, true)
                                        if received then
                                            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
                                            db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
                                            doPlayerSave(cid)
                                        else
                                            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need a free slot on container to receive "..productn..".")
                                        end
                                    else
                                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need "..getItemWeightById(id, count).." of free capacity to receive "..productn..".")
                                    end
                            end
                    end
                itemr:free()
                if not(result:next()) then
                    break
                end
            end
            result:free()
        end
    return true
end
 

Similar threads

Back
Top