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

TFS 0.X Not working Shop System Globalevent

kikol

New Member
Joined
May 3, 2019
Messages
17
Reaction score
0
Hi, does anyone know what I need to change in this script to work properly? The script should send the purchased items in an SMS to depo.

Lua:
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) .. ".")
        elseif (type(item) == "string") then
            if getItemIdByName(item) then
                local thing = doAddContainerItem(attritemid, item, count)
                doItemSetAttribute(thing, "description", "This item belongs to " .. getPlayerName(cid) .. ".")
            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 z_ots_comunication WHERE `type` = 'login';")
    if (result and result:getID() ~= -1) then
        while(true) do
            local id = tonumber(result:getDataInt("id"))
            local action = tostring(result:getDataString("action"))
            local delete = tonumber(result:getDataInt("delete_it"))
            local cid = getCreatureByName(tostring(result:getDataString("name")))
            local id = tonumber(result:getDataInt("id"))
             local itemr = db.getResult("SELECT * FROM z_shop_offer WHERE `id` = "..id..";")
            if isPlayer(cid) then
                local itemtogive_id = tonumber(result:getDataInt("param1"))
                local itemtogive_count = tonumber(result:getDataInt("param2"))
                local container_id = tonumber(result:getDataInt("param3"))
                local container_count = tonumber(result:getDataInt("param4"))
                local add_item_type = tostring(result:getDataString("param5"))
                local add_item_name = tostring(result:getDataString("param6"))
                            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 "..itemtogive_id.." in depot of your hometown.")
                                        db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
                                        db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
                                        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 depo.")
                                            db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
                                            db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
                                            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


The error he receives in console:
[12:31:36.661] [Error - GlobalEvent Interface]
[12:31:36.676] data/globalevents/scripts/shop.lua:eek:nThink
[12:31:36.676] Description:
[12:31:36.676] data/lib/004-database.lua:100: [Result:free] Result not set!
[12:31:36.692] stack traceback:
[12:31:36.692] [C]: in function 'error'
[12:31:36.708] data/lib/004-database.lua:100: in function 'free'
[12:31:36.739] data/globalevents/scripts/shop.lua:87: in function <data/globalevents/scripts/shop.lua:25>
[12:31:36.973] [Error - GlobalEvents::think] Couldn't execute event: shop
 
Back
Top