Advertisement
LuckOake

Quiz Talkaction

Dec 23rd, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.90 KB | None | 0 0
  1. function onSay(cid, words, param)
  2. onquiz_event = {
  3. storage_reply = 36201, -- global storage
  4. storage_check = 175201,
  5. storage_points = 175202,
  6. acess = 3
  7. }
  8.     if isInArray({'/quizpts','!quizpts','!quizpoints'}, words) then
  9.     return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você possui "..(getPlayerStorageValue(cid, onquiz_event.storage_points) <= 0 and 0 or getPlayerStorageValue(cid, onquiz_event.storage_points)).." pontos de quiz.")
  10.     elseif isInArray({'/openquiz','!openquiz','/abrirquiz'}, words) then
  11.         if getPlayerAccess(cid) < onquiz_event.acess then
  12.             doPlayerSendTextMessage(cid, 28, "Você não pode executar essa ação.") return true
  13.         end
  14.     local t = string.explode(param, ",")
  15.     if not tonumber(getGlobalStorageValue(onquiz_event.storage_reply)) then
  16.         doPlayerSendTextMessage(cid, 27, "Já há um quiz aberto no momento.") return true
  17.     elseif not t[1] or not t[2] then
  18.         doPlayerSendTextMessage(cid, 28, "Digite: comando pergunta,reposta.")return true
  19.     end
  20.         setGlobalStorageValue(onquiz_event.storage_reply, ":"..t[1]..",:"..t[2])
  21.         doBroadcastMessage("Quiz aberto com a seguinte pergunta: ["..t[1].."]\ndigite '/quiz resposta' para responder ou !quizinfo para saber mais.")
  22.     return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Quiz aberto com a pergunta "..t[1].." e resposta: "..t[2]..".")
  23.     elseif isInArray({'/quiz','!quiz'}, words) then
  24.     if not param or param == "" then
  25.         doPlayerSendCancel(cid, "Digite a resposta.") return true
  26.     elseif getPlayerAccess(cid) >= onquiz_event.acess then
  27.         doPlayerSendCancel(cid, "Staff não pode responder o quiz.") return true
  28.     elseif tonumber(getGlobalStorageValue(onquiz_event.storage_reply)) then
  29.         doPlayerSendCancel(cid, "Não há quiz aberto no momento.") return true
  30.     elseif getPlayerStorageValue(cid, onquiz_event.storage_check) >= 1 then
  31.         doPlayerSendCancel(cid, "Você já respondeu o quiz do momento.") return true
  32.     end
  33.     local s = tostring(getGlobalStorageValue(onquiz_event.storage_reply)):gsub(':', ''):explode(',')
  34.         setPlayerStorageValue(cid, onquiz_event.storage_check, 1)
  35.     if string.lower(param) ~= string.lower(s[2]) then
  36.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Você errou o quiz. Fale /quizpts para ver seus pontos.") return true
  37.     end
  38.         setPlayerStorageValue(cid, onquiz_event.storage_points, getPlayerStorageValue(cid, onquiz_event.storage_points) <= 0 and 1 or getPlayerStorageValue(cid, onquiz_event.storage_points)+1)
  39.     print("[QUIZ SYSTEM] "..getCreatureName(cid).." respondeu "..s[1]..". Certo.")
  40.     return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Você acertou o quiz. Você marcou 1 ponto. Fale /quizpts para ver seus pontos.")
  41.     elseif isInArray({'/closequiz','!closequiz','/fecharquiz'}, words) then
  42.     if getPlayerAccess(cid) < onquiz_event.acess then
  43.         doPlayerSendTextMessage(cid, 28, "Você não pode executar essa ação.") return true
  44.     end
  45.     for _, pid in ipairs(getPlayersOnline()) do
  46.         setPlayerStorageValue(pid, onquiz_event.storage_check, -1)
  47.     end
  48.         db.executeQuery("DELETE FROM `player_storage` WHERE `key` = "..onquiz_event.storage_check)
  49.     local s = tostring(getGlobalStorageValue(onquiz_event.storage_reply)):gsub(':', ''):explode(',')
  50.         doBroadcastMessage("Quiz fechado. Pergunta: "..s[1].."\nResposta: "..s[2])
  51.     return setGlobalStorageValue(onquiz_event.storage_reply, 0)
  52.     elseif isInArray({'/infoquiz','!infoquiz'}, words) then
  53.     if tonumber(getGlobalStorageValue(onquiz_event.storage_reply)) then
  54.         doPlayerSendCancel(cid, "Não há quiz aberto no momento.") return true
  55.     end
  56.     local s = tostring(getGlobalStorageValue(onquiz_event.storage_reply)):gsub(':', ''):explode(',')
  57.     return doPlayerPopupFYI(cid, "--[Quiz System]--\n\nPergunta: "..s[1].."\n\n"..(getPlayerAccess(cid) >= onquiz_event.acess and "Resposta: "..s[2] or "").."\n\nPara responder digite: /quiz resposta, exemplo: /quiz messi.\n\nOBS: Cuidado com espaços ou pontos no final da reposta.")
  58.     end
  59. return true
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement