• 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 How to remove the item from arrow slot

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
I tried:
Code:
local item = getPlayerSlotItem(cid, CONST_SLOT_AMMO).itemid
        local Item_Count = getPlayerSlotItem(cid, CONST_SLOT_AMMO).type

        if(tonumber(Item_Count) < 1) then
            Item_Count = 1
        end
doPlayerRemoveItem(cid, item, itemcount)

But it is removing a random item...

For example, if i have a demon helmet on head and one in arrow slot, it remove the demon helmet from head

I need to remove from the arrow slot...

How to do?
 
Solution
Tested. Works over there. Didn't remove any item other than what I placed in arrow slot.

View attachment 57207

View attachment 57208

test with a demon helmet on arrow slot and other on head
Post automatically merged:

i've found the solution here:
try
Lua:
local item = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
if item and item.uid ~= 0 then
    doPlayerRemoveItem(cid, item.itemid, 1)
end

Code:
[22:14:25.375] [Error - TalkAction Interface] 
[22:14:25.375] data/talkactions/scripts/auctionsystem.lua:onSay
[22:14:25.375] Description: 
[22:14:25.375] data/talkactions/scripts/auctionsystem.lua:147: attempt to index local 'item' (a number value)
[22:14:25.375] stack traceback:
[22:14:25.375]     data/talkactions/scripts/auctionsystem.lua:147: in function <data/talkactions/scripts/auctionsystem.lua:58>

line 147 is:
Code:
doPlayerRemoveItem(cid, item.itemid, itemcount)
 
Code:
[22:14:25.375] [Error - TalkAction Interface]
[22:14:25.375] data/talkactions/scripts/auctionsystem.lua:onSay
[22:14:25.375] Description:
[22:14:25.375] data/talkactions/scripts/auctionsystem.lua:147: attempt to index local 'item' (a number value)
[22:14:25.375] stack traceback:
[22:14:25.375]     data/talkactions/scripts/auctionsystem.lua:147: in function <data/talkactions/scripts/auctionsystem.lua:58>

line 147 is:
Code:
doPlayerRemoveItem(cid, item.itemid, itemcount)
I wonder what's going on over there.
Post your script
 
Test
Lua:
local item = getPlayerSlotItem(cid, CONST_SLOT_AMMO) ~= nil and getPlayerSlotItem(cid, CONST_SLOT_AMMO) or nil
The item is there, i just have it in head and on arrow slot


I wonder what's going on over there.
Post your script


whole script:

Code:
--[[
Offline player to player item trader (Auction System) by vDk
Script version: 1.2a [ -- FIXED CLONE ITEMS BUG -- ]
]]--
local config = {
    levelRequiredToAdd = 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, 6093, 2123}
}

local function updatePlayerBalance(name, value)
    db.query('UPDATE players SET balance=' .. value .. ' WHERE name=' .. db.escapeString(name) .. ' LIMIT 1')
end

local nameLv = {
    [1] = "[U]",
    [2] = "[R]",
    [3] = "[E]",
    [4] = "[M]",
    [5] = "[L]",
}

function itemExtractNameLevel(item_uid, clean_name)
    local name = getItemAttribute(item_uid, "name")
    if name ~= nil then
        local level = 0
        for lvl, flourish in ipairs(nameLv) do
            if name:find(flourish) then
                level = lvl
            end
        end
        if level == 0 then
            name = clean_name
        end
    else
        name = clean_name
    end
    return name
end

function getRarity(str)
    local value = 0
    local n = str:match("%[(.-)%]")
    if n == "U" then
       value = 1
    elseif n == "R" then
       value = 2
    elseif n == "E" then
       value = 3
    elseif n == "M" then
       value = 4
    elseif n == "L" then
       value = 5
    end
    return value
end

function onSay(cid, words, param, channel)
    if(param == '') then
        local msg = "Market:\n\n/market buy, ID\n/market remove, ID\n/market add, ItemPrice\n\nMore information look in us website!"
        doPlayerPopupFYI(cid, msg)
        return true
    end

    local maxOffersPerPlayer = math.floor(getPlayerLevel(cid) / 5)
    local pricePerOffer = 500
 
    local t = string.explode(param, ",")
    if(t[1] == "add") then
        local Item_Price = t[2]

        if(not Item_Price) then
            local msg = "/market add, ItemPrice"
            doPlayerPopupFYI(cid, msg)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
            return true
        end
 
        if(not tonumber(Item_Price)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
            return true
        end
 
        if(string.len(Item_Price) > 7) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
            return true
        end

        if getPlayerSlotItem(cid, CONST_SLOT_AMMO).itemid == 0 then
            return doPlayerSendCancel(cid, "You have no item in your equipament arrow slot to sell!")
        end
        
        local item = getPlayerSlotItem(cid, CONST_SLOT_AMMO).itemid
        local itemUniqueID = getPlayerSlotItem(cid, CONST_SLOT_AMMO).uid
        local Item_Count = getPlayerSlotItem(cid, CONST_SLOT_AMMO).type

        if(tonumber(Item_Count) < 1) then
            Item_Count = 1
        end
        local Item_Name = getItemNameById(item)

        if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
            return true
        end
 
        if(isInArray(config.blocked_items, item)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
            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) >= maxOffersPerPlayer) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max for your level: " .. 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(Item_Price) < 1)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
            return true
        end

        if(getPlayerBalance(cid) < 500) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to have 500GPs in your bank balance to make a offer.")
            return true
        end

        -- check if it is enchanted
        -- check if before name there is:
        -- [XXX] itemname
        local itemname = Item_Name
        local nameWithRarity = itemExtractNameLevel(itemUniqueID, Item_Name)
        local rarityOnly = getRarity(nameWithRarity)

        doPlayerSetBalance(cid, getPlayerBalance(cid) - 500)
        updatePlayerBalance(getCreatureByName(cid), getPlayerBalance(cid))
 
        local itemcount, costgp = math.floor(Item_Count), math.floor(Item_Price)
        doPlayerRemoveItem(cid, item.itemid, itemcount)
        db.executeQuery("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`, `upgrade_level`) VALUES (" .. getPlayerGUID(cid) .. ", \"" .. nameWithRarity .. "\", " .. getItemIdByName(Item_Name) .. ", " .. itemcount .. ", " .. costgp ..", " .. os.time() .. ", ".. rarityOnly ..")")
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. nameWithRarity .." for " .. costgp .. " gps to offerts 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 (getPlayerBalance(cid) < buy:getDataInt("cost")) then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enoguh Bank Balance.")
                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
 
            local buyed_item
            if(isItemStackable((buy:getDataString("item_id")))) then
                buyed_item = doPlayerAddItem(cid, buy:getDataString("item_id"), buy:getDataInt("count"))
            else
                for i = 1, buy:getDataInt("count") do
                    buyed_item = doPlayerAddItem(cid, buy:getDataString("item_id"), 1)
                end
            end
            doPlayerSetBalance(cid, getPlayerBalance(cid) - buy:getDataInt("cost"))
            updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))

            local upgraded_level = buy:getDataInt("upgrade_level")
            if upgraded_level > 0 then
                -- | set name |
                function setItemName(uid,name)
                    return doItemSetAttribute(uid,'name',name)
                end
                local item_name_withoutupgrade = getItemNameById(buy:getDataString("item_id"))
                local item_name_withupgrade = nameLv[upgraded_level] .. " " .. item_name_withoutupgrade
                setItemName(buyed_item,item_name_withupgrade)
                -- self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1]..(self:getItemName():gsub("%["..self.nameLv[self.item.level].."%]", "")) or self.nameLv[1].." "..self:getItemName())
                -- | set atk,def,armor |
                -- local item = buy:getDataString("item_id")
                -- doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
            
            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!")
           
            local tid = getPlayerByGUID(buy:getDataInt("player"))
            if(isPlayer(tid)) then
                doPlayerSetBalance(tid, getPlayerBalance(tid) + buy:getDataInt("cost"))
            else
                db.executeQuery("UPDATE `players` SET `balance` = `balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")
            end
 
            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
    return true
end
 
that's how it was

Try
Lua:
--[[
Offline player to player item trader (Auction System) by vDk
Script version: 1.2a [ -- FIXED CLONE ITEMS BUG -- ]
]]--

local config = {
    levelRequiredToAdd = 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, 6093, 2123}
}

local function updatePlayerBalance(name, value)
    db.query('UPDATE players SET balance=' .. value .. ' WHERE name=' .. db.escapeString(name) .. ' LIMIT 1')
end

local nameLv = {
    [1] = "[U]",
    [2] = "[R]",
    [3] = "[E]",
    [4] = "[M]",
    [5] = "[L]",
}

function itemExtractNameLevel(item_uid, clean_name)
    local name = getItemAttribute(item_uid, "name")
    if name ~= nil then
        local level = 0
        for lvl, flourish in ipairs(nameLv) do
            if name:find(flourish) then
                level = lvl
            end
        end
        if level == 0 then
            name = clean_name
        end
    else
        name = clean_name
    end
    return name
end

function getRarity(str)
    local value = 0
    local n = str:match("%[(.-)%]")
    if n == "U" then
       value = 1
    elseif n == "R" then
       value = 2
    elseif n == "E" then
       value = 3
    elseif n == "M" then
       value = 4
    elseif n == "L" then
       value = 5
    end
    return value
end

function onSay(cid, words, param, channel)
    if(param == '') then
        local msg = "Market:\n\n/market buy, ID\n/market remove, ID\n/market add, ItemPrice\n\nMore information look in us website!"
        doPlayerPopupFYI(cid, msg)
        return true
    end
    local maxOffersPerPlayer = math.floor(getPlayerLevel(cid) / 5)
    local pricePerOffer = 500
 
    local t = string.explode(param, ",")
    if(t[1] == "add") then
        local Item_Price = t[2]
        if(not Item_Price) then
            local msg = "/market add, ItemPrice"
            doPlayerPopupFYI(cid, msg)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
            return true
        end
 
        if(not tonumber(Item_Price)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
            return true
        end
 
        if(string.len(Item_Price) > 7) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
            return true
        end
        local ammoItem = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
        if (not ammoItem) or (ammoItem.uid == 0) then
            return doPlayerSendCancel(cid, "You have no item in your equipament arrow slot to sell!")
        end
        
        local item = ammoItem.itemid
        local itemUniqueID = ammoItem.uid
        local Item_Count = ammoItem.type
        if(tonumber(Item_Count) < 1) then
            Item_Count = 1
        end
        local Item_Name = getItemNameById(item)
        if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
            return true
        end
 
        if(isInArray(config.blocked_items, item)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
            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) >= maxOffersPerPlayer) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max for your level: " .. 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(Item_Price) < 1)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
            return true
        end
        if(getPlayerBalance(cid) < 500) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to have 500GPs in your bank balance to make a offer.")
            return true
        end
        -- check if it is enchanted
        -- check if before name there is:
        -- [XXX] itemname
        local nameWithRarity = itemExtractNameLevel(itemUniqueID, Item_Name)
        local rarityOnly = getRarity(nameWithRarity)
        doPlayerSetBalance(cid, getPlayerBalance(cid) - 500)
        updatePlayerBalance(getCreatureByName(cid), getPlayerBalance(cid))
 
        local itemcount = math.floor(Item_Count)
        local costgp = math.floor(Item_Price)
        doPlayerRemoveItem(cid, item, itemcount)
        db.executeQuery("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`, `upgrade_level`) VALUES (" .. getPlayerGUID(cid) .. ", \"" .. nameWithRarity .. "\", " .. getItemIdByName(Item_Name) .. ", " .. itemcount .. ", " .. costgp ..", " .. os.time() .. ", ".. rarityOnly ..")")
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. nameWithRarity .." for " .. costgp .. " gps to offerts 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 (getPlayerBalance(cid) < buy:getDataInt("cost")) then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enoguh Bank Balance.")
                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
 
            local buyed_item
            if(isItemStackable((buy:getDataString("item_id")))) then
                buyed_item = doPlayerAddItem(cid, buy:getDataString("item_id"), buy:getDataInt("count"))
            else
                for i = 1, buy:getDataInt("count") do
                    buyed_item = doPlayerAddItem(cid, buy:getDataString("item_id"), 1)
                end
            end
            doPlayerSetBalance(cid, getPlayerBalance(cid) - buy:getDataInt("cost"))
            updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))
            local upgraded_level = buy:getDataInt("upgrade_level")
            if upgraded_level > 0 then
                -- | set name |
                function setItemName(uid,name)
                    return doItemSetAttribute(uid,'name',name)
                end
                local item_name_withoutupgrade = getItemNameById(buy:getDataString("item_id"))
                local item_name_withupgrade = nameLv[upgraded_level] .. " " .. item_name_withoutupgrade
                setItemName(buyed_item,item_name_withupgrade)
                -- self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1]..(self:getItemName():gsub("%["..self.nameLv[self.item.level].."%]", "")) or self.nameLv[1].." "..self:getItemName())
                -- | set atk,def,armor |
                -- local item = buy:getDataString("item_id")
                -- doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
            
            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!")
           
            local tid = getPlayerByGUID(buy:getDataInt("player"))
            if(isPlayer(tid)) then
                doPlayerSetBalance(tid, getPlayerBalance(tid) + buy:getDataInt("cost"))
            else
                db.executeQuery("UPDATE `players` SET `balance` = `balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")
            end
 
            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
    return true
end
 
Try
Lua:
--[[
Offline player to player item trader (Auction System) by vDk
Script version: 1.2a [ -- FIXED CLONE ITEMS BUG -- ]
]]--

local config = {
    levelRequiredToAdd = 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, 6093, 2123}
}

local function updatePlayerBalance(name, value)
    db.query('UPDATE players SET balance=' .. value .. ' WHERE name=' .. db.escapeString(name) .. ' LIMIT 1')
end

local nameLv = {
    [1] = "[U]",
    [2] = "[R]",
    [3] = "[E]",
    [4] = "[M]",
    [5] = "[L]",
}

function itemExtractNameLevel(item_uid, clean_name)
    local name = getItemAttribute(item_uid, "name")
    if name ~= nil then
        local level = 0
        for lvl, flourish in ipairs(nameLv) do
            if name:find(flourish) then
                level = lvl
            end
        end
        if level == 0 then
            name = clean_name
        end
    else
        name = clean_name
    end
    return name
end

function getRarity(str)
    local value = 0
    local n = str:match("%[(.-)%]")
    if n == "U" then
       value = 1
    elseif n == "R" then
       value = 2
    elseif n == "E" then
       value = 3
    elseif n == "M" then
       value = 4
    elseif n == "L" then
       value = 5
    end
    return value
end

function onSay(cid, words, param, channel)
    if(param == '') then
        local msg = "Market:\n\n/market buy, ID\n/market remove, ID\n/market add, ItemPrice\n\nMore information look in us website!"
        doPlayerPopupFYI(cid, msg)
        return true
    end
    local maxOffersPerPlayer = math.floor(getPlayerLevel(cid) / 5)
    local pricePerOffer = 500

    local t = string.explode(param, ",")
    if(t[1] == "add") then
        local Item_Price = t[2]
        if(not Item_Price) then
            local msg = "/market add, ItemPrice"
            doPlayerPopupFYI(cid, msg)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
            return true
        end

        if(not tonumber(Item_Price)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
            return true
        end

        if(string.len(Item_Price) > 7) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
            return true
        end
        local ammoItem = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
        if (not ammoItem) or (ammoItem.uid == 0) then
            return doPlayerSendCancel(cid, "You have no item in your equipament arrow slot to sell!")
        end
       
        local item = ammoItem.itemid
        local itemUniqueID = ammoItem.uid
        local Item_Count = ammoItem.type
        if(tonumber(Item_Count) < 1) then
            Item_Count = 1
        end
        local Item_Name = getItemNameById(item)
        if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
            return true
        end

        if(isInArray(config.blocked_items, item)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
            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) >= maxOffersPerPlayer) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max for your level: " .. 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(Item_Price) < 1)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
            return true
        end
        if(getPlayerBalance(cid) < 500) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to have 500GPs in your bank balance to make a offer.")
            return true
        end
        -- check if it is enchanted
        -- check if before name there is:
        -- [XXX] itemname
        local nameWithRarity = itemExtractNameLevel(itemUniqueID, Item_Name)
        local rarityOnly = getRarity(nameWithRarity)
        doPlayerSetBalance(cid, getPlayerBalance(cid) - 500)
        updatePlayerBalance(getCreatureByName(cid), getPlayerBalance(cid))

        local itemcount = math.floor(Item_Count)
        local costgp = math.floor(Item_Price)
        doPlayerRemoveItem(cid, item, itemcount)
        db.executeQuery("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`, `upgrade_level`) VALUES (" .. getPlayerGUID(cid) .. ", \"" .. nameWithRarity .. "\", " .. getItemIdByName(Item_Name) .. ", " .. itemcount .. ", " .. costgp ..", " .. os.time() .. ", ".. rarityOnly ..")")
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. nameWithRarity .." for " .. costgp .. " gps to offerts 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 (getPlayerBalance(cid) < buy:getDataInt("cost")) then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enoguh Bank Balance.")
                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

            local buyed_item
            if(isItemStackable((buy:getDataString("item_id")))) then
                buyed_item = doPlayerAddItem(cid, buy:getDataString("item_id"), buy:getDataInt("count"))
            else
                for i = 1, buy:getDataInt("count") do
                    buyed_item = doPlayerAddItem(cid, buy:getDataString("item_id"), 1)
                end
            end
            doPlayerSetBalance(cid, getPlayerBalance(cid) - buy:getDataInt("cost"))
            updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))
            local upgraded_level = buy:getDataInt("upgrade_level")
            if upgraded_level > 0 then
                -- | set name |
                function setItemName(uid,name)
                    return doItemSetAttribute(uid,'name',name)
                end
                local item_name_withoutupgrade = getItemNameById(buy:getDataString("item_id"))
                local item_name_withupgrade = nameLv[upgraded_level] .. " " .. item_name_withoutupgrade
                setItemName(buyed_item,item_name_withupgrade)
                -- self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1]..(self:getItemName():gsub("%["..self.nameLv[self.item.level].."%]", "")) or self.nameLv[1].." "..self:getItemName())
                -- | set atk,def,armor |
                -- local item = buy:getDataString("item_id")
                -- doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
           
            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!")
          
            local tid = getPlayerByGUID(buy:getDataInt("player"))
            if(isPlayer(tid)) then
                doPlayerSetBalance(tid, getPlayerBalance(tid) + buy:getDataInt("cost"))
            else
                db.executeQuery("UPDATE `players` SET `balance` = `balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")
            end

            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
    return true
end

Still removing from head instead of arrow
 
Tested. Works over there. Didn't remove any item other than what I placed in arrow slot.

View attachment 57207

View attachment 57208

test with a demon helmet on arrow slot and other on head
Post automatically merged:

i've found the solution here:
 
Last edited:
Solution
test with a demon helmet on arrow slot and other on head
Post automatically merged:

i've found the solution here:

That's going to happen for sure, the script isn't checking whether the item is ammo or helmet.

i've found the solution here:
Alright mister
 
Back
Top