• 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 help auctionsystem GetItemIdByName

miguelshta

Member
Joined
Mar 21, 2009
Messages
351
Solutions
1
Reaction score
13
Location
Toronto, Canada
hello i'm receiving this error im using tfs 0.4_svn tibia 7.72
Lua:
[16:30:45.619] [Error - TalkAction Interface]
[16:30:45.619] data/talkactions/scripts/auctionsystem.lua:onSay
[16:30:45.634] Description:
[16:30:45.634] (LuaInterface::luaGetItemIdByName) Item not found

and here is my auction talkaction script:

Lua:
--[[
        Offline player to player item trader (Auction System) by vDk
                Script version: 1.2a [ -- FIXED CLONE ITEMS BUG -- ]
]]--
local config = {
        levelRequiredToAdd = 1,
        maxOffersPerPlayer = 5,
        SendOffersOnlyInPZ = true,
        blocked_items = {2165, 2152, 2148, 2160, 2166, 2167, 2168, 2169, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2343, 2433, 2640, 6132, 6300, 6301, 9932, 9933}
        }
function onSay(cid, words, param, channel)
        if(param == '') then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
                return true
        end
 
        local t = string.explode(param, ",")
        if(t[1] == "add") then
                if((not t[2]) or (not t[3]) or (not t[4])) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
                        return true
                end         

                if(not tonumber(t[3]) or (not tonumber(t[4]))) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
                        return true
                end
 
                if(string.len(t[3]) > 7 or (string.len(t[4]) > 3)) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
                        return true
                end
 
                local item = getItemIdByName(t[2], false)
                if(not item) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.")
                        return true
                end
 
                if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
                        return true
                end
 
                if(getPlayerVocation(cid) == 0) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have the profession to do that action!")
                        return true
                end

                if(isInArray(config.blocked_items, item)) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
                        return true
                end
 
                if(getPlayerItemCount(cid, item) < (tonumber(t[4]))) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you don't have this item(s).")
                        return true
                end
 
                local check = db.getResult("SELECT `id` FROM `auction_system` WHERE `player` = " .. getPlayerGUID(cid) .. ";")
                if(check:getID() == -1) then
                elseif(check:getRows(true) >= config.maxOffersPerPlayer) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max. " .. config.maxOffersPerPlayer .. ")")
                        return true
                end
 
                if(config.SendOffersOnlyInPZ) then   
                        if(not getTilePzInfo(getPlayerPosition(cid))) then
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you add offert to database.")
                                return true
                        end
                end
 
                if(tonumber(t[4]) < 1 or (tonumber(t[3]) < 1)) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
                        return true
                end
 
                local itemcount, costgp = math.floor(t[4]), math.floor(t[3])
                doPlayerRemoveItem(cid, item, itemcount)
                db.executeQuery("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`) VALUES (" .. getPlayerGUID(cid) .. ", \"" .. t[2] .. "\", " .. getItemIdByName(t[2]) .. ", " .. itemcount .. ", " .. costgp ..", " .. os.time() .. ")")
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. t[2] .." for " .. costgp .. " gps to offers database.")
        end
 
        if(t[1] == "buy") then
                if(not tonumber(t[2])) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
                        return true
                end
 
                local buy = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")
                if(buy:getID() ~= -1) then
                        if(getPlayerMoney(cid) < buy:getDataInt("cost")) then
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enoguh GP.")
                                buy:free()
                                return true
                        end
 
                        if(getPlayerName(cid) == getPlayerNameByGUID(buy:getDataInt("player"))) then
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can't buy your own items.")
                                buy:free()
                                return true
                        end
 
                        if(getPlayerFreeCap(cid) < getItemWeightById(buy:getDataInt("item_id"), buy:getDataInt("count")))then
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You try to buy a " .. buy:getDataString("item_name") .. ". It weight " .. getItemWeightById(buy:getDataInt("item_id"), buy:getDataInt("count")) .. " cap oz. and you have only " .. getPlayerFreeCap(cid) .. " oz. free capacity. Put some items to depot and try again.")
                                buy:free()
                                return true
                        end

                        if(getPlayerVocation(cid) == 0) then
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have the profession to do that action!")
                                return true
                        end
 
                        if(isItemStackable((buy:getDataString("item_id")))) then
                                doPlayerAddItem(cid, buy:getDataString("item_id"), buy:getDataInt("count"))
                        else
                                for i = 1, buy:getDataInt("count") do
                                        doPlayerAddItem(cid, buy:getDataString("item_id"), 1)
                                end
                        end
 
                        doPlayerRemoveMoney(cid, buy:getDataInt("cost"))
                        db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. buy:getDataInt("count") .. " ".. buy:getDataString("item_name") .. " for " .. buy:getDataInt("cost") .. " gps!")
                        db.executeQuery("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")
                        buy:free()
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
                end
        end
 
        if(t[1] == "remove") then
                if((not tonumber(t[2]))) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
                        return true
                end
 
                                if(config.SendOffersOnlyInPZ) then   
                                        if(not getTilePzInfo(getPlayerPosition(cid))) then
                                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you remove offerts from database.")
                                                return true
                                        end
                end
 
                local delete = db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (tonumber(t[2])) .. ";")       
                if(delete:getID() ~= -1) then
                        if(getPlayerGUID(cid) == delete:getDataInt("player")) then
                                db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. t[2] .. ";")
                                if(isItemStackable(delete:getDataString("item_id"))) then
                                        doPlayerAddItem(cid, delete:getDataString("item_id"), delete:getDataInt("count"))
                                else
                                        for i = 1, delete:getDataInt("count") do
                                                doPlayerAddItem(cid, delete:getDataString("item_id"), 1)
                                        end
                                end
 
                                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your offert has been deleted from offerts database.")
                        else
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This is not your offert!")
                        end
                delete:free()
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
                end
        end
 
        if(t[1] == "withdraw") then
                local balance = db.getResult("SELECT `auction_balance` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. ";")
                if(balance:getDataInt("auction_balance") < 1) then
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have money on your auction balance.")
                        balance:free()
                        return true
                end
 
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You got " .. balance:getDataInt("auction_balance") .. " gps from auction system!")
                doPlayerAddMoney(cid, balance:getDataInt("auction_balance"))
                db.executeQuery("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. getPlayerGUID(cid) .. ";")
                balance:free()
        end
        return true
end

it is from this post
 
Solution
Alright, so this may be a problem with your server source code / binary. I had a similar problem.

Basically luaGetItemIdByName ends up not working correctly in certain releases.

make this change around ~line 130
Diff:
-        local item = getItemIdByName(t[2], false)
+        local item = getItemIdByName(t[2])

and see if that makes the error go away.
I recall you haven't finished with this thread yet. If there is a problem with the script, tell me. Or mark it as best answer, because that was a pain in the ass to get completely working.
 
Lua:
--[[
        Offline player to player item trader (Auction System) by vDk
                Script version: 1.3 [ -- FIXED CLONE ITEMS BUG -- ]
                    ~~ Lessaire best practices patch ~~
]]--

local config = {
    levelRequiredToAdd = 1,
    maxOffersPerPlayer = 5,
    sendOffersOnlyInPZ = true,
    blocked_items = {2165, 2152, 2148, 2160, 2166, 2167, 2168, 2169, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2343, 2433, 2640, 6132, 6300, 6301, 9932, 9933}
}

function onSay(cid, words, param, channel)
    local messages = {
        cparam     = "This command requires action param: add buy remove withdraw",
        aparam     = "This action requires params: item, cost, count.",
        unknown    = "Unrecognized action path for this command. Available actions: add buy remove withdraw",

        badItem    = "Item with such name does not exist.",
        ownOffer   = "Sorry, you can't buy your own items.",
        dontHave   = "Sorry, you don't have this item(s).",
        notYours   = "This is not your offer!",
        contraband = "This item is blocked.",
        invalid    = "Wrong ID.",
        youPoor    = "You don't have enough GP.",
        noSales    = "You don't have money on your auction balance.",
        rookie     = "You don't have the profession to do that action!",
        sanity     = "You don't set valid price or items count.",
        minimums   = "You have to type a number higher than 0.",
        maximums   = "This price or item count is too high.",
        safeOffer  = "You must be in PZ area when you add offer to database.",
        safeDelist = "You must be in PZ area when you remove offers from database.",
        delisted   = "Your offer has been deleted from offers database.",

        minLevel  = ("You don't have required (" .. config.levelRequiredToAdd .. ") level."),
        maxOffers = ("Sorry you can't add more offers (max. " .. config.maxOffersPerPlayer .. ")"),

        tooHeavy = (function(name, weight, maxcap)
            return ("You try to buy a " .. name ..
                ". It weighs " .. weight ..
                " cap oz. and you have only " .. maxcap ..
                " oz. free capacity. Put some items to depot and try again.")
        end),

        purchase = (function(count, name, price)
            return ("You bought " .. count .. " " .. name .. " for " .. price .. " gps!")
        end),

        marketed = (function(count, name, price)
            return ("You successfully add " .. count .. " " .. name .. " for " .. price .. " gps to offers database.")
        end),

        collectTill = (function(sales)
            return ("You got " .. sales .. " gps from auction system!")
        end),
    }

    local function problem(message)
        return sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
    end

    local function success(message)
        return sendMessage(MESSAGE_INFO_DESCR, message)
    end

    local function sendMessage(color, message)
        return doPlayerSendTextMessage(cid, color, message)
    end

    if(param == '') then
        return problem(messages['cparam'])
    end

    local sql = {
        selectID   = (function(offerID) return db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (offerID) .. ";") end),
        selectGUID = (function(guid) return db.getResult("SELECT `id` FROM `auction_system` WHERE `player` = " .. (guid) .. ";") end),
        getBalance = (function(guid) return db.getResult("SELECT `auction_balance` FROM `players` WHERE `id` = " .. (guid) .. ";") end),
        insert     = (function(guid, item, id, count, price) db.executeQuery("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`) VALUES (" ..
            guid .. ", \"" .. item .. "\", " .. id .. ", " .. count .. ", " .. price .. ", " .. os.time() .. ")") end),
        deleteOffer = (function(id) db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. id .. ";") end),
        cashout = (function(guid) db.executeQuery("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. guid .. ";") end),
        claimOffer = (function(id, sale, vendor)
            db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. id .. ";")
            db.executeQuery("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. sale .. " WHERE `id` = " .. vendor .. ";")
        end),
    }

    local function doWithdraw()
        local balance = sql.getBalance(getPlayerGUID(cid))
        local count = balance:getDataInt("auction_balance")
        balance:free()
        if(count < 1) then
            return problem(messages['noSales'])
        end

        sql.cashout(getPlayerGUID(cid))
        doPlayerAddMoney(cid, count)
        return success(messages['collectTill'](count))
    end

    local function doAdd(t)
        if(getPlayerVocation(cid) == 0) then
            return problem(messages['rookie'])
        end

        if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
            return problem(messages['minLevel'])
        end

        if(config.sendOffersOnlyInPZ and (not getTilePzInfo(getPlayerPosition(cid)))) then
            return problem(messages['safeOffer'])
        end

        if((not t[2]) or (not t[3]) or (not t[4])) then
            return problem(messages['aparam'])
        end

        if(not tonumber(t[3]) or (not tonumber(t[4]))) then
            return problem(messages['sanity'])
        end

        if(string.len(t[3]) > 7 or (string.len(t[4]) > 3)) then
            return problem(messages['maximums'])
        end

        if(tonumber(t[4]) < 1 or (tonumber(t[3]) < 1)) then
            return problem(messages['minimums'])
        end

        local item = getItemIdByName(t[2], false)
        if(not item) then
            return problem(messages['badItem'])
        end

        if(isInArray(config.blocked_items, item)) then
            return problem(messages['contraband'])
        end

        if(getPlayerItemCount(cid, item) < (tonumber(t[4]))) then
            return problem(messages['dontHave'])
        end

        local check = sql.selectGUID(getPlayerGUID(cid))
        if(check:getID() == -1) then
        elseif(check:getRows(true) >= config.maxOffersPerPlayer) then
            return problem(messages['maxOffers'])
        end

        local itemcount, costgp = math.floor(t[4]), math.floor(t[3])
        doPlayerRemoveItem(cid, item, itemcount)
        sql.insert(getPlayerGUID(cid), t[2], item, itemcount, costgp)

        return success(messages['marketed'](itemcount, t[2], costgp))
    end

    local function doRemove(t)
        if(config.sendOffersOnlyInPZ and (not getTilePzInfo(getPlayerPosition(cid)))) then
            return problem(messages['safeDelist'])
        end

        if((not tonumber(t[2]))) then
            return problem(messages['invalid'])
        end

        local delete = sql.selectID(tonumber(t[2]))
        if(delete:getID() ~= -1) then
            if(getPlayerGUID(cid) == delete:getDataInt("player")) then
                sql.deleteOffer(t[2])
                if(isItemStackable(delete:getDataString("item_id"))) then
                    doPlayerAddItem(cid, delete:getDataString("item_id"), delete:getDataInt("count"))
                else
                    for i = 1, delete:getDataInt("count") do
                        doPlayerAddItem(cid, delete:getDataString("item_id"), 1)
                    end
                end

                delete:free()
                return success(messages['delisted'])
            else
                delete:free()
                return problem(messages['notYours'])
            end
        else
            return problem(messages['invalid'])
        end
    end

    local function doBuy(t)
        if(getPlayerVocation(cid) == 0) then
            return problem(messages['rookie'])
        end

        if(not tonumber(t[2])) then
            return problem(messages['invalid'])
        end

        local buy = sql.selectID(tonumber(t[2]))
        if(buy:getID() ~= -1) then
            local seller = buy:getDataInt("player")
            local count = buy:getDataInt("count")
            local name = buy:getDataString("item_name")
            local price = buy:getDataInt("cost")
            local itemid = buy:getDataInt("item_id")
            local weight = getItemWeightById(itemid, count)
            buy:free()

            if(getPlayerName(cid) == getPlayerNameByGUID(seller)) then
                return problem(messages['ownOffer'])
            end

            if(getPlayerMoney(cid) < price) then
                return problem(messages['youPoor'])
            end

            local freecap = getPlayerFreeCap(cid)
            if (freecap < weight) then
                return problem(messages['tooHeavy'](name, weight, freecap))
            end

            if(isItemStackable((itemid))) then
                doPlayerAddItem(cid, itemid, count)
            else
                for i = 1, count do doPlayerAddItem(cid, itemid, 1) end
            end

            doPlayerRemoveMoney(cid, price)
            sql.claimOffer(t[2], price, seller)
            return success(messages['purchase'](count, name, price))
        else
            return problem(messages['invalid'])
        end
    end

    local actions = {
        ['add']      = doAdd,
        ['buy']      = doBuy,
        ['remove']   = doRemove,
        ['withdraw'] = doWithdraw,
    }
    local t = string.explode(param, ",")
    if(actions[t[1]] ~= nil) then
        return actions[t[1]](t)
    end

    return problem(messages['unknown'])
end

Ok. This probably doesn't fix your bug, but it fixes my urge to beat whoever wrote this script with an old stinky shoe.

Also, since I don't have whatever system this is from to test it, please... if there is minor bugs, just post the line its from and not the whole script... 😒
 
Lua:
--[[
        Offline player to player item trader (Auction System) by vDk
                Script version: 1.3 [ -- FIXED CLONE ITEMS BUG -- ]
                    ~~ Lessaire best practices patch ~~
]]--

local config = {
    levelRequiredToAdd = 1,
    maxOffersPerPlayer = 5,
    sendOffersOnlyInPZ = true,
    blocked_items = {2165, 2152, 2148, 2160, 2166, 2167, 2168, 2169, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2343, 2433, 2640, 6132, 6300, 6301, 9932, 9933}
}

function onSay(cid, words, param, channel)
    local messages = {
        cparam     = "This command requires action param: add buy remove withdraw",
        aparam     = "This action requires params: item, cost, count.",
        unknown    = "Unrecognized action path for this command. Available actions: add buy remove withdraw",

        badItem    = "Item with such name does not exist.",
        ownOffer   = "Sorry, you can't buy your own items.",
        dontHave   = "Sorry, you don't have this item(s).",
        notYours   = "This is not your offer!",
        contraband = "This item is blocked.",
        invalid    = "Wrong ID.",
        youPoor    = "You don't have enough GP.",
        noSales    = "You don't have money on your auction balance.",
        rookie     = "You don't have the profession to do that action!",
        sanity     = "You don't set valid price or items count.",
        minimums   = "You have to type a number higher than 0.",
        maximums   = "This price or item count is too high.",
        safeOffer  = "You must be in PZ area when you add offer to database.",
        safeDelist = "You must be in PZ area when you remove offers from database.",
        delisted   = "Your offer has been deleted from offers database.",

        minLevel  = ("You don't have required (" .. config.levelRequiredToAdd .. ") level."),
        maxOffers = ("Sorry you can't add more offers (max. " .. config.maxOffersPerPlayer .. ")"),

        tooHeavy = (function(name, weight, maxcap)
            return ("You try to buy a " .. name ..
                ". It weighs " .. weight ..
                " cap oz. and you have only " .. maxcap ..
                " oz. free capacity. Put some items to depot and try again.")
        end),

        purchase = (function(count, name, price)
            return ("You bought " .. count .. " " .. name .. " for " .. price .. " gps!")
        end),

        marketed = (function(count, name, price)
            return ("You successfully add " .. count .. " " .. name .. " for " .. price .. " gps to offers database.")
        end),

        collectTill = (function(sales)
            return ("You got " .. sales .. " gps from auction system!")
        end),
    }

    local function problem(message)
        return sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
    end

    local function success(message)
        return sendMessage(MESSAGE_INFO_DESCR, message)
    end

    local function sendMessage(color, message)
        return doPlayerSendTextMessage(cid, color, message)
    end

    if(param == '') then
        return problem(messages['cparam'])
    end

    local sql = {
        selectID   = (function(offerID) return db.getResult("SELECT * FROM `auction_system` WHERE `id` = " .. (offerID) .. ";") end),
        selectGUID = (function(guid) return db.getResult("SELECT `id` FROM `auction_system` WHERE `player` = " .. (guid) .. ";") end),
        getBalance = (function(guid) return db.getResult("SELECT `auction_balance` FROM `players` WHERE `id` = " .. (guid) .. ";") end),
        insert     = (function(guid, item, id, count, price) db.executeQuery("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`) VALUES (" ..
            guid .. ", \"" .. item .. "\", " .. id .. ", " .. count .. ", " .. price .. ", " .. os.time() .. ")") end),
        deleteOffer = (function(id) db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. id .. ";") end),
        cashout = (function(guid) db.executeQuery("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. guid .. ";") end),
        claimOffer = (function(id, sale, vendor)
            db.executeQuery("DELETE FROM `auction_system` WHERE `id` = " .. id .. ";")
            db.executeQuery("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. sale .. " WHERE `id` = " .. vendor .. ";")
        end),
    }

    local function doWithdraw()
        local balance = sql.getBalance(getPlayerGUID(cid))
        local count = balance:getDataInt("auction_balance")
        balance:free()
        if(count < 1) then
            return problem(messages['noSales'])
        end

        sql.cashout(getPlayerGUID(cid))
        doPlayerAddMoney(cid, count)
        return success(messages['collectTill'](count))
    end

    local function doAdd(t)
        if(getPlayerVocation(cid) == 0) then
            return problem(messages['rookie'])
        end

        if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
            return problem(messages['minLevel'])
        end

        if(config.sendOffersOnlyInPZ and (not getTilePzInfo(getPlayerPosition(cid)))) then
            return problem(messages['safeOffer'])
        end

        if((not t[2]) or (not t[3]) or (not t[4])) then
            return problem(messages['aparam'])
        end

        if(not tonumber(t[3]) or (not tonumber(t[4]))) then
            return problem(messages['sanity'])
        end

        if(string.len(t[3]) > 7 or (string.len(t[4]) > 3)) then
            return problem(messages['maximums'])
        end

        if(tonumber(t[4]) < 1 or (tonumber(t[3]) < 1)) then
            return problem(messages['minimums'])
        end

        local item = getItemIdByName(t[2], false)
        if(not item) then
            return problem(messages['badItem'])
        end

        if(isInArray(config.blocked_items, item)) then
            return problem(messages['contraband'])
        end

        if(getPlayerItemCount(cid, item) < (tonumber(t[4]))) then
            return problem(messages['dontHave'])
        end

        local check = sql.selectGUID(getPlayerGUID(cid))
        if(check:getID() == -1) then
        elseif(check:getRows(true) >= config.maxOffersPerPlayer) then
            return problem(messages['maxOffers'])
        end

        local itemcount, costgp = math.floor(t[4]), math.floor(t[3])
        doPlayerRemoveItem(cid, item, itemcount)
        sql.insert(getPlayerGUID(cid), t[2], item, itemcount, costgp)

        return success(messages['marketed'](itemcount, t[2], costgp))
    end

    local function doRemove(t)
        if(config.sendOffersOnlyInPZ and (not getTilePzInfo(getPlayerPosition(cid)))) then
            return problem(messages['safeDelist'])
        end

        if((not tonumber(t[2]))) then
            return problem(messages['invalid'])
        end

        local delete = sql.selectID(tonumber(t[2]))
        if(delete:getID() ~= -1) then
            if(getPlayerGUID(cid) == delete:getDataInt("player")) then
                sql.deleteOffer(t[2])
                if(isItemStackable(delete:getDataString("item_id"))) then
                    doPlayerAddItem(cid, delete:getDataString("item_id"), delete:getDataInt("count"))
                else
                    for i = 1, delete:getDataInt("count") do
                        doPlayerAddItem(cid, delete:getDataString("item_id"), 1)
                    end
                end

                delete:free()
                return success(messages['delisted'])
            else
                delete:free()
                return problem(messages['notYours'])
            end
        else
            return problem(messages['invalid'])
        end
    end

    local function doBuy(t)
        if(getPlayerVocation(cid) == 0) then
            return problem(messages['rookie'])
        end

        if(not tonumber(t[2])) then
            return problem(messages['invalid'])
        end

        local buy = sql.selectID(tonumber(t[2]))
        if(buy:getID() ~= -1) then
            local seller = buy:getDataInt("player")
            local count = buy:getDataInt("count")
            local name = buy:getDataString("item_name")
            local price = buy:getDataInt("cost")
            local itemid = buy:getDataInt("item_id")
            local weight = getItemWeightById(itemid, count)
            buy:free()

            if(getPlayerName(cid) == getPlayerNameByGUID(seller)) then
                return problem(messages['ownOffer'])
            end

            if(getPlayerMoney(cid) < price) then
                return problem(messages['youPoor'])
            end

            local freecap = getPlayerFreeCap(cid)
            if (freecap < weight) then
                return problem(messages['tooHeavy'](name, weight, freecap))
            end

            if(isItemStackable((itemid))) then
                doPlayerAddItem(cid, itemid, count)
            else
                for i = 1, count do doPlayerAddItem(cid, itemid, 1) end
            end

            doPlayerRemoveMoney(cid, price)
            sql.claimOffer(t[2], price, seller)
            return success(messages['purchase'](count, name, price))
        else
            return problem(messages['invalid'])
        end
    end

    local actions = {
        ['add']      = doAdd,
        ['buy']      = doBuy,
        ['remove']   = doRemove,
        ['withdraw'] = doWithdraw,
    }
    local t = string.explode(param, ",")
    if(actions[t[1]] ~= nil) then
        return actions[t[1]](t)
    end

    return problem(messages['unknown'])
end

Ok. This probably doesn't fix your bug, but it fixes my urge to beat whoever wrote this script with an old stinky shoe.

Also, since I don't have whatever system this is from to test it, please... if there is minor bugs, just post the line its from and not the whole script... 😒
got this error:

Lua:
[6:54:19.168] [Error - TalkAction Interface]
[6:54:19.184] data/talkactions/scripts/auctionsystem.lua:onSay
[6:54:19.199] Description:
[6:54:19.199] data/talkactions/scripts/auctionsystem.lua:61: attempt to call global 'sendMessage' (a nil value)
[6:54:19.231] stack traceback:
[6:54:19.231]   data/talkactions/scripts/auctionsystem.lua:61: in function <data/talkactions/scripts/auctionsystem.lua:60>
 
oops.

see the local sendMessage function? just move it above the problem function. then try again
how i didnt understand
Lua:
    local function problem(message)
        return sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
    end

    local function success(message)
        return sendMessage(MESSAGE_INFO_DESCR, message)
    end

    local function sendMessage(color, message)
        return doPlayerSendTextMessage(cid, color, message)
    end
 
:really:

Lua:
    local function sendMessage(color, message)
        return doPlayerSendTextMessage(cid, color, message)
    end

    local function problem(message)
        return sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
    end

    local function success(message)
        return sendMessage(MESSAGE_INFO_DESCR, message)
    end
 
:really:

Lua:
    local function sendMessage(color, message)
        return doPlayerSendTextMessage(cid, color, message)
    end

    local function problem(message)
        return sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
    end

    local function success(message)
        return sendMessage(MESSAGE_INFO_DESCR, message)
    end
now this error

Lua:
[21:1:04.026] [Error - TalkAction Interface]
[21:1:04.026] data/talkactions/scripts/auctionsystem.lua:onSay
[21:1:04.026] Description:
[21:1:04.041] (LuaInterface::luaGetItemIdByName) Item not found
 
Alright, so this may be a problem with your server source code / binary. I had a similar problem.

Basically luaGetItemIdByName ends up not working correctly in certain releases.

make this change around ~line 130
Diff:
-        local item = getItemIdByName(t[2], false)
+        local item = getItemIdByName(t[2])

and see if that makes the error go away.
 
Solution
Back
Top