peonso

npc long history exemple

Nov 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.35 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 Topic = {}
  11.  
  12. local story = {}
  13.  
  14. local function cancelStory(cid)
  15.     if not(story[cid]) then return true end
  16.         for _, eventId in pairs(story[cid]) do
  17.         stopEvent(eventId)
  18.     end
  19.     story[cid] = {}
  20. end
  21.  
  22. function creatureFarewell(cid)
  23.     if not(isPlayer(cid)) then
  24.         return true
  25.     end
  26.     cancelStory(cid)
  27.     return true
  28. end
  29.  
  30. npcHandler:setCallback(CALLBACK_FAREWELL, creatureFarewell)
  31. npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureFarewell)
  32.  
  33. function creatureSayCallback(cid, type, msg)
  34.  
  35.     if(not npcHandler:isFocused(cid)) then
  36.         return false
  37.     end
  38.    
  39.     local player = Player(cid)
  40.     local t = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  41.     local delayTime = 5*1000
  42.  
  43.     if isInArray({"quest", "mission", "sumail"}, msg:lower()) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) < 0 and Topic[t] == nil then
  44.         npcHandler:say("I can help you build trust with Sumail, but you will need to help me first. Are you interested?", cid)
  45.         Topic[t] = 1
  46.     elseif msgcontains(msg, "trade") then
  47.         npcHandler:say("{Sumail} is the one that do the trading.", cid)
  48.         Topic[t] = nil
  49.     elseif msgcontains(msg, "yes") and Topic[t] == 1 and player:getStorageValue(STORAGEVALUE_DJINNQUEST) < 0 then
  50.         npcHandler:say("Our families don't like each other, but me and Sumail are really close, you know? I'm thinking about cooking him a special meal, I need you to steal a special cook book from the elves.", cid)
  51.         player:setStorageValue(STORAGEVALUE_DJINNQUEST, 1)
  52.         player:setStorageValue(6025, 1) -- magic door
  53.         Topic[t] = nil
  54.     elseif isInArray({"meal", "book", "mission", "cookbook"}, msg:lower()) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 1 then
  55.         if player:removeItem(2347, 1) then
  56.             npcHandler:say("Ohh, thanks! That's exactly what I was needing. I will tell Sumail you the one that got the recipe. Would you {help} me more?", cid)
  57.             player:setStorageValue(STORAGEVALUE_DJINNQUEST, 2)
  58.             player:addExperience(10 * 1000, true)
  59.             player:setStorageValue(6025, 0) -- magic door
  60.             Topic[t] = 1
  61.         else
  62.             npcHandler:say("Please, I need this special meal to pleasure Sumail.", cid)
  63.             Topic[t] = nil
  64.         end
  65.     elseif ((msgcontains(msg, "yes") and Topic[t] == 1) or msgcontains(msg, "help")) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 2 then
  66.         npcHandler:say("Ok, I will be honest with you, what I will ask you now has nothing to do with Sumail, but I really need help with it. I haven't been able to travel with my magic capert lately because it need some {repair}.", cid)
  67.         Topic[t] = nil
  68.     elseif msgcontains(msg, "repair") and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 2 then
  69.         npcHandler:say("It has some holes, I need a blue fabric to fix it. I heard whispers about a person in Stonegate that deal with blue tapestry, I need just one.", cid)
  70.         player:setStorageValue(STORAGEVALUE_DJINNQUEST, 3)
  71.         Topic[t] = nil
  72.     elseif isInArray({"blue", "tapestry", "mission", "blue tapestry", "fabric"}, msg:lower()) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 3 then
  73.         if player:removeItem(1872, 1) then
  74.             npcHandler:say("It can't be better! My magic carpet will be gorgeous now. Should we get back to the Sumail {issue}?", cid)
  75.             player:setStorageValue(STORAGEVALUE_DJINNQUEST, 4)
  76.             player:addExperience(10 * 1000, true)
  77.             Topic[t] = 1
  78.         else
  79.             npcHandler:say("I heard whispers about a person in Stonegate that deal with blue tapestry, I need just one.", cid)
  80.             Topic[t] = nil
  81.         end
  82.     elseif ((msgcontains(msg, "yes") and Topic[t] == 1) or msgcontains(msg, "issue")) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 4 then
  83.         cancelStory(cid)
  84.         story[cid] = selfStory({"I want to give Sumail a really special present, that he won't ever forget. He was set free from his magical lamp by the famous hero Alistar Lionheart.",
  85.             "Alistar Lionheart is a really great person, I think he will concede me this favor, as he also appreciate the services Sumail did for him in the past.",
  86.             "I need you to find him, and ask him for Sumail magic {lamp}. He went in a mission in the orc cave to the west."}, cid, delayTime)
  87.         player:setStorageValue(STORAGEVALUE_DJINNQUEST, 5)
  88.         player:setStorageValue(6026, 1) -- magic door
  89.         Topic[t] = nil
  90.     elseif isInArray({"lamp", "alistar", "mission", "dead"}, msg:lower()) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 5 then
  91.         npcHandler:say("Please find Alistar Lionheart and ask him for Sumail {lamp}.", cid)
  92.         Topic[t] = nil
  93.     elseif isInArray({"lamp", "alistar", "mission", "dead"}, msg:lower()) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 6 then
  94.         cancelStory(cid)
  95.         story[cid] = selfStory({"Nooo! I can't believe, he was soo strong. Please do never mention this to Sumail, he will be hearthbroken by this notice, I will chose the best moment to tell him.",
  96.             "But we shouldn't give up, you still up to help me find a {present}, right?"}, cid, delayTime)
  97.         player:setStorageValue(STORAGEVALUE_DJINNQUEST, 7)
  98.         player:setStorageValue(6026, 0) -- magic door
  99.         Topic[t] = 1
  100.     elseif ((msgcontains(msg, "yes") and Topic[t] == 1) or msgcontains(msg, "present")) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 7 then
  101.         npcHandler:say("Great. In the bloodborne library, there is a bookshelf with a special book. Sumail is a real bookworm, and would love this rare volume. Try to find it in the Monastery of Angels.", cid)
  102.         player:setStorageValue(STORAGEVALUE_DJINNQUEST, 8)
  103.         player:setStorageValue(6027, 1) -- magic door
  104.         Topic[t] = nil
  105.     elseif isInArray({"book", "special", "mission", "rare", "special book", "present", "rare volume", "volume"}, msg:lower()) and player:getStorageValue(STORAGEVALUE_DJINNQUEST) == 8 then
  106.         if player:removeItem(8983, 1) then
  107.             npcHandler:say("You are awesome, |PLAYERNAME|. I can't believe you really got it. Sumail will be so happy with me, ... I mean, with us! I will tell him everything, I'm sure it will soften his heart, talk to him about {trust}.", cid)
  108.             player:setStorageValue(STORAGEVALUE_DJINNQUEST, 9)
  109.             player:setStorageValue(6027, 0) -- magic door
  110.             player:addExperience(10 * 1000, true)
  111.             Topic[t] = 1
  112.         else
  113.             npcHandler:say("Please bring me the rare book from bloodborne library.", cid)
  114.             Topic[t] = nil
  115.         end
  116.     elseif msgcontains(msg, "mission") and player:getStorageValue(STORAGEVALUE_DJINNQUEST) >= 9 then
  117.         npcHandler:say("I have no more missions for you, my friend.", cid)
  118.         Topic[t] = nil
  119.     end
  120.    
  121.     return true
  122.    
  123. end
  124.  
  125. --[[
  126. -- Travel
  127. local function addTravelKeyword(keyword, cost, destination)
  128.     local travelKeyword = keywordHandler:addKeyword({keyword}, StdModule.say, {npcHandler = npcHandler, text = 'Do you seek a passage to ' .. keyword:titleCase() .. ' for |TRAVELCOST|?', cost = cost, discount = 'postman'})
  129.         travelKeyword:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, cost = cost, discount = 'postman', destination = destination})
  130.         travelKeyword:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'We would like to serve you some time.', reset = true})
  131. end
  132.  
  133. addTravelKeyword('stonegate', 140, Position(494, 488, 6))
  134. ]]--
  135.  
  136. -- Basic
  137. keywordHandler:addKeyword({'sail'}, StdModule.say, {npcHandler = npcHandler, text = 'The winds are dangerous today, sorry.'})
  138. keywordHandler:addAliasKeyword({'passage'})
  139. keywordHandler:addAliasKeyword({'city'})
  140. keywordHandler:addAliasKeyword({'cities'})
  141. keywordHandler:addAliasKeyword({'travel'})
  142. keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'I am a licensed carpetpilot'})
  143. keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, text = 'I\'m Saahil Arora.'})
  144.  
  145. npcHandler:setMessage(MESSAGE_GREET, 'Be greeted, human |PLAYERNAME|. How can a humble djinn be of service?')
  146. npcHandler:setMessage(MESSAGE_FAREWELL, 'Finally.')
  147. npcHandler:setMessage(MESSAGE_WALKAWAY, 'Finally.')
  148.  
  149. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  150. npcHandler:addModule(FocusModule:new())
Add Comment
Please, Sign In to add comment