Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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(player, words, param)
- if(param == '') then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
- return true
- end
- local split = param:split(",")
- if(split[1] == "add") then
- if split[2] == null then
- return player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
- end
- if((not split[2]) or (not split[3]) or (not split[4])) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
- return true
- end
- if(not tonumber(split[3]) or (not tonumber(split[4]))) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You don't set valid price or items count.")
- return true
- end
- if(string.len(split[3]) > 7 or (string.len(split[4]) > 3)) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "This price or item count is too high.")
- return true
- end
- local itemType = ItemType(split[2])
- local item_s = ItemType(split[2]):getId()
- if(not item_s) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.".. item_s .." ")
- return true
- end
- if(player:getLevel() < config.levelRequiredToAdd) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You don't have required (" .. config.levelRequiredToAdd .. ") level.")
- return true
- end
- if(isInArray(config.blocked_items, item_s)) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "This item is blocked.")
- return true
- end
- if(player:getItemCount(item_s) < tonumber(split[4])) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you don't have this item.")
- return true
- end
- local resultId = db.storeQuery("SELECT `id` FROM `auction_system` WHERE `player` = " .. player:getGuid())
- local qtd = result.getNumber(resultId, "id")
- local amount = 0
- local tmpResultId = resultId
- while tmpResultId ~= false do
- tmpResultId = result.next(resultId)
- amount = amount + 1
- end
- if resultId ~= false then
- local limit = amount >= config.maxOffersPerPlayer
- if limit then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sorry you can't add more offers (max. " .. config.maxOffersPerPlayer .. ")")
- return true
- end
- if(config.SendOffersOnlyInPZ) then
- if(not getTilePzInfo(player:getPosition())) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you add offert to database.")
- return true
- end
- end
- end
- if(tonumber(split[4]) < 1 or (tonumber(split[3]) < 1)) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have to type a number higher than 0.")
- return true
- end
- local itemcount, costgp = math.floor(split[4]), math.floor(split[3])
- player:removeItem(item_s, itemcount)
- db.query("INSERT INTO `auction_system` (`player`, `item_name`, `item_id`, `count`, `cost`, `date`) VALUES (" .. player:getGuid() .. ", \"" .. split[2] .. "\", " .. item_s .. ", " .. itemcount .. ", " .. costgp ..", " .. os.time() .. ")")
- player:sendTextMessage(MESSAGE_INFO_DESCR, "You successfully add " .. itemcount .." " .. split[2] .." for " .. costgp .. " gps to offerts database.")
- end
- if(split[1] == "comprar") then
- if split[2] == null then
- return player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
- end
- local resultado = db.storeQuery("SELECT * FROM `auction_system` WHERE `id` = ".. tonumber(split[2]))
- local player_id = player:getGuid()
- local player_vendas = result.getNumber(resultado, "player")
- local item_ids = result.getNumber(resultado, "item_id")
- local costs = result.getNumber(resultado, "cost")
- local item_ns = result.getNumber(resultado, "item_name")
- local item_names = getItemName(item_ids)
- local counts = result.getNumber(resultado, "count")
- if(not tonumber(split[2])) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
- return true
- end
- if(resultado ~= false) then
- if(player:getMoney() < costs) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enoguh GP.")
- return true
- end
- if(player_id == player_vendas) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can't buy your own items.")
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, " "..player_id.."\n"..player_vendas.." ")
- return true
- end
- if(player:getFreeCapacity() < getItemWeight(item_ids, counts))then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You try to buy a " .. item_names .. ". It weight " .. getItemWeightByUID(item_ids, counts) .. " cap oz. and you have only " .. player:getFreeCapacity() .. " oz. free capacity. Put some items to depot and try again.")
- return true
- end
- if(isItemStackable((item_ids))) then
- player:addItem(item_ids, counts)
- else
- for i = 1, count do
- player:addItem(item_ids, 1)
- end
- end
- player:removeMoney(costs)
- db.query("DELETE FROM `auction_system` WHERE `id` = " .. split[2] .. ";")
- player:sendTextMessage(MESSAGE_INFO_DESCR, "You bought " .. counts .. " ".. item_names .. " for " .. costs .. " gps!")
- db.query("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. costs .. " WHERE `id` = " .. player_vendas .. ";")
- else
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
- end
- end
- if(split[1] == "remover") then
- if split[2] == null then
- return player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
- end
- local resultado = db.storeQuery("SELECT * FROM `auction_system` WHERE `id` = ".. tonumber(split[2]))
- local player_id = player:getGuid()
- local player_vendas = result.getNumber(resultado, "player")
- local item_ids = result.getNumber(resultado, "item_id")
- local costs = result.getNumber(resultado, "cost")
- local item_ns = result.getNumber(resultado, "item_name")
- local item_names = getItemName(item_ids)
- local counts = result.getNumber(resultado, "count")
- if((not tonumber(split[2]))) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
- return true
- end
- if(config.SendOffersOnlyInPZ) then
- if(not getTilePzInfo(player:getPosition())) then
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you remove offerts from database.")
- return true
- end
- end
- if(resultado ~= false) then
- if(player:getGuid() == player_vendas) then
- db.query("DELETE FROM `auction_system` WHERE `id` = " .. split[2] .. ";")
- if(isItemStackable(item_ids)) then
- player:addItem(item_ids, counts)
- else
- for i = 1, counts do
- player:addItem(item_ids, 1)
- end
- end
- player:sendTextMessage(MESSAGE_INFO_DESCR, "Your offert has been deleted from offerts database.")
- else
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "This is not your offert!")
- end
- result.free(resultado)
- else
- player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Wrong ID.")
- end
- end
- if(split[1] == "sacar") then
- local balance = db.storeQuery("SELECT * FROM `players` WHERE `id` = " .. player:getGuid() .. ";")
- local auction_balance = result.getNumber(balance, "auction_balance")
- if(auction_balance < 1) then
- player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have money on your auction balance.")
- result.free(balance)
- return true
- end
- player:sendTextMessage(MESSAGE_INFO_DESCR, "You got " .. auction_balance .. " gps from auction system!")
- player:addMoney(auction_balance)
- db.query("UPDATE `players` SET `auction_balance` = '0' WHERE `id` = " .. player:getGuid() .. ";")
- result.free(balance)
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement