Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.92 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)                end
  6. function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)             end
  7. function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)        end
  8. function onThink()                          npcHandler:onThink()                            end
  9.  
  10. local cfg = {
  11.     kicktime = 3, -- Tempo para Kickar o Player / Em Segundos
  12.     vocations = {
  13.         ["druid"] = {
  14.                 level = 30, -- Level Mínimo
  15.                 voc = { -- Possíveis Promoções
  16.                     {name = 'sanders druid', id = 6},
  17.                 },
  18.                 price = { -- Preço
  19.                     {id = 2152, amount = 100},
  20.                     {id = 2160, amount = 1},
  21.                 },
  22.             },
  23.         -- [[ New Vocation Below ]] --
  24.         ["sorcerer"] = {
  25.                 level = 30, -- Level Mínimo
  26.                 voc = { -- Possíveis Promoções
  27.                     {name = 'crowler sorcerer', id = 5},
  28.                 },
  29.                 price = { -- Preço
  30.                     {id = 2152, amount = 100},
  31.                     {id = 2160, amount = 1},
  32.                 },
  33.             },
  34.  
  35.             ["paladin"] = {
  36.                 level = 30, -- Level Mínimo
  37.                 voc = { -- Possíveis Promoções
  38.                     {name = 'Drizzt Paladin', id = 7},
  39.                 },
  40.                 price = { -- Preço
  41.                     {id = 2152, amount = 100},
  42.                     {id = 2160, amount = 1},
  43.                 },
  44.             },
  45.  
  46.         ["knight"] = {
  47.                 level = 30, -- Level Mínimo
  48.                 voc = { -- Possíveis Promoções
  49.                     {name = 'Beowulf Knight', id = 8},
  50.                 },
  51.                 price = { -- Preço
  52.                     {id = 2152, amount = 100},
  53.                     {id = 2160, amount = 1},
  54.                 },
  55.             },
  56.         },
  57.        
  58. }
  59.  
  60. function creatureSayCallback(cid, type, msg)
  61.     if(not npcHandler:isFocused(cid)) then
  62.         return false
  63.     end
  64.     if msgcontains(msg, 'promote') or msgcontains(msg, 'promo') or msgcontains(msg, 'promotion') and talk_state == 0 then
  65.         getVocation = getPlayerVocationName(cid):lower()
  66.         get = vocations[getVocation]
  67.         if get then
  68.             if getPlayerLevel(cid) >= get.level then
  69.                 str = getTextPromoVocations(get.voc)
  70.                 npcHandler:say('Alright, you can choose this vocation(s): '..str..'.', cid)
  71.                 talk_state = 1
  72.             else
  73.                 npcHandler:say('Sorry, but you need level '..get.level..' to be promoted.', cid)
  74.                 talk_state = 0
  75.                 return true
  76.             end
  77.         else
  78.             npcHandler:say('Sorry, but I don\'t have nothing more for your vocation.', cid)
  79.             talk_state = 0
  80.             return true
  81.         end
  82.  
  83.     elseif talk_state == 1 then
  84.         get = cfg[getVocation]
  85.         if get then
  86.             ctrl = 0
  87.             svocId = 0
  88.             for b = 1, #get.voc do
  89.                 g = get.voc[b].name:lower()
  90.                 if msg:lower() == g then
  91.                     ctrl = ctrl + 1
  92.                     svocId = get.voc[b].id
  93.                 end
  94.             end
  95.             if ctrl > 0 then
  96.                 items = getItemsPromoVocations(get.price)
  97.                 npcHandler:say('Alright, you need pay: '..items..' to continue, you have this items?', cid)
  98.                 talk_state = 2
  99.             else
  100.                 npcHandler:say('Vocation not founded, try choose again: '..str..'.', cid)
  101.                 talk_state = 1
  102.                 return true
  103.             end
  104.         else
  105.             npcHandler:say('Sorry, but some error have occurred with your vocation, please contact to administrator.', cid)
  106.             talk_state = 0
  107.         end
  108.  
  109.     elseif talk_state == 2 then
  110.         if msgcontains(msg, 'yes') then
  111.             c = 0
  112.             for j = 1, #get.price do
  113.                 if getPlayerItemCount(cid, get.price[j].id) >= get.price[j].amount then
  114.                     c = c + 1
  115.                 else
  116.                     if get.price[j].amount > 1 then name = getItemPluralNameById else name = getItemNameById end
  117.                     npcHandler:say('Sorry, but you DON\'T have {'..get.price[j].amount..'x '..name(get.price[j].id)..'}.', cid)
  118.                     talk_state = 0
  119.                     break
  120.                 end
  121.             end
  122.             if c == #get.price then
  123.                 npcHandler:say('Well, well, you have been PROMOTED and will be kicked in 3 seconds.', cid)
  124.                 doNewPromoteThing(cid, get.price, svocId)
  125.                 talk_state = 0
  126.             end
  127.         end
  128.        
  129.     elseif msgcontains(msg, 'no') then
  130.         npcHandler:say('Well, then leave.', cid)
  131.         talk_state = 0
  132.     end
  133.    
  134.     return true
  135. end
  136.  
  137. function getTextPromoVocations(vocs)
  138.     text = ''
  139.     for i = 1, #vocs do
  140.         if #vocs == 1 or i == 1 then
  141.             text = '{'..vocs[i].name..'}'
  142.         elseif #vocs > 1 and i == #vocs then
  143.             text = ''..text..' and {'..vocs[i].name..'}'
  144.         else
  145.             text = ''..text..', {'..vocs[i].name..'}'
  146.         end
  147.     end
  148. return text
  149. end
  150.  
  151. function getItemsPromoVocations(list)
  152.     items = ''
  153.     for i = 1, #list do
  154.         if list[i].amount > 1 then name = getItemPluralNameById else name = getItemNameById end
  155.         if #list == 1 or i == 1 then
  156.             items = '{'..list[i].amount..'x '..name(list[i].id)..'}'
  157.         elseif #list > 1 and i == #list then
  158.             items = ''..items..' and {'..list[i].amount..'x '..name(list[i].id)..'}'
  159.         else
  160.             items = ''..items..', {'..list[i].amount..'x '..name(list[i].id)..'}'
  161.         end
  162.     end
  163. return items
  164. end
  165.  
  166. function doNewPromoteThing(cid, list, vocid)
  167.     for k = 1, #list do
  168.         doPlayerRemoveItem(cid, list[k].id, list[k].amount)
  169.     end
  170.     doPlayerSetVocation(cid, vocid)
  171.     addEvent(doRemoveCreature, cfg.kicktime * 1000, cid)
  172. return true
  173. end
  174.  
  175. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  176. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement