• 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 Auction system (Website Tradeoff) + Upgrade system (Refin Items)

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
I have this upgrade system:

/lib/upgradesystem.lua
Code:
--PERFECT UPGRADE SYSTEM

UpgradeHandler = {

    nameLv = {

        [1] = "[R]",

        [2] = "[G]",

        [3] = "[B]",

        [4] = "[W]",

        [5] = "[D]",

    },

    completeNameLv = {

        [1] = "red",

        [2] = "green",

        [3] = "blue",

        [4] = "white",

        [5] = "dark",

    },

    levels = {

          [1] = {65, false, false},

          [2] = {40, false, false},

          [3] = {25, false, false},

          [4] = {10, false, false},

          [5] = {5, true, true},

    },

    broadcast = 5,

    attributes = {

          ["attack"] = 3,

          ["defense"] = 2,

          ["armor"] = 1

    },

    message = {

          console = "Trying to refine %s to level +%s with %s%% success rate.",

          success = "You have upgraded %s to level %s",

          fail = "You have failed in upgrade of %s to level +%s",

          downgrade = "The upgrade level of %s has downgraded to +%s",

          erase = "The upgrade level of %s has been erased.",

          maxlevel = "The targeted %s is already on max upgrade level.",

          notupgradeable = "This item is not upgradeable.",

          broadcast = "The player %s was successful in upgrading %s to level %s.\nCongratulations!!",

          invalidtool = "This is not a valid upgrade tool.",

          toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"

    },

    tools = {

        [8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},

        [8300] = {range = {0, 10}, info = {chance = 20, removeable = true}}

    },

    isEquipment = function(self)

        local weaponType = self:getItemWeaponType()

        return ((weaponType > 0 and weaponType < 8) or self.item.armor ~= 0)

    end,

    setItemName = function(self, name)

        return doItemSetAttribute(self.item.uid, "name", name)

    end,

    chance = function(self)

        local chances = {}

        chances.upgrade = (self.levels[self.item.level + 1][1] or 100)

        chances.downgrade = (self.item.level * 5)

        chances.erase = (self.item.level * 3)

        return chances

    end

}

function UpgradeHandler:new(item)

    local obj, ret = {}

    obj.item = {}

    obj.item.level = 0

    obj.item.uid = item.uid

    for key, value in pairs(getItemInfo(item.itemid)) do

        obj.item[key] = value

    end

    ret = setmetatable(obj, {

        __index = function(self, index)

            if _G[index] then

                return (setmetatable({callback = _G[index]},

                    {__call = function(self, ...)

                        return self.callback(item.uid, ...)

                    end}

                ))

            else

                return UpgradeHandler[index]

            end

    end})

    if ret:isEquipment() then

        ret:update()

        return ret

    end

    return false

end

function UpgradeHandler:update()

   -- this will return the level by the quality or 0 if it has no quality.

    self.item.level = 0

    for r, v in ipairs(self.nameLv) do

        if self:getItemName():find(v) then

            self.item.level = r

        end

    end

end

function UpgradeHandler:refine(uid, item)

    if not self.item then

        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)

        return "miss"

    end

    local tool = self.tools[item.itemid]

    if(tool == nil) then

        doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)

        return "miss"

    end

    if(self.item.level > #self.levels) then

        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))

        return "miss"

    end

    if(tool.range[1] and self.item.level < tool.range[1]) or (tool.range[2] and self.item.level >= tool.range[2]) then

        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))

        return "miss"

    end

    local chance = (self:chance().upgrade + tool.info.chance)

    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))

    if(tool.info.removeable == true) then

        doRemoveItem(item.uid, 1)

    end

    if chance * 100 > math.random(1, 10000) then

        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.completeNameLv[self.item.level + 1])))

        if (self.item.level + 1) >= self.broadcast then

            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, self.completeNameLv[self.item.level + 1]))

        end

        -- it says if the item's level is greater then 0 (meaning is level equal to 1 or more) if it is add 1 more

        -- if the current level equals 0 add 1 to it

        --self:setItemName(self.item.level > 0 and (self:getItemName():gsub(self.nameLv[self.item.level], ""))..self.nameLv[self.item.level + 1] or self:getItemName().." "..self.nameLv[1])

        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())

        for key, value in pairs(self.attributes) do

            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then

                doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)

            end

        end

        return "success"

    else

        if item.itemid == 8300 then

            if self.item.level > 0 then

                -- this will remove any number with a + sign in front of it from the string

                --self:setItemName(self:getItemName():gsub((" "..self.nameLv[self.item.level]), ""))

                self:setItemName(self:getItemName():gsub(("%["..self.nameLv[self.item.level].."%] "), ""))

                for key, value in pairs(self.attributes) do

                    if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then

                        doItemSetAttribute(self.item.uid, key, getItemAttribute(self.item.uid, key) - self.item.level * value)

                    end

                end

            end

        else

            doRemoveItem(self.item.uid, 1)

        end

        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")

    end

end

from: TFS 0.X - Caracter [] bug on upgrade system (https://otland.net/threads/caracter-bug-on-upgrade-system.273485/#post-2634658)

and when a item got upgraded it name become:
[R] sabre, [B] sabre

like:
Code:
00:42 You see a [R] sabre (Atk:12, Def:10 +1).

I also have this system where players can put items on theirs arrow slot to sell on website market (trade off)

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


function itemExtractNameLevel(item_uid)

    local nameLv = {

        [1] = "[R]",

        [2] = "[G]",

        [3] = "[B]",

        [4] = "[W]",

        [5] = "[D]",

    }


    local name = getItemAttribute(item_uid, "name")

    local level = 0

    for lvl, flourish in ipairs(nameLv) do

        if name:find(flourish) then

            level = lvl

        end

    end

    return name, lvl, flourish

end


function getRarity(str)

    local value = 0

    local n = str:match("%[(.-)%]")

    if n == "R" then

       value = 1

    elseif n == "G" then

       value = 2

    elseif n == "B" then

       value = 3

    elseif n == "W" then

       value = 4

    elseif n == "D" 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)

        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, 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

 

            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

            doPlayerSetBalance(cid, getPlayerBalance(cid) - buy:getDataInt("cost"))

            updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))

            

            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

and i want to make it work together
it means: people can put upgraded items to sell on auction system

i already manage to store upgrade_level when players put items to sell
but i need some help to when others players buy the item it be created with the refin system

is anybody here know how to do it?
 
Solution
Code:
                -- | set atk,def,armor |
                print("buyed_item: " .. buyed_item)
                local buyed_item_uid = buyed_item.uid


Code:
buyed_item: 70002
Ok, seems like it return a uid, so you should be able to just put buyed_item where i told you to use buyed_item.uid

but for some reason buyed_item get nil.
Not sure if the getItemAttack() function exists in the engine

Try to search for that function inside your source

potinho

Active Member
Joined
Oct 11, 2009
Messages
526
Solutions
14
Reaction score
43
Location
Brazil
here's my contribuition, im using this upgrade system on my server, works perfectly.

Lua:
--[[

PERFECT UPGRADE SYSTEM
            2.0

Criado por Oneshot

É proibido a venda ou a cópia sem os devidos créditos desse script.

]]--

UpgradeHandler = {
levels = {
    [1] = {90, false, false},
    [2] = {80, false, false},
    [3] = {70, false, false},
    [4] = {55, true, false},
    [5] = {40, true, false},
    [6] = {30, true, false},
    [7] = {20, true, false},
    [8] = {10, true, true},
    [9] = {5, true, true},
    [10] = {3, true, true}
},
broadcast = 5,
attributes = {
    ["attack"] = 2,
    ["defense"] = 1,
    ["armor"] = 1
},
message = {
    console = "Trying to refine %s to level +%s with %s%% success rate.",
    success = "You have upgraded %s to level +%s",
    fail = "You have failed in upgrade of %s to level +%s",
    downgrade = "The upgrade level of %s has downgraded to +%s",
    erase = "The upgrade level of %s has been erased.",
    maxlevel = "The targeted %s is already on max upgrade level.",
    notupgradeable = "This item is not upgradeable.",
    broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
    invalidtool = "This is not a valid upgrade tool.",
    toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
},
tools = {
    [5114] = {range = {0, 10}, info = {chance = 0, removeable = true}},
},

isEquipment = function(self)
    local weaponType = self:getItemWeaponType()
    return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
end,

setItemName = function(self, name)
    return doItemSetAttribute(self.item.uid, "name", name)
end,

chance = function(self)
    local chances = {}
    chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
    chances.downgrade = (self.item.level * 5)
    chances.erase = (self.item.level * 3)

    return chances
end
}

function UpgradeHandler:new(item)
local obj, ret = {}
obj.item = {}

obj.item.level = 0
obj.item.uid = item.uid
for key, value in pairs(getItemInfo(item.itemid)) do
    obj.item[key] = value
end

ret = setmetatable(obj, {__index = function(self, index)
    if _G[index] then
        return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
            return self.callback(item.uid, ...)
        end}))
    else
        return UpgradeHandler[index]
    end
end})

if ret:isEquipment() then
    ret:update()
    return ret
end
return false
end

function UpgradeHandler:update()
self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end

function UpgradeHandler:refine(uid, item)
if not self.item then
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
    return "miss"
end    

local tool = self.tools[item.itemid]

if(tool == nil) then
    doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
    return "miss"
end

if(self.item.level > #self.levels) then
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
    return "miss"
end

if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
    return "miss"
end

local chance = (self:chance().upgrade + tool.info.chance)
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))

if(tool.info.removeable == true) then
    doRemoveItem(item.uid, 1)
end

if chance * 100 > math.random(1, 10000) then
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
    if (self.item.level + 1) >= self.broadcast then
        doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
    end

    self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
    for key, value in pairs(self.attributes) do
        if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
            doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
        end
    end
    return "success"
else
    if(self.levels[self.item.level][3] == true and (self:chance().erase * 100) > math.random(1, 10000)) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.erase:format(self.item.name))
        self:setItemName(self.item.name)
        for key, value in pairs(self.attributes) do
            if self.item[key] > 0 then
                doItemSetAttribute(self.item.uid, key, self.item[key])
            end
        end
    elseif(self.levels[self.item.level][2] == true and (self:chance().downgrade * 100) > math.random(1, 10000)) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.downgrade:format(self.item.name, (self.item.level - 1)))
        self:setItemName((self.item.level == 1 and self.item.name or self:getItemName():gsub("%+(%d+)", "+".. (self.item.level - 1))))
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item[key] + value * (self.item.level - 1)))
            end
        end
    else
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.fail:format(self.item.name, (self.item.level + 1)))
    end
    return "fail"
end
end
Post automatically merged:

and mine auction system, everything working:

Lua:
local config = {
        levelRequiredToAdd = 20,
        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])
                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(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 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(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(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
 
Last edited:
OP
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
here's my contribuition, im using this upgrade system on my server, works perfectly.

Lua:
--[[

PERFECT UPGRADE SYSTEM
            2.0

Criado por Oneshot

É proibido a venda ou a cópia sem os devidos créditos desse script.

]]--

UpgradeHandler = {
levels = {
    [1] = {90, false, false},
    [2] = {80, false, false},
    [3] = {70, false, false},
    [4] = {55, true, false},
    [5] = {40, true, false},
    [6] = {30, true, false},
    [7] = {20, true, false},
    [8] = {10, true, true},
    [9] = {5, true, true},
    [10] = {3, true, true}
},
broadcast = 5,
attributes = {
    ["attack"] = 2,
    ["defense"] = 1,
    ["armor"] = 1
},
message = {
    console = "Trying to refine %s to level +%s with %s%% success rate.",
    success = "You have upgraded %s to level +%s",
    fail = "You have failed in upgrade of %s to level +%s",
    downgrade = "The upgrade level of %s has downgraded to +%s",
    erase = "The upgrade level of %s has been erased.",
    maxlevel = "The targeted %s is already on max upgrade level.",
    notupgradeable = "This item is not upgradeable.",
    broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
    invalidtool = "This is not a valid upgrade tool.",
    toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
},
tools = {
    [5114] = {range = {0, 10}, info = {chance = 0, removeable = true}},
},

isEquipment = function(self)
    local weaponType = self:getItemWeaponType()
    return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
end,

setItemName = function(self, name)
    return doItemSetAttribute(self.item.uid, "name", name)
end,

chance = function(self)
    local chances = {}
    chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
    chances.downgrade = (self.item.level * 5)
    chances.erase = (self.item.level * 3)

    return chances
end
}

function UpgradeHandler:new(item)
local obj, ret = {}
obj.item = {}

obj.item.level = 0
obj.item.uid = item.uid
for key, value in pairs(getItemInfo(item.itemid)) do
    obj.item[key] = value
end

ret = setmetatable(obj, {__index = function(self, index)
    if _G[index] then
        return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
            return self.callback(item.uid, ...)
        end}))
    else
        return UpgradeHandler[index]
    end
end})

if ret:isEquipment() then
    ret:update()
    return ret
end
return false
end

function UpgradeHandler:update()
self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end

function UpgradeHandler:refine(uid, item)
if not self.item then
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
    return "miss"
end   

local tool = self.tools[item.itemid]

if(tool == nil) then
    doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
    return "miss"
end

if(self.item.level > #self.levels) then
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
    return "miss"
end

if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
    return "miss"
end

local chance = (self:chance().upgrade + tool.info.chance)
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))

if(tool.info.removeable == true) then
    doRemoveItem(item.uid, 1)
end

if chance * 100 > math.random(1, 10000) then
    doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
    if (self.item.level + 1) >= self.broadcast then
        doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))
    end

    self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
    for key, value in pairs(self.attributes) do
        if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
            doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
        end
    end
    return "success"
else
    if(self.levels[self.item.level][3] == true and (self:chance().erase * 100) > math.random(1, 10000)) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.erase:format(self.item.name))
        self:setItemName(self.item.name)
        for key, value in pairs(self.attributes) do
            if self.item[key] > 0 then
                doItemSetAttribute(self.item.uid, key, self.item[key])
            end
        end
    elseif(self.levels[self.item.level][2] == true and (self:chance().downgrade * 100) > math.random(1, 10000)) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.downgrade:format(self.item.name, (self.item.level - 1)))
        self:setItemName((self.item.level == 1 and self.item.name or self:getItemName():gsub("%+(%d+)", "+".. (self.item.level - 1))))
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item[key] + value * (self.item.level - 1)))
            end
        end
    else
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.fail:format(self.item.name, (self.item.level + 1)))
    end
    return "fail"
end
end
Post automatically merged:

and mine auction system, everything working:

Lua:
local config = {
        levelRequiredToAdd = 20,
        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])
                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(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 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(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(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

Both systems are working...
Upgrade and Auction

What i'm asking for help to someone more experient is:
Make possible to buy/sell upgraded items in auction system...
 

Liombera

Member
Joined
Mar 3, 2021
Messages
13
Reaction score
10
Hello you are looking to make possible buy/sell item on Auction House in game right ?
I dont know the version you are using, but for example on 12x, editing client , you can add, remove items into cyclopedia, market, rename items, category of market, if is weapon hand or bag, movable or not and much more, you will need do this one by one.
If is this, is editing client.
You will need select Market, trade as same client ID and show as with same client ID.

Obviously this is for client 12x for previous version i dont know,
editor.png
 
OP
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
Hello you are looking to make possible buy/sell item on Auction House in game right ?
I dont know the version you are using, but for example on 12x, editing client , you can add, remove items into cyclopedia, market, rename items, category of market, if is weapon hand or bag, movable or not and much more, you will need do this one by one.
If is this, is editing client.
You will need select Market, trade as same client ID and show as with same client ID.

Obviously this is for client 12x for previous version i dont know,
View attachment 56879

Auction house? Idk what is it...
What i want to do is to make possible in auction talkaction...

There is no market in my server, i'm using 8.60 version
 
OP
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
Somehow i have to bring the upgrade part from upgrade system:
Code:
    if chance * 100 > math.random(1, 10000) then
        doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.completeNameLv[self.item.level + 1])))
        if (self.item.level + 1) >= self.broadcast then
            doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, self.completeNameLv[self.item.level + 1]))
        end
        -- it says if the item's level is greater then 0 (meaning is level equal to 1 or more) if it is add 1 more
        -- if the current level equals 0 add 1 to it
        --self:setItemName(self.item.level > 0 and (self:getItemName():gsub(self.nameLv[self.item.level], ""))..self.nameLv[self.item.level + 1] or self:getItemName().." "..self.nameLv[1])
        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())
        for key, value in pairs(self.attributes) do
            if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
                doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
            end
        end
        return "success"

To put on buy from auction system:
Code:
    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

            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
            doPlayerSetBalance(cid, getPlayerBalance(cid) - buy:getDataInt("cost"))
            updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))
          
            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

By
Code:
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
 
Last edited:
OP
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
By looking a script from @Mummrik

I could manage to make the item name works

Now its setting the rigth name when item is upgraded, but i still need to set the atk,def,armor atributes and i don't know how to do :(

Full talkaction:
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, 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

Code part:
Code:
            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 stats |
                -- 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

Is anybody here knows how to do the ATK/DEF/ARMOR part?
Post automatically merged:

The full script now is:
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
        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, ammoItem.uid, itemcount)
        local thing = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
        if thing.uid > 0 then
            doRemoveItem(thing.uid)
        end

        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

I need some help to when player buys (if(t[1] == "buy") then)
I besides change the item name with upgrade name
(
-- | 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())
)

it should change the stats (atk/def/armor) too

Is anybody know how to do it?
 
Last edited:

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
By looking a script from @Mummrik

I could manage to make the item name works

Now its setting the rigth name when item is upgraded, but i still need to set the atk,def,armor atributes and i don't know how to do :(

Is anybody here knows how to do the ATK/DEF/ARMOR part?
Post automatically merged:

The full script now is:
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
        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, ammoItem.uid, itemcount)
        local thing = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
        if thing.uid > 0 then
            doRemoveItem(thing.uid)
        end

        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

I need some help to when player buys (if(t[1] == "buy") then)
I besides change the item name with upgrade name
(
-- | 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())
)

it should change the stats (atk/def/armor) too

Is anybody know how to do it?
it looks like you have commented out the part where you set the atk/def/arm attribute in the last script you posted

Only the set name attribute is active

Edit:

I did find this lua functions, Im not sure if you should set the attribute or set the atk/def/arm value on the item

Lua:
    // Set  
    setItemAttack(uid, attack)
    setItemExtraAttack(uid, extraattack)
    setItemDefense(uid, defense)
    setItemArmor(uid, armor)
    setItemExtraDefense(uid, extradefense)
    setItemAttackSpeed(uid, attackspeed)
    setItemHitChance(uid, hitChance)
    setItemShootRange(uid, shootRange)

    // Get
    getItemAttack(uid)
    getItemExtraAttack(uid)
    getItemDefense(uid)
    getItemExtraDefense(uid)
    getItemArmor(uid)
    getItemAttackSpeed(uid)
    getItemHitChance(uid)
    getItemShootRange(uid)
 
Last edited:
OP
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
it looks like you have commented out the part where you set the atk/def/arm attribute in the last script you posted

Only the set name attribute is active

Edit:

I did find this lua functions, Im not sure if you should set the attribute or set the atk/def/arm value on the item

Lua:
    // Set 
    setItemAttack(uid, attack)
    setItemExtraAttack(uid, extraattack)
    setItemDefense(uid, defense)
    setItemArmor(uid, armor)
    setItemExtraDefense(uid, extradefense)
    setItemAttackSpeed(uid, attackspeed)
    setItemHitChance(uid, hitChance)
    setItemShootRange(uid, shootRange)

    // Get
    getItemAttack(uid)
    getItemExtraAttack(uid)
    getItemDefense(uid)
    getItemExtraDefense(uid)
    getItemArmor(uid)
    getItemAttackSpeed(uid)
    getItemHitChance(uid)
    getItemShootRange(uid)

I've tried this:
Code:
                local buyitem_atk = getItemAttack(buyed_item)
                if buyitem_atk > 0 then
                    setItemAttack(buyed_item, buyitem_atk + (upgraded_level * 3))
                end
                local buyitem_def = getItemDefense(buyed_item)
                if buyitem_def > 0 then
                    setItemDefense(buyed_item, buyitem_def + (upgraded_level * 2))
                end
                local buyitem_armor = getItemArmor(buyed_item)
                if buyitem_armor > 0 then
                    setItemArmor(buyed_item, buyitem_armor + (upgraded_level * 1))
                end

full 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
        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, ammoItem.uid, itemcount)
        local thing = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
        if thing.uid > 0 then
            doRemoveItem(thing.uid)
        end

        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 buyitem_atk = getItemAttack(buyed_item)
                if buyitem_atk > 0 then
                    setItemAttack(buyed_item, buyitem_atk + (upgraded_level * 3))
                end
                local buyitem_def = getItemDefense(buyed_item)
                if buyitem_def > 0 then
                    setItemDefense(buyed_item, buyitem_def + (upgraded_level * 2))
                end
                local buyitem_armor = getItemArmor(buyed_item)
                if buyitem_armor > 0 then
                    setItemArmor(buyed_item, buyitem_armor + (upgraded_level * 1))
                end
                -- 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

but shows this error on console:
Code:
[8:46:41.051] [Error - TalkAction Interface] 
[8:46:41.051] data/talkactions/scripts/auctionsystem.lua:onSay
[8:46:41.051] Description: 
[8:46:41.051] data/talkactions/scripts/auctionsystem.lua:205: attempt to call global 'getItemAttack' (a nil value)
[8:46:41.052] stack traceback:
[8:46:41.052]     data/talkactions/scripts/auctionsystem.lua:205: in function <data/talkactions/scripts/auctionsystem.lua:59>
 

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
I've tried this:
Code:
                local buyitem_atk = getItemAttack(buyed_item)
                if buyitem_atk > 0 then
                    setItemAttack(buyed_item, buyitem_atk + (upgraded_level * 3))
                end
                local buyitem_def = getItemDefense(buyed_item)
                if buyitem_def > 0 then
                    setItemDefense(buyed_item, buyitem_def + (upgraded_level * 2))
                end
                local buyitem_armor = getItemArmor(buyed_item)
                if buyitem_armor > 0 then
                    setItemArmor(buyed_item, buyitem_armor + (upgraded_level * 1))
                end

full 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
        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, ammoItem.uid, itemcount)
        local thing = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
        if thing.uid > 0 then
            doRemoveItem(thing.uid)
        end

        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 buyitem_atk = getItemAttack(buyed_item)
                if buyitem_atk > 0 then
                    setItemAttack(buyed_item, buyitem_atk + (upgraded_level * 3))
                end
                local buyitem_def = getItemDefense(buyed_item)
                if buyitem_def > 0 then
                    setItemDefense(buyed_item, buyitem_def + (upgraded_level * 2))
                end
                local buyitem_armor = getItemArmor(buyed_item)
                if buyitem_armor > 0 then
                    setItemArmor(buyed_item, buyitem_armor + (upgraded_level * 1))
                end
                -- 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

but shows this error on console:
Code:
[8:46:41.051] [Error - TalkAction Interface]
[8:46:41.051] data/talkactions/scripts/auctionsystem.lua:onSay
[8:46:41.051] Description:
[8:46:41.051] data/talkactions/scripts/auctionsystem.lua:205: attempt to call global 'getItemAttack' (a nil value)
[8:46:41.052] stack traceback:
[8:46:41.052]     data/talkactions/scripts/auctionsystem.lua:205: in function <data/talkactions/scripts/auctionsystem.lua:59>
is "buyed_item" a uid? else try buyed_item.uid
 
OP
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
is "buyed_item" a uid? else try buyed_item.uid

I don't know

---

Like this:
Code:
                -- | set atk,def,armor |
                local buyed_item_uid = buyed_item.uid
                local buyitem_atk = getItemAttack(buyed_item_uid)
                if buyitem_atk > 0 then
                    setItemAttack(buyed_item_uid, buyitem_atk + (upgraded_level * 3))
                end
                local buyitem_def = getItemDefense(buyed_item_uid)
                if buyitem_def > 0 then
                    setItemDefense(buyed_item_uid, buyitem_def + (upgraded_level * 2))
                end
                local buyitem_armor = getItemArmor(buyed_item_uid)
                if buyitem_armor > 0 then
                    setItemArmor(buyed_item_uid, buyitem_armor + (upgraded_level * 1))
                end
?

Shows
Code:
[9:25:15.263] [Error - TalkAction Interface] 
[9:25:15.263] data/talkactions/scripts/auctionsystem.lua:onSay
[9:25:15.263] Description: 
[9:25:15.263] data/talkactions/scripts/auctionsystem.lua:205: attempt to index local 'buyed_item' (a number value)
[9:25:15.263] stack traceback:
[9:25:15.263]     data/talkactions/scripts/auctionsystem.lua:205: in function <data/talkactions/scripts/auctionsystem.lua:59>
 

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
I don't know

---

Like this:
Code:
                -- | set atk,def,armor |
                local buyed_item_uid = buyed_item.uid
                local buyitem_atk = getItemAttack(buyed_item_uid)
                if buyitem_atk > 0 then
                    setItemAttack(buyed_item_uid, buyitem_atk + (upgraded_level * 3))
                end
                local buyitem_def = getItemDefense(buyed_item_uid)
                if buyitem_def > 0 then
                    setItemDefense(buyed_item_uid, buyitem_def + (upgraded_level * 2))
                end
                local buyitem_armor = getItemArmor(buyed_item_uid)
                if buyitem_armor > 0 then
                    setItemArmor(buyed_item_uid, buyitem_armor + (upgraded_level * 1))
                end
?

Shows
Code:
[9:25:15.263] [Error - TalkAction Interface]
[9:25:15.263] data/talkactions/scripts/auctionsystem.lua:onSay
[9:25:15.263] Description:
[9:25:15.263] data/talkactions/scripts/auctionsystem.lua:205: attempt to index local 'buyed_item' (a number value)
[9:25:15.263] stack traceback:
[9:25:15.263]     data/talkactions/scripts/auctionsystem.lua:205: in function <data/talkactions/scripts/auctionsystem.lua:59>
Could you print(buyed_item) on the line above where it crash and see what it returns

Edit:
And yes looks right, but seems like buyed_item isnt what i thought it was
 
OP
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
Code:
                -- | set atk,def,armor |
                print("buyed_item: " .. buyed_item)
                local buyed_item_uid = buyed_item.uid


Code:
buyed_item: 70002
 

Mummrik

Hey!
Joined
Oct 22, 2007
Messages
707
Solutions
28
Reaction score
126
Location
Sweden
Code:
                -- | set atk,def,armor |
                print("buyed_item: " .. buyed_item)
                local buyed_item_uid = buyed_item.uid


Code:
buyed_item: 70002
Ok, seems like it return a uid, so you should be able to just put buyed_item where i told you to use buyed_item.uid

but for some reason buyed_item get nil.
Not sure if the getItemAttack() function exists in the engine

Try to search for that function inside your source
 
Solution
OP
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
Ok, seems like it return a uid, so you should be able to just put buyed_item where i told you to use buyed_item.uid

but for some reason buyed_item get nil.
Not sure if the getItemAttack() function exists in the engine

Try to search for that function inside your source

ty
 
Top