Skymagnum

Leilao

May 12th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. function onSay(cid, words, param)
  2.  
  3. local config = {
  4.     acess = 4,
  5.     time = 5,
  6.     storage = {25601, 25602, 650213},
  7. }
  8.  
  9. function getWinnerLeilao()
  10.  
  11.     local w = tostring(getGlobalStorageValue(config.storage[1])):gsub(':', ''):explode(',')
  12.  
  13.     if not getPlayerByNameWildcard(w[4]) then
  14.         local item = doCreateItemEx(w[1]-1, w[2])
  15.         local x = doItemSetAttribute(item, "description", "Item comprado em leilão por "..w[3].." gps.")
  16.         doPlayerSendMailByName(w[4], item)
  17.     else
  18.         local x = doPlayerAddItem(getPlayerByNameWildcard(w[4]), w[1], w[2])
  19.         doItemSetAttribute(x, "description", "Item comprado em leilão por "..w[3].." gps.")
  20.     end
  21.  
  22.     doBroadcastMessage("O item ["..getItemNameById(w[1]).." : "..w[2].."] Foi vendido para o jogador "..w[4].." por "..w[3].." gps!")
  23.     setGlobalStorageValue(config.storage[1], -1)
  24.     setGlobalStorageValue(config.storage[2], -1)
  25.  
  26.     for _, pid in pairs(getPlayersOnline()) do
  27.         setPlayerStorageValue(pid, config.storage[3], -1)
  28.     end
  29.  
  30.     return db.executeQuery("DELETE FROM `player_storage` WHERE `key` = "..config.storage[3])
  31. end
  32.  
  33.     if words == "/leilao" then
  34.         if getPlayerAccess(cid) < config.acess then
  35.             doPlayerSendTextMessage(cid, 28, "Você não pode executar essa ação.") return true
  36.         end
  37.    
  38.     local t = string.explode(param, ",")
  39.  
  40.     if not tonumber(getGlobalStorageValue(config.storage[1])) then
  41.         doPlayerSendTextMessage(cid, 27, "Já há um leilão ativo no momento.") return true
  42.     elseif not tonumber(t[1]) or not tonumber(t[2]) or not tonumber(t[3]) then
  43.         doPlayerSendTextMessage(cid, 28, "Faltou parametro.")return true
  44.     elseif not isItemMovable(t[1]) then
  45.         doPlayerSendTextMessage(cid, 28, "Você não pode adicionar esse item no leilão.")return true
  46.     end
  47.  
  48.     setGlobalStorageValue(config.storage[1], ":"..t[1]..",:"..(isItemStackable(t[1]) and t[2] or 1)..",:"..t[3]..",:"..getCreatureName(cid))
  49.     setGlobalStorageValue(config.storage[2], os.time()+ config.time*60)
  50.     doBroadcastMessage("[Leilão] O item ["..getItemNameById(t[1]).." : "..(isItemStackable(t[1]) and t[2] or 1).."] Está em leilão até "..os.date("%X ", getGlobalStorageValue(config.storage[2])).."\nLance Minimo: "..t[3].." gps.")
  51.     addEvent(getWinnerLeilao, config.time * 1000 * 60)
  52.  
  53.     elseif words == "!lance" then
  54.         if tonumber(getGlobalStorageValue(config.storage[1])) then
  55.             doPlayerSendTextMessage(cid, 27, "Não tem nenhum leilão ativo no momento.") return true
  56.         end
  57.  
  58.     local s = tostring(getGlobalStorageValue(config.storage[1])):gsub(':', ''):explode(',')
  59.  
  60.     if param == "lista" then
  61.         doShowTextDialog(cid,s[1], "Item: "..getItemNameById(s[1]).."\n\nQuantidade: "..s[2].."\n\nMaior lance atual: "..s[3].."\n\nJogador: "..s[4].."\n\nPrazo Final: "..os.date("%X ", getGlobalStorageValue(config.storage[2]))) return true
  62.     elseif not tonumber(param) or tonumber(param) <= 0 or tonumber(param) > 9999999 then
  63.         doPlayerSendTextMessage(cid, 28, "digite um número válido.") return true
  64.     end
  65.  
  66. local li = getPlayerStorageValue(cid, config.storage[3]) < 0 and 0 or getPlayerStorageValue(cid, config.storage[3])
  67. local conta = (li + tonumber(param))
  68.  
  69.     if conta <= tonumber(s[3]) then
  70.         doPlayerSendTextMessage(cid, 28, "você tem que dar um lance maior que "..s[3].." gps") return true
  71.     elseif not doPlayerRemoveMoney(cid, tonumber(param)) then
  72.         doPlayerSendTextMessage(cid, 28, "você não tem gps suficientes para dar um lance") return true
  73.     end
  74.  
  75.     setPlayerStorageValue(cid, config.storage[3], conta)
  76.     setGlobalStorageValue(config.storage[1], ":"..s[1]..",:"..s[2]..",:"..conta..",:"..getCreatureName(cid))
  77.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Parabéns, agora você deu o maior lance de "..conta.." gps no item [Nome: "..getItemNameById(s[1]).."] [Count: "..s[2].."]")
  78.     end
  79.  
  80.     return true
  81. end
Advertisement
Add Comment
Please, Sign In to add comment