Advertisement
Guest User

Trade Off tfs 1.2 - v2.0

a guest
Aug 24th, 2016
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.32 KB | None | 0 0
  1. local config = {
  2.     level_add = 20,
  3.     max_ofertas = 5,
  4.     ofertas_pz = true,
  5.     itens_bloqueados = {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}
  6. }
  7. function onSay(player, words, param)
  8.     if (param == 'saldo') then
  9.         local consulta = db.storeQuery("SELECT * FROM `players` WHERE `id` = " .. player:getGuid() .. ";")
  10.         local saldo = result.getNumber(consulta, "auction_balance")
  11.         player:sendTextMessage(MESSAGE_INFO_DESCR, "Seu saldo é de " .. saldo .. " gps de suas vendas no mercado!")
  12.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Seu saldo é de " .. saldo .. " gps de suas vendas no mercado!")
  13.         return true
  14.     end
  15.     if(param == '') or (param == 'info') then
  16.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Comandos para utilizar este sistema:\n!oferta saldo\nUse este comando para verificar o saldo de suas vendas.\n!oferta add, nomedoitem, preço, qtd\nexemplo: !oferta add,plate armor,500,1\n\n\n!oferta comprar,id_da_compra\nexemplo: !oferta comprar,1943\n\n\n!oferta remover,id_da_compra\nexemplo: !oferta remover,1943\n\n\n!oferta sacar, qtd\nexemplo: !oferta sacar, 1000.\n")
  17.         return true
  18.     end
  19.     local split = param:split(",")
  20.     if split[2] == nil  then
  21.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Parâmetros necessários. Use !oferta info para mais informações!")
  22.         return false
  23.     end
  24.     split[2] = split[2]:gsub("^%s*(.-)$", "%1")
  25.     _BUSCA_DB = db.storeQuery("SELECT * FROM `auction_system` WHERE `player` = " .. player:getGuid())
  26.     if(split[1] == "add") then
  27.         if(not tonumber(split[3]) or (not tonumber(split[4]))) then
  28.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Use somente números.")
  29.             return true
  30.         end
  31.         if(string.len(split[3]) > 7 or (string.len(split[4]) > 3)) then
  32.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Este preço ou a quantidade itens é muito alta.")
  33.             return true
  34.         end
  35.         local itemType, item_s = ItemType(split[2]), ItemType(split[2]):getId()
  36.         if(not item_s) then
  37.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "O item "..itemType.." não existe!")
  38.             return true
  39.         end
  40.         if(player:getLevel() < config.level_add) then
  41.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas vcê precisa de level igual ou superior a (" .. config.level_add .. ") para continuar.")
  42.             return true
  43.         end
  44.         if(isInArray(config.itens_bloqueados, item_s)) then
  45.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você não pode adicionar este item.")
  46.             return true
  47.         end
  48.         if(player:getItemCount(item_s) < tonumber(split[4])) then
  49.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas você não tem este item.")
  50.             return true
  51.         end
  52.         local amount, tmp_BUSCA_DB  = 0, _BUSCA_DB
  53.         while tmp_BUSCA_DB ~= false do
  54.             tmp_BUSCA_DB = result.next(_BUSCA_DB)
  55.             amount = amount + 1
  56.         end
  57.         if _BUSCA_DB ~= false then
  58.             local limit = amount >= config.max_ofertas
  59.             if limit then
  60.                 player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas você atingiu o limite máximo(" .. config.max_ofertas .. ") de publicações de venda de itens.")
  61.                 return true
  62.             end
  63.             if(config.SendOffersOnlyInPZ) then    
  64.             if(not getTilePzInfo(player:getPosition())) then
  65.                 player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas você só pode usar este comando estando em protection zone.")
  66.                 return true
  67.             end
  68.         end
  69.     end
  70.     if(tonumber(split[4]) < 1 or (tonumber(split[3]) < 1)) then
  71.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas você precisa informar um número maior que 0.")
  72.         return true
  73.     end
  74.     local itemcount, costgp = math.floor(split[4]), math.floor(split[3])
  75.     player:removeItem(item_s, itemcount)
  76.     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() .. ")")
  77.     player:sendTextMessage(MESSAGE_INFO_DESCR, "Parabéns! Você adicionou para à venda " .. itemcount .." " .. split[2] .." por " .. costgp .. " gps!")
  78. end
  79. if(split[1] == "comprar") then
  80.     _BUSCA_DB = db.storeQuery("SELECT * FROM `auction_system` WHERE `id` = ".. tonumber(split[2]))
  81.     local player_id, player_vendas, item_ids, costs, item_names, counts = player:getGuid(), result.getNumber(_BUSCA_DB, "player"), result.getNumber(_BUSCA_DB, "item_id"), result.getNumber(_BUSCA_DB, "cost"), result.getString(_BUSCA_DB, "item_name"), result.getNumber(_BUSCA_DB, "count")
  82.    
  83.     if(not tonumber(split[2])) then
  84.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas somente números são aceitos.")
  85.         return true
  86.     end
  87.  
  88.     if(_BUSCA_DB ~= false) then
  89.         local total_custo = costs - player:getMoney()
  90.         if(player:getMoney() < costs) then
  91.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas você não possuí a quantia necessária para comprar. São necessários: "..costs.."gps para comprar o item: "..item_names..". Você tem: " .. player:getMoney() .. "gps. Você precisa de: "..total_custo.." gps.")
  92.             return true
  93.         end
  94.         if(player_id == player_vendas) then
  95.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas você não pode comprar seu próprio item.")
  96.         return true
  97.     end
  98.         if player:removeMoney(costs) then
  99.             if(isItemStackable((item_ids))) then
  100.                 player:addItem(item_ids, counts)
  101.             else
  102.                 for i = 1, count do
  103.                     player:addItem(item_ids, 1)
  104.                 end
  105.             end
  106.             db.query("DELETE FROM `auction_system` WHERE `id` = " .. split[2] .. ";")
  107.             player:sendTextMessage(MESSAGE_INFO_DESCR, "Parabéns! Você comprou " .. counts .. " ".. item_names .. " por " .. costs .. " gps com sucesso!")
  108.             db.query("UPDATE `players` SET `auction_balance` = `auction_balance` + " .. costs .. " WHERE `id` = " .. player_vendas .. ";")
  109.         end
  110. else
  111.     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas o ID "..split[2].." não existe!.")
  112. end
  113. end
  114.  
  115. if(split[1] == "remover") then
  116.     local _BUSCA_DB = db.storeQuery("SELECT * FROM `auction_system` WHERE `id` = ".. tonumber(split[2]))
  117.     local player_id, player_vendas, item_ids, costs, item_names, counts = player:getGuid(), result.getNumber(_BUSCA_DB, "player"), result.getNumber(_BUSCA_DB, "item_id"), result.getNumber(_BUSCA_DB, "cost"), result.getString(_BUSCA_DB, "item_name"), result.getNumber(_BUSCA_DB, "count")
  118.     if((not tonumber(split[2]))) then
  119.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas somente números são aceitos.")
  120.         return true
  121.     end
  122.     if(config.SendOffersOnlyInPZ) then    
  123.     if(not getTilePzInfo(player:getPosition())) then
  124.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must be in PZ area when you remove offerts from database.")
  125.         return true
  126.     end
  127. end  
  128. if(_BUSCA_DB ~= false) then
  129.     if(player_id == player_vendas) then
  130.     db.query("DELETE FROM `auction_system` WHERE `id` = " .. split[2] .. ";")
  131.     if(isItemStackable(item_ids)) then
  132.         player:addItem(item_ids, counts)
  133.     else
  134.         for i = 1, counts do
  135.             player:addItem(item_ids, 1)
  136.         end
  137.     end
  138.     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Parabéns! A oferta "..split[2].." foi removida com sucesso do mercado.\nVocê recebeu: "..counts.." "..item_names..".")
  139. else
  140.     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas essa oferta não é sua.")
  141. end
  142. result.free(resultado)
  143. else
  144.     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas este ID não existe.")
  145. end
  146. end
  147. if(split[1] == "sacar") then
  148.     if((not tonumber(split[2]))) then
  149.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Desculpe, mas somente números são aceitos.")
  150.         return true
  151.     end
  152.     local balance = db.storeQuery("SELECT * FROM `players` WHERE `id` = " .. player:getGuid() .. ";")
  153.     local auction_balance = result.getNumber(balance, "auction_balance")
  154.     if(auction_balance < 1) then
  155.         player:sendTextMessage(MESSAGE_INFO_DESCR, "Você não possuí saldo suficiente para sacar.")
  156.         result.free(balance)
  157.         return true
  158.     end
  159.     local tz = auction_balance - split[2]
  160.     player:sendTextMessage(MESSAGE_INFO_DESCR, "Você sacou " .. split[2] .. " gps de suas vendas no mercado! Seu saldo é de: "..tz.."gps.")
  161.     player:addMoney(tz)
  162.     db.query("UPDATE `players` SET `auction_balance` = ".. tz .." WHERE `id` = " .. player:getGuid() .. ";")
  163.     result.free(balance)
  164. end
  165.  
  166. return true
  167. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement