• 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 + bank

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
Bank NPC script:
http://hastebin.com/ecenupivug.lua

Auction Talkaction script:
http://hastebin.com/turofepoke.lua
From (https://otland.net/threads/offline-player-to-player-item-trader-auction-system.51447/)

I want to remove this auction_balance its useless
PHP:
ALTER TABLE `players` DROP `auction_balance`;
Should be better use only bank balance

What i need to put to when player buy:
PHP:
if(t[1] == "buy") then

No send money to auction_balance like is
PHP:
db.executeQuery("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")

Send money to player bank...
Link transfer (bank system)...

So i could remove it too
PHP:
        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
 
I see you have a habit of deleting things from the database but then are confused of how to edit the scripts which access the database.
What i need to put to when player buy:
Stop deleting things from the database before the script has been edited.

Edit script 1st. then delete columns in the database if it calls for that.

I had a friend who use to do that all the time, I would write him a script for his site and he would "edit" it, then he would complain it doesn't work, because he removed the very things that made the script function.

Look if you don't know what you are doing, don't delete things from the script, post the script and say hey I have this script and this is what it does. Could someone alter it so it does this instead.
 
Last edited:
I see you have a habit of deleting things from the database but then are confused of how to edit the scripts which access the database.

Stop deleting things from the database before the script has been edited.

Edit script 1st. then delete columns in the database if it calls for that.

I had a friend who use to do that all the time, I would write him a script for his site and he would "edit" it, then he would complain it doesn't work, because he removed the very things that made the script function.

Look if you don't know what you are doing, don't delete things from the script, post the script and say hey I have this script and this is what it does. Could someone alter it so it does this instead.

Thank you, but have no problem, my server is not open i waiting to fix this 2 scripts before open
https://otland.net/threads/auction-system-bank.246665/
https://otland.net/threads/delete-from-mysql-when-kill.246663/

It weighs in the database, there is no reason to this auction_balance if i can use bank balance like is in global tibia (maybe script author made it to servers who no use bank system)
i just want make a DB more light, clean
 
I dont know how to do, but its just need to find a way to change
PHP:
db.executeQuery("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. buy:getDataInt("cost") .. " WHERE `id` = " .. buy:getDataInt("player") .. ";")

To:
PHP:
local v = getCreatureByName(transfer[cid])
if v then -- player online
    doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
    updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))
    doPlayerSetBalance(v, getPlayerBalance(v) + count[cid])
    updatePlayerBalance(getCreatureName(v), getPlayerBalance(v))
    npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. getCreatureName(v) .. '.', cid)
elseif findPlayer(transfer[cid]):lower() == transfer[cid]:lower() then  -- player offline
    doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
    updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))
    db.query('UPDATE players SET balance=balance+' .. count[cid] .. ' WHERE name=' .. db.escapeString(transfer[cid]) .. ' LIMIT 1')
    npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. findPlayer(transfer[cid]) .. '.', cid)
else
    npcHandler:say('This player does not exist.', cid)
end
 
Here you go: (thats the new script)
Code:
--[[
Offline player to player item trader (Auction System) by vDk
Script version: 1.2a [ -- FIXED CLONE ITEMS BUG -- ]
]]--
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], false)
        if(not item) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.")
            return true
        end

        if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
            return true
        end

        if(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!")
            
            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
 
Here you go: (thats the new script)
Code:
--[[
Offline player to player item trader (Auction System) by vDk
Script version: 1.2a [ -- FIXED CLONE ITEMS BUG -- ]
]]--
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], false)
        if(not item) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.")
            return true
        end

        if(getPlayerLevel(cid) < config.levelRequiredToAdd) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
            return true
        end

        if(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!")
           
            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

THANK YOU!!
sorry to this long, i trough no one know that, thank you a lot!!!!
 
Back
Top