Advertisement
LuckOake

Quiz Npc

Dec 23rd, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | None | 0 0
  1. local focuses = {}
  2. local quiz = {}
  3.  
  4. local function isFocused(cid)
  5.     for i, v in pairs(focuses) do
  6.         if(v == cid) then
  7.             return true
  8.         end
  9.     end
  10.     return false
  11. end
  12.  
  13. local function addFocus(cid)
  14.     if(not isFocused(cid)) then
  15.         table.insert(focuses, cid)
  16.     end
  17. end
  18.  
  19. local function removeFocus(cid)
  20.     for i, v in pairs(focuses) do
  21.         if(v == cid) then
  22.             table.remove(focuses, i)
  23.             break
  24.         end
  25.     end
  26. end
  27.  
  28. local function lookAtFocus()
  29.     for i, v in pairs(focuses) do
  30.         if(isPlayer(v) == TRUE) then
  31.             doNpcSetCreatureFocus(v)
  32.             return
  33.         end
  34.     end
  35.     doNpcSetCreatureFocus(0)
  36. end
  37.  
  38. function onCreatureAppear(cid)
  39. end
  40.  
  41. function onCreatureDisappear(cid)
  42.     if(isFocused(cid)) then
  43.         selfSay("Hmph!")
  44.         removeFocus(cid)
  45.     end
  46. end
  47.  
  48. function onCreatureSay(cid, type, msg)
  49.     a = {
  50.         ["quiz 1"] = {id = 8110, cost = 5, uid = 8910, name = "quiz bag 1", r = "Muito Comum"},
  51.         ["quiz 2"] = {id = 8110, cost = 10, uid = 8911, name = "quiz bag 2", r = "Comum"},
  52.         ["quiz 3"] = {id = 8110, cost = 15, uid = 8912, name = "quiz bag 3", r = "Raro"},
  53.         ["quiz 4"] = {id = 8110, cost = 20, uid = 8913, name = "quiz bag 4", r = "Muito Raro"},
  54.         }
  55.    
  56.     b = a[msg]
  57.    
  58.     if msg == "hi" and not isFocused(cid) then
  59.         selfSay("Bem vindo, ".. getCreatureName(cid) ..".", cid, TRUE)
  60.         selfSay("Olá, deseja ver o que eu vendo? Fale {offer}.", cid)
  61.         addFocus(cid)
  62.     elseif isFocused(cid) and msg == "offer" or msg == "trade" then
  63.         selfSay("Eu vendo {quiz 1} bag por 5 Quiz Points, {quiz 2} bag por 10 Quiz Points, {quiz 3} bag por 15 Quiz Points e {quiz 4} bag por 20 Quiz Points.", cid)
  64.     elseif b then
  65.         selfSay("Você deseja comprar 1 quiz bag de raridade "..b.r.." por "..b.cost.." acertos?", cid)
  66.         quiz[cid] = b
  67.     elseif msg == "yes" and quiz[cid] then
  68.         if getPlayerStorageValue(cid, 8914) < quiz[cid].cost then
  69.             return selfSay("Você não possui pontos suficientes.", cid)
  70.         end
  71.         setPlayerStorageValue(cid, 8914, getPlayerStorageValue(cid, 8914)-quiz[cid].cost)
  72.         bag2 = doPlayerAddItem(cid, 8110, 1)
  73.         doItemSetAttribute(bag2, "uid", quiz[cid].uid)
  74.         doItemSetAttribute(bag2, "name", quiz[cid].name)
  75.         selfSay("Você comprou 1 quiz bag de raridade "..quiz[cid].r.." por "..quiz[cid].cost.." acertos.", cid)
  76.         quiz[cid] = nil
  77.     elseif isFocused(cid) and (msg == "bye" or msg == "goodbye" or msg == "cya") then
  78.         selfSay("Goodbye!", cid, TRUE)
  79.         removeFocus(cid)
  80.     end
  81. end
  82.  
  83. function onPlayerCloseChannel(cid)
  84.     if isFocused(cid) then
  85.         selfSay("Hmph!")
  86.         removeFocus(cid)
  87.     end
  88. end
  89.  
  90. function onThink()
  91.     for i, focus in pairs(focuses) do
  92.         if(isCreature(focus) == FALSE) then
  93.             removeFocus(focus)
  94.         else
  95.             local distance = getDistanceTo(focus) or -1
  96.             if((distance > 4) or (distance == -1)) then
  97.                 selfSay("Hmph!")
  98.                 removeFocus(focus)
  99.             end
  100.         end
  101.     end
  102.     lookAtFocus()
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement