Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.00 KB | None | 0 0
  1. --[[
  2. #### worthdavi
  3. #### 12/07/2019
  4. --]]
  5.  
  6. local moeda = 21400
  7.  
  8. local itens = {
  9.    [2798] = {valor = 25},
  10.    [20620] = {valor = 50},
  11.    [33082] = {valor = 50},
  12.    [33083] = {valor = 50},
  13.    [33084] = {valor = 50},
  14.    [33085] = {valor = 50},
  15.    [33086] = {valor = 50},
  16.    [33087] = {valor = 50},
  17.    [23588] = {valor = 100},
  18.    [16007] = {valor = 150},
  19.    [27063] = {valor = 150},
  20.    [27063] = {valor = 150}
  21. }
  22.  
  23. local clothes = {
  24.     -- [idF or idM] = {valor = x, idM = y, idF = z},
  25. }
  26.  
  27. local mounts = {
  28.     [44] = {valor = 250},
  29.     [45] = {valor = 250},
  30.     [37] = {valor = 250}
  31. }
  32.  
  33. local inicioDaLista = 0
  34. local fimDaLista = 4
  35.  
  36. local keywordHandler = KeywordHandler:new()
  37. local npcHandler = NpcHandler:new(keywordHandler)
  38. NpcSystem.parseParameters(npcHandler)
  39.  
  40. function onCreatureAppear(cid)          npcHandler:onCreatureAppear(cid)            end
  41. function onCreatureDisappear(cid)       npcHandler:onCreatureDisappear(cid)         end
  42. function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)        end
  43. function onThink()              npcHandler:onThink()                    end
  44.  
  45. local playerTopic = {}
  46. local function greetCallback(cid)
  47.     local player = Player(cid) 
  48.     if player then
  49.         npcHandler:setMessage(MESSAGE_GREET, "Hello, ".. player:getName() .."! With me you can buy {clothes}, {mounts}, {artifacts} and some {other stuff}, would you be interested?")
  50.         playerTopic[cid] = 1
  51.     end
  52.     npcHandler:addFocus(cid)
  53.     return true
  54. end
  55.  
  56. local valor = {}
  57. local quantidade = {}
  58. local itemName = {}
  59. local precoTotal = {}
  60. local itemId = {}
  61.  
  62. local function showItemsCatalog(table)
  63.     local max = 0
  64.     for _, k in pairs(table) do
  65.         max = max + 1
  66.     end
  67.     local msg = ""
  68.     local c = 0
  69.     for i, k in pairs(table) do
  70.         local virgula = ", "
  71.         if c ~= (max - 1) then
  72.             c = c + 1
  73.         else
  74.             virgula = ""
  75.         end
  76.         msg = msg .. "{".. ItemType(i):getName():lower() .. "}" .. virgula
  77.     end
  78.     return msg
  79. end
  80.  
  81. local function showMountCatalog(table)
  82.     local max = 0
  83.     for _, k in pairs(table) do
  84.         max = max + 1
  85.     end
  86.     local msg = ""
  87.     local c = 0
  88.     for i, k in pairs(table) do
  89.         local virgula = ", "
  90.         if c ~= (max - 1) then
  91.             c = c + 1
  92.         else
  93.             virgula = ""
  94.         end
  95.         msg = msg .. "{".. Mount(i):getName():lower() .. "}" .. virgula
  96.     end
  97.     return msg
  98. end
  99.  
  100. local function creatureSayCallback(cid, type, msg)
  101.     if not npcHandler:isFocused(cid) then
  102.         return false
  103.     end
  104.    
  105.     npcHandler.topic[cid] = playerTopic[cid]
  106.     local player = Player(cid)
  107.     local arrayProdutos = ""
  108.     local plural = ""
  109.    
  110.     local function sendHello(topic)
  111.         npcHandler:say({"Glad you were interested. I'm a different merchant ... My currency is based on the players participating in server events. Do you have event tokens?"}, cid)
  112.         npcHandler.topic[cid] = topic
  113.         playerTopic[cid]= topic
  114.     end
  115.    
  116.     if (msgcontains(msg, "artifacts") or msgcontains(msg, "items")) and (npcHandler.topic[cid] == 1) then
  117.         sendHello(2)
  118.     -- Prosseguindo com a partes de itens
  119.     elseif npcHandler.topic[cid] == 2 then
  120.         if msgcontains(msg, "sim") or msgcontains(msg, "yes") then
  121.             local arrayProdutos = showItemsCatalog(itens)      
  122.             npcHandler:say({"How nice! Then browse my catalog of artifacts and let me know if something interests you: ".. arrayProdutos .."."}, cid)
  123.             npcHandler.topic[cid] = 3
  124.             playerTopic[cid]= 3
  125.         end
  126.     elseif npcHandler.topic[cid] == 3 then
  127.         local itemType = ItemType(msg)
  128.         if not itemType then
  129.            npcHandler:say({"An error has ocurred, please contact an administrator."}, cid)
  130.            return false
  131.         end
  132.         local itensTable = itens[itemType:getId()]
  133.         if itensTable then
  134.             valor[cid] = itensTable.valor
  135.             itemName[cid] = msg
  136.             npcHandler:say({"Good choice! If you really want the ".. itemName[cid] ..", it will cost you ".. valor[cid] .." ".. ItemType(moeda):getName():lower() .." each. How many would you be interested in?"}, cid)
  137.             npcHandler.topic[cid] = 4
  138.             playerTopic[cid]= 4
  139.         else
  140.             npcHandler:say({"This item is not in my catalog."}, cid)
  141.         end    
  142.     elseif npcHandler.topic[cid] == 4 then
  143.         quantidade[cid] = tonumber(msg)
  144.         if quantidade[cid] then
  145.             if quantidade[cid] > 1 then
  146.                 plural = plural .. "s"
  147.             end
  148.             if quantidade[cid] >= 20 then
  149.                 npcHandler:say({"Calm down!! It doesn't fit in a bag!"}, cid)
  150.             else
  151.                 precoTotal[cid] = valor[cid]*quantidade[cid]
  152.                 npcHandler:say({"So you want ".. quantidade[cid] .." ".. itemName[cid] .. plural ..". Hmmmm, this will give a total of ".. precoTotal[cid] .." ".. ItemType(moeda):getName():lower() .."s. Do you accept?"}, cid)
  153.                 playerTopic[cid] = 5
  154.                 npcHandler.topic[cid] = 5
  155.             end
  156.         else
  157.             npcHandler:say({"I did not understand."}, cid)
  158.         end
  159.     elseif npcHandler.topic[cid] == 5 then
  160.         if msgcontains(msg, "yes") or msgcontains(msg, "sim") then
  161.             if player:getItemCount(moeda) >= precoTotal[cid] then                  
  162.                 itemId[cid] = ItemType(itemName[cid]):getId()
  163.                 -- Criando container no mailbox
  164.                 local parcel = player:getInbox():addItem(2596, 1, false, 1)
  165.                 parcel:addItem(1988, 1, false, 1):addItem(itemId[cid], quantidade[cid], false, 1)
  166.                 player:removeItem(moeda, precoTotal[cid])
  167.                 npcHandler:say({"Great. I will ask my delivery boy to leave the items in your mailbox."}, cid)                     
  168.             else
  169.                 npcHandler:say({"You don't have enough event tokens..."}, cid)
  170.                 npcHandler.topic[cid] = 1
  171.                 playerTopic[cid]= 1
  172.             end
  173.         end
  174.        
  175.     -- Prosseguindo com a parte de mounts
  176.     elseif (msgcontains(msg, "mount") or msgcontains(msg, "mounts")) and (npcHandler.topic[cid] == 1) then
  177.         sendHello(6)
  178.     elseif npcHandler.topic[cid] == 6 then
  179.         if msgcontains(msg, "sim") or msgcontains(msg, "yes") then
  180.             local arrayMounts = showMountCatalog(mounts)       
  181.             npcHandler:say({"How nice! Then browse my catalog of mounts and let me know if something interests you: ".. arrayMounts .."."}, cid)
  182.             npcHandler.topic[cid] = 7
  183.             playerTopic[cid]= 7
  184.         end
  185.     elseif npcHandler.topic[cid] == 7 then
  186.         local mount = Mount(msg)
  187.         if not mount then
  188.             npcHandler:say({"An error has ocurred, please contact an administrator."}, cid)
  189.             return false
  190.         end
  191.         local mountTable = mounts[mount:getId()]
  192.         if mountTable then
  193.             valor[cid] = itensTable.valor
  194.             itemName[cid] = msg
  195.             npcHandler:say({"Good choice! If you really want the ".. itemName[cid] ..", it will cost you ".. valor[cid] .." ".. ItemType(moeda):getName():lower() .."s. Are you sure?"}, cid)
  196.             npcHandler.topic[cid] = 8
  197.             playerTopic[cid]= 8
  198.         else
  199.             npcHandler:say({"I did not understand."}, cid)
  200.         end
  201.     elseif npcHandler.topic[cid] == 8 then
  202.         if msgcontains(msg, "yes") or msgcontains(msg, "sim") then
  203.             if player:getItemCount(moeda) >= precoTotal[cid] then
  204.                 if player:hasMount(itemName[cid]) then
  205.                     npcHandler:say({"You already have this mount. Choose another one."}, cid)
  206.                     npcHandler.topic[cid] = 7
  207.                     playerTopic[cid]= 7
  208.                 else
  209.                     player:addMount(itemName[cid])
  210.                     player:removeItem(moeda, precoTotal[cid])
  211.                     npcHandler:say({"Great. Here it is."}, cid)
  212.                     npcHandler.topic[cid] = 0
  213.                     playerTopic[cid]= 0
  214.                 end                    
  215.             else
  216.                 npcHandler:say({"You don't have enough event tokens..."}, cid)
  217.                 npcHandler.topic[cid] = 1
  218.                 playerTopic[cid]= 1
  219.             end
  220.         end
  221.     -- Prosseguindo com a parte de clothes
  222.     elseif (msgcontains(msg, "clothes") or msgcontains(msg, "outfit")) and (npcHandler.topic[cid] == 1) then
  223.    
  224.     -- Prosseguindo com a parte de other stuff
  225.     elseif (msgcontains(msg, "other stuff") or msgcontains(msg, "other") or msgcontains(msg, "stuff")) and (npcHandler.topic[cid] == 1) then
  226.    
  227.     else
  228.         npcHandler:say({"I did not understand."}, cid)
  229.     end
  230.    
  231.     if msgcontains(msg, "no") or msgcontains(msg, "nao") then
  232.         npcHandler:say({"Ah feel free to talk to me whenever I am here."}, cid)
  233.         npcHandler.topic[cid] = 0
  234.         playerTopic[cid]= 0
  235.     end
  236.     return true
  237. end
  238.  
  239. npcHandler:setMessage(MESSAGE_WALKAWAY, 'Valeu, |PLAYERNAME|!')
  240.  
  241. npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
  242. npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
  243.  
  244. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  245. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  246. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement