• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Auction System + Upgrade System

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
I do have 2 system i found here on forum...
I love both and i want to use both together, but idk how, so i need help of someone who have experience in here

system 1: upgrade your items, one by one, add more armor,attack,defense...
/lib/upgradesystem.lua
hastebin

system 2: auction system, is like a market, trade offline to a 8.60 server
/talkactions/scripts/auctionsystem.lua
hastebin
(from here: TalkAction - Offline player to player item trader (Auction System). , allmost all bigs ot 8.6 uses this, so if someone help me could help a lot others guys)

What is my problem? If i put a upgraded item on auction system it lose the upgrade...

What do i need to do?
My idea was add a new row:
Code:
ALTER TABLE `auction_system` ADD `upgrade_level` INT NOT NULL DEFAULT '0' AFTER `date`;

And if item is upgraded change upgrade lvl to 1,2,3 and somehow uses it on add,buy,remove item from auction system
And shows on website
But i don't have experience enough to do alone, anybody can help?


Full script?
Perfect Upgrade System
 
Last edited:
Code:
--@Retorna el level de upgrade del item
--#Return number
function Item.getUpgradeLevel(item)
    local name = item:getName():split('+')
    if (#name > 1) then
        return math.abs(name[2])
    end
    return 0
end

example:
Code:
You see a sword +1 (Atk:14, Def:12 +1).
It weighs 35.00 oz.
^^^^
Code:
local level = item:getUpgradeLevel()
print(level) ==> 1
Uncompatible with TFS 0.4... Someone can transpose to 0.4 ? :D
 
Uncompatible with TFS 0.4... Someone can transpose to 0.4 ? :D

0.4
Lua:
function getItemLevel(uid)
    local split = string.explode(getItemName(uid), "+")
    if #split > 1 then
        return math.abs(split[2])
    end
    return 0
end
-- Example: You see sword +10 (Atk: 10).
local level = getItemLevel(item.uid)
print(level) --> 10
 
0.4
Lua:
function getItemLevel(uid)
    local split = string.explode(getItemName(uid), "+")
    if #split > 1 then
        return math.abs(split[2])
    end
    return 0
end
-- Example: You see sword +10 (Atk: 10).
local level = getItemLevel(item.uid)
print(level) --> 10

Very nice!! Sorry for my lack of knowledge, I should probably add this function to "data\lib\050-function.lua", right? But would you know how to incorporate it into the "auction_system"?? 🤔😅

Here is my auctionsystem.lua... Do I need to change many lines? Or not? 🤔

Lua:
local config = {
        levelRequiredToAdd = 1,
        maxOffersPerPlayer = 5,
        SendOffersOnlyInPZ = true,
        blocked_items = {2165, 2152, 2148, 2160, 2166, 2167, 2168, 2169, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2343, 2433, 2640, 6132, 6300, 6301, 9932, 9933, }
        }
function onSay(cid, words, param, channel)
        if(param == '') then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Type !offer help to learn how to use the "Trade Offline".')
                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, "The command is wrong, type !offer help to learn how to use correctly.")
                        return true
                end
                if(not tonumber(t[3]) or (not tonumber(t[4]))) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid price or items quantity.")
                        return true
                end
                if(string.len(t[3]) > 9 or (string.len(t[4]) > 3)) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The price or quantity of these items are too high, the maximum price for the item is de 999999999, and the maximum quantity is 3.")
                        return true
                end
                local item = getItemIdByName(t[2])
                if(not item) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "There is no item with this name.")
                        return true
                end
                if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be level (" .. config.levelRequiredToAdd .. ") to use offline trade.")
                        return true
                end
                if(isInArray(config.blocked_items, item)) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You cannot add this item.")
                        return true
                end
                if(getPlayerItemCount(cid, item) < (tonumber(t[4]))) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have this item.")
                        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, "You cannot make further offers as you have reached the limit of " .. config.maxOffersPerPlayer ".")
                        return true
                end
                if(config.SendOffersOnlyInPZ) then   
                        if(not getTilePzInfo(getPlayerPosition(cid))) then
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be in PZ (protection zone) to make an offert.")
                                return true
                        end
                end
                if(tonumber(t[4]) < 1 or (tonumber(t[3]) < 1)) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The price or number of items must be greater 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 added " .. itemcount .." " .. t[2] ..", for " .. costgp .. " gold coins.")
        end
        if(t[1] == "buy") then
                if(not tonumber(t[2])) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid ID. To verify a valid ID, type !offer list or !offer list, ItemName.")
                        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 enough gold coins.")
                                buy:free()
                                return true
                        end
                        if(getPlayerName(cid) == getPlayerNameByGUID(buy:getDataInt("player"))) then
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can't purchase your own offers, but can retrieve them by command !offer remove, ID.")
                                buy:free()
                                return true
                        end
                        if(getPlayerFreeCap(cid) < getItemWeightById(buy:getDataInt("item_id"), buy:getDataInt("count")))then
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You tried to buy " .. buy:getDataString("item_name") .. ". that weighs " .. getItemWeightById(buy:getDataInt("item_id"), buy:getDataInt("count")) .. "oz. But you only have " .. getPlayerFreeCap(cid) .. "oz.")
                                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, "Invalid ID.")
                end
        end
        if(t[1] == "remove") then
                if((not tonumber(t[2]))) then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid ID.")
                        return true
                end
                                if(config.SendOffersOnlyInPZ) then   
                                        if(not getTilePzInfo(getPlayerPosition(cid))) then
                                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must be in protection zone (PZ) to remove your offers.")
                                                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, "You removed an offer.")
                        else
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This offer isn't yours.")
                        end
                delete:free()
                else
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid 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 nothing to withdraw.")
                        balance:free()
                        return true
                end
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received " .. balance:getDataInt("auction_balance") .. " gps from Trade Offline!")
                doPlayerAddMoney(cid, balance:getDataInt("auction_balance"))
                db.executeQuery("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. getPlayerGUID(cid) .. ";")
                balance:free()
        end
        --[[ Tentativa de listar os itens sem o gesior ]]
        if(t[1] == "list" and (not t[2])) then
            local result = db.getResult("SELECT * FROM `auction_system` ORDER BY `auction_system`.`id` DESC")
            if result:getID() == -1 then
                return true
            end
            --[[local msg = "+-----------+\n" ..
                        "|  Trade Offline:  |\n" ..
                        "+-----------+\n\n" ]]
            local msg = ""
            local counter = 0   
            
            while true do
                local id = result:getDataString("id")
                local name = getPlayerNameByGUID(result:getDataString("player"))
                local item_name = getItemNameById(result:getDataString("item_id"))
                local count = result:getDataString("count")
                local custo = result:getDataString("cost")/1000
                local custo2 = result:getDataString("cost")
                --[[if isPlayer(cid) then
                    msg = ""..msg.."ID: "..id.." -Item: "..item_name.." -Quantidade: "..count.." -Preco: "..custo.."k("..custo2.."GP) -Dono: "..name.."\n"
                end ]]
                if isPlayer(cid) then
                    msg = "" ..msg.. "ID: " ..id.. " -amount: "..count.."x " ..item_name.. ", -price: "..custo.."K("..custo2.."GPs), owner: "..name.."\n"
                end
                if not result:next() then
                    break
                end
                if(counter==39) then
                    break
                end
                counter = counter + 1;
            end
            doPlayerPopupFYI(cid, msg) return true
        end
        if(t[1] == "list" and t[2] ~= nil) then
            local item = getItemIdByName(t[2])
            if(not item) then
                doMutePlayer(cid, 10)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The item with that name does not exist, you will be muted for 10 seconds. Be careful when typing the name of the item.")
                return true
            end
            local result = db.getResult("SELECT * FROM `auction_system` where `auction_system`.`item_id`=" ..item.. " ORDER BY `auction_system`.`cost` ASC")
            if result:getID() == -1 then
                return true
            end
            local msg = "+-----------+\n" ..
                        "|  Trade Offline:  |\n" ..
                        "+-----------+\n\n"
            local msg = ""
            local counter = 0   
            
            while true do
                local id = result:getDataString("id")
                local name = getPlayerNameByGUID(result:getDataString("player"))
                local item_name = getItemNameById(result:getDataString("item_id"))
                local count = result:getDataString("count")
                local custo = result:getDataString("cost")/1000
                local custo2 = result:getDataString("cost")
                if isPlayer(cid) then
                    msg = ""..msg.."ID: "..id.." -Item: "..item_name.." -amount: "..count.." -price: "..custo.."k("..custo2.."GP) -owner: "..name.."\n"
                end
                --[[ if isPlayer(cid) then
                    msg = "" ..msg.. "ID: " ..id.. " " ..item_name.. " Preco: " ..custo2.. "GP\n"
                end ]]
                if not result:next() then
                    break
                end
                if(counter==9) then
                    break
                end
                counter = counter + 1;
            end
            doPlayerPopupFYI(cid, msg) return true
        end
        --[[ Fim da listagem sem o Gesior ]]
        if(t[1] == "my") then
            local result = db.getResult("SELECT `auction_system`.* FROM `auction_system` JOIN `players` WHERE `auction_system`.`player` = `players`.`id` AND `players`.`name` = '"..getPlayerName(cid).."'")
            if result:getID() == -1 then
                doPlayerPopupFYI(cid, getPlayerName(cid)) return true
            end
            local msg = "+----------------+\n" ..
                        "| Your trade offers: |\n" ..
                        "+----------------+\n\n"
            local counter = 0   
            
            while true do
                local id = result:getDataString("id")
                local name = getPlayerNameByGUID(result:getDataString("player"))
                local item_name = getItemNameById(result:getDataString("item_id"))
                local count = result:getDataString("count")
                local custo = result:getDataString("cost")
                if isPlayer(cid) then
                    msg = ""..msg.."ID: "..id.." -Item: "..item_name.." -amount: "..count.." -price: "..custo.." GP\n"
                end
                --[[ if isPlayer(cid) then
                    msg = "" ..msg.. "ID: " ..id.. " " ..item_name.. " Preco: " ..custo2.. "GP\n"
                end ]]
                if not result:next() then
                    break
                end
                if(counter==9) then
                    break
                end
                counter = counter + 1;
            end
            doPlayerPopupFYI(cid, msg) return true
        end
        
        if(t[1] == "help") then
            local msg = "+--------------------------------------------------+\n" ..
                        "| !offer buy, ID - Purchase an offer\n" ..
                        '| !offer remove, ID - Remove your offer by ID\n' ..
                        '| !offer my - See all your offers in "Trade Offline"\n'..
                        "| !offer add, ItemName, PRICE, ItemAmount\n" ..
                        '| !offer withdraw - Withdraw all money from sellings in "Trade Offline"\n' ..
                        '| !offer list -- Shows the last 40 offers in "Trade Offline"\n' ..
                        "| !offer list, ItemName -- Shows the 10 cheapests items\n" ..
                        "+--------------------------------------------------+\n"
            doPlayerPopupFYI(cid, msg) return true
        end
        return true
end
 
Back
Top