Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.91 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3.  
  4. NpcSystem.parseParameters(npcHandler)
  5.  
  6. local talkState = {}
  7.  
  8. function onCreatureAppear(cid)
  9.     npcHandler:onCreatureAppear(cid)
  10. end
  11. function onCreatureDisappear(cid)
  12.     npcHandler:onCreatureDisappear(cid)
  13. end
  14. function onCreatureSay(cid, type, msg)
  15.     npcHandler:onCreatureSay(cid, type, msg)
  16. end
  17. function onThink()
  18.     npcHandler:onThink()
  19. end
  20.  
  21. local fyi = {
  22.     [5] = "Congratulations on reaching Tier 2!",
  23.     [12] = "Congratulations on reaching Tier 3!",
  24.     [25] = "Congratulations on reaching Tier 4!",
  25.     [55] = "Congratulations on reaching Tier 5!",
  26.     [90] = "Congratulations on reaching Tier 6!",
  27.     [150] = "Congratulations on reaching Tier 7!",
  28.     [240] = "Congratulations on reaching Tier 8!",
  29.     [401] = "Congratulations on reaching Tier 9!",
  30. }
  31.  
  32. local spells = {
  33.     [5] = "death whip",
  34.     [10] = {"thunderblast", "flame nova"},
  35.     [25] = {"exevo gran mas candy", "poison plague"},
  36.     [40] = "exevo gran mas love",
  37.     [50] = "frost flash",
  38.     [100] = "aguamenti",
  39.     [150] = "energy volley",
  40.     [200] = "alohomora",
  41.     [250] = "frost arrow",
  42.     [300] = "expecto patrinum",
  43.     [350] = "shooting star",
  44.     [400] = "avada kedavra",
  45.     [450] = "void strike"
  46.  
  47. }
  48.  
  49. function creatureSayCallback(cid, type, msg)
  50.     if (not npcHandler:isFocused(cid)) then
  51.         return false
  52.     end
  53.      
  54.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  55.     local reb = getPlayerRebirth(cid)
  56.     local c, current = getRebirthCost(reb + 1), getPlayerStorageValue(cid, REBIRTH_STORAGE_STAGE)
  57.     local name, i, amount = "", 0, 0
  58.  
  59.     if (current > 0 or (current == -1 and REBIRTH_MISSIONS[reb] ~= nil and REBIRTH_MISSIONS[reb]["kill"] ~= nil)) then
  60.         for k, v in pairs(REBIRTH_MISSIONS[reb]["kill"]) do
  61.             i = i + 1
  62.  
  63.             if (current == i or current == -1) then
  64.                 name = k
  65.                 amount = v
  66.                 break
  67.             end
  68.         end
  69.     end
  70.  
  71.     local str, nr = "", 0
  72.     if (REBIRTH_MISSIONS[reb] ~= nil and REBIRTH_MISSIONS[reb]["collect"] ~= nil) then
  73.         for _, v in pairs(REBIRTH_MISSIONS[reb]["collect"]) do
  74.             nr = nr + 1
  75.             str = str .. v[2] .. " " .. getItemNameById(v[1]) .. "s, "
  76.         end
  77.     end
  78.  
  79.     if (msgcontains(msg, 'mission')) then      
  80.         if (current == 0) then
  81.             if (nr > 0) then
  82.                 selfSay('Your (final) mission for this rebirth is to bring me ' .. str .. ' and say {rebirth}.', cid)
  83.             else
  84.                 selfSay('You have finished all your missions. Please ask me to {rebirth} you.', cid)
  85.             end
  86.         else   
  87.             if (amount == 0) then
  88.                 selfSay('I do not have any missions for your rebirth.', cid)
  89.             else
  90.                 if (current == -1) then
  91.                     setPlayerStorageValue(cid, REBIRTH_STORAGE_STAGE, 1)
  92.                     setPlayerStorageValue(cid, REBIRTH_STORAGE_AMOUNT, 0)
  93.                 end
  94.                 selfSay('Your current mission is to kill ' .. amount .. ' ' .. name:lower() .. 's.', cid)
  95.             end
  96.         end
  97.  
  98.     elseif (msgcontains(msg, 'rebirth')) then
  99.         if getPlayerLevel(cid) >= 717217 then
  100.             if (reb <= 200) then
  101.                 selfSay('Are you ready for me to rebirth you!? You would have ' .. (getPlayerRebirth(cid) + 1) .. ' rebirths. But you have to give me ' .. (c > 1 and c or 'a') .. ' gold ingot' .. (c > 1 and 's' or '') .. ' OR finish my {missions} in return.', cid)
  102.             else
  103.                 selfSay('Are you ready for me to rebirth you!? You would have ' .. (getPlayerRebirth(cid) + 1) .. ' rebirths. But you have to finish my {missions} in return.', cid)
  104.             end
  105.             talkState[talkUser] = 1
  106.         else
  107.             selfSay('Only characters of level 717 217 level or higher may rebirth.', cid)
  108.             talkState[talkUser] = 0
  109.         end
  110.      
  111.      
  112.     elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
  113.         if (getPlayerLevel(cid) >= 717217) then
  114.             local hasIngots = (getPlayerItemCount(cid, 9971) >= c)
  115.             local didMissions = (current == 0)
  116.  
  117.             if (didMissions) then
  118.                 if (nr > 0) then
  119.                     for _, v in pairs(REBIRTH_MISSIONS[reb]["collect"]) do
  120.                         if (getPlayerItemCount(cid, v[1]) < v[2]) then
  121.                             didMissions = false
  122.                             break
  123.                         end
  124.                     end
  125.                 end
  126.             end
  127.  
  128.             if didMissions or hasIngots then
  129.                 if (didMissions) then
  130.                     if (nr > 0) then
  131.                         for _, v in pairs(REBIRTH_MISSIONS[reb]["collect"]) do
  132.                             doPlayerRemoveItem(cid, v[1], v[2])
  133.                         end
  134.                     end
  135.                 else
  136.                     doPlayerRemoveItem(cid, 9971, c)
  137.                 end
  138.                 local newRebirth = getPlayerRebirth(cid) + 1
  139.                 setPlayerRebirth(cid, newRebirth)
  140.                 doPlayerAddSkill(cid, SKILL__LEVEL, -717208, true)
  141.                 local text = {}
  142.                 local fyiData = fyi[newRebirth]
  143.                 local toLearn = spells[newRebirth]
  144.                 if fyiData then
  145.                     text[#text+1] = ("%s%s"):format(fyiData, (toLearn and "---------------\nSpells Learned\n---------------" or ""))
  146.                 end
  147.                 if toLearn then
  148.                     if type(toLearn) == "string" then
  149.                         doPlayerLearnInstantSpell(cid, toLearn)
  150.                         text[#text+1] = "\t-> ".. toLearn
  151.                     elseif type(toLearn) == "table" then
  152.                         for i = 1, #toLearn do
  153.                             doPlayerLearnInstantSpell(cid, toLearn[i])
  154.                             text[#text+1] = "\t-> ".. toLearn[i]
  155.                         end
  156.                     end
  157.                 end
  158.                 if #text > 0 then
  159.                     doPlayerPopupFYI(cid, table.concat(text, "\n"))
  160.                 end
  161.  
  162.                 while (getPlayerLevel(cid) > 8) do
  163.                     doPlayerAddSkill(cid, SKILL__LEVEL, -100000, true)
  164.                 end
  165.  
  166.                 doCreatureSetStorage(cid, REBIRTH_STORAGE_STAGE)
  167.                 doCreatureSetStorage(cid, REBIRTH_STORAGE_AMOUNT)
  168.                 doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREATTACK)
  169.                 updateStats(cid)
  170.             else
  171.                 selfSay('You do not have enough gold ingots nor have you finished all your mission!', cid)
  172.                 doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
  173.             end
  174.  
  175.                
  176.         else
  177.             selfSay('Only characters of level 717 217 level or higher may rebirth.', cid)
  178.             talkState[talkUser] = 0
  179.         end
  180.     elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
  181.         talkState[talkUser] = 0
  182.         selfSay('Okey come back when you have some money you poor scum.', cid)
  183.     end
  184.     return true
  185. end
  186.  
  187. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  188. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement