Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. local talkState = {}
  6.  
  7. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  8. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  9. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  10. function onThink() npcHandler:onThink() end
  11. local items = {[1] = {5878, 100}, [2] = {5876, 50}}
  12. local exp = 5000
  13.  
  14. local function getLeftItems(cid,tablem)
  15. local text = ""
  16. for i = 1,#tablem do
  17. if i == 1 then
  18. text = ""..text.." "..tablem[i][2] - getPlayerItemCount(cid, tablem[i][2]).." "..getItemNameById(tablem[i][1]).."."
  19. elseif i > 1 then
  20. text = ""..text.." and "..tablem[i][2] - getPlayerItemCount(cid, tablem[i][2]).." "..getItemNameById(tablem[i][1]).."."
  21. elseif i == #tablem then
  22. text = ""..text.." and "..tablem[i][2] - getPlayerItemCount(cid, tablem[i][2]).." "..getItemNameById(tablem[i][1]).."."
  23. end
  24. end
  25. return text
  26. end
  27.  
  28. local function getItemsFromTable(cid,tablem)
  29. local text = ""
  30. for i = 1,#tablem do
  31. if i == 1 then
  32. text = ""..text.." "..tablem[i][2].."x "..getItemNameById(tablem[i][1])..""
  33. elseif i > 1 then
  34. text = ""..text.." and "..tablem[i][2].."x "..getItemNameById(tablem[i][1])..""
  35. elseif i == #tablem then
  36. text = ""..text.." and "..tablem[i][2].."x "..getItemNameById(tablem[i][1]).."."
  37. end
  38. doPlayerAddItem(cid,tablem[i][1],tablem[i][2])
  39. end
  40. return text
  41. end
  42. local function hasItems(cid,tablem)
  43. for i = 1,#tablem do
  44. if getPlayerItemCount(cid, tablem[i][1]) >= tablem[i][2] then
  45. return true
  46. end
  47. end
  48.  
  49. return false
  50. end
  51.  
  52. local function RemoveCollected(cid,tablem)
  53. local text = ""
  54. for i = 1,#tablem do
  55. doPlayerRemoveItem(cid, tablem[i][1], tablem[i][2])
  56. end
  57. return true
  58. end
  59.  
  60. local function getItemsFromTable2(cid,tablem)
  61. local text = ""
  62. for i = 1,#tablem do
  63. if i == 1 then
  64. text = ""..text.." "..tablem[i][2].."x "..getItemNameById(tablem[i][1])..""
  65. elseif i > 1 then
  66. text = ""..text.." and "..tablem[i][2].."x "..getItemNameById(tablem[i][1])..""
  67. elseif i == #tablem then
  68. text = ""..text.." and "..tablem[i][2].."x "..getItemNameById(tablem[i][1]).."."
  69. end
  70. end
  71. return text
  72. end
  73.  
  74. function creatureSayCallback(cid, type, msg)
  75.  
  76. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  77.  
  78. if not npcHandler:isFocused(cid) then
  79. return false
  80. end
  81. local t = 0
  82. if msgcontains(msg, 'mission') then
  83. selfSay("So You Are The Guy Who Wana pass through that Door??", cid)
  84. talkState[talkUser] = 1
  85. elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
  86. if getPlayerStorageValue(cid, 5027) <= 0 then
  87. if getPlayerLevel(cid) >= 1100000 then
  88. selfSay("First You Have To Prove Yourself By Collecting this", cid)
  89. talkState[talkUser] = 2
  90. else
  91. selfSay("I Know you Have must Courage.. but you need to be level 1100000 to get the quest.", cid)
  92. end
  93. elseif getPlayerStorageValue(cid, 5027) > 0 and hasItems(cid,items) then
  94. RemoveCollected(cid,items)
  95. doPlayerSetStorageValue(cid, 5027, 2)
  96. doPlayerAddExperience(cid, exp)
  97. selfSay("You Are Now Allowed to Pass Through the Door..",cid)
  98. elseif getPlayerStorageValue(cid, 5027) > 0 and not hasItems(cid,items) then
  99. selfSay("you still need "..getLeftItems(cid,items)..".",cid)
  100. elseif getPlayerStorageValue(cid, 5027) > 1 then
  101. selfSay("This Mission is already Done",cid)
  102. end
  103. elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
  104. doPlayerSetStorageValue(cid, 5027,1)
  105. selfSay("Here is what you need to collect so i can make you a key",cid)
  106. selfSay(""..getItemsFromTable2(cid,items).."",cid)
  107. elseif msgcontains(msg, 'done') then
  108. if hasItems(cid,items) then
  109. RemoveCollected(cid,items)
  110. doPlayerAddExperience(cid, exp)
  111. doPlayerSetStorageValue(cid, 5027, 2)
  112. selfSay("You Are Now Allowed to Pass Through the Door..",cid)
  113. else
  114. selfSay("you still need "..getLeftItems(cid,items)..".",cid)
  115. end
  116. end
  117. return true
  118. end
  119.  
  120. npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
  121. npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye? I guess...")
  122. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  123. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement