Advertisement
Guest User

npc/script

a guest
Aug 3rd, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.22 KB | None | 0 0
  1. local THESNAPPER_POSITION = {x = 100, y = 100, z = 7}
  2. local HIDE_POSITION = {x = 100, y = 100, z = 7}
  3. local THEBLOODTUSK_POSITION = {x = 100, y = 100, z = 7}
  4. local SHARDHEAD_POSITION = {x = 100, y = 100, z = 7}
  5. local THUL_POSITION = {x = 100, y = 100, z = 7}
  6. local ESMERALDA_POSITION = {x = 100, y = 100, z = 7}
  7. local THEOLDWIDOW_POSITION = {x = 100, y = 100, z = 7}
  8. local THEMANY_POSITION = {x = 100, y = 100, z = 7}
  9. local LEVIATHAN_POSITION = {x = 100, y = 100, z = 7}
  10. local STONECRACKER_POSITION = {x = 100, y = 100, z = 7}
  11. local THENOXIUSSPAWN_POSITION = {x = 100, y = 100, z = 7}
  12. local MERIKHTHESLAUGHTERER_POSITION = {x = 100, y = 100, z = 7}
  13. local FAHIMTHEWISE_POSITION = {x = 100, y = 100, z = 7}
  14. local RANDOMPIRATEBOSS_POSITION = {x = 100, y = 100, z = 7}
  15. local THEHORNEDFOX_POSITION = {x = 100, y = 100, z = 7}
  16. local NECROPHARUS_POSITION = {x = 100, y = 100, z = 7}
  17.  
  18.  
  19. local tasks =
  20. {
  21. [1] = {questStarted = 1510, questStorage = 65000, killsRequired = 100, raceName = "Trolls", rewards = {{enable = true, type = "exp", values = 200}, {enable = true, type = "money", values = 200}}},
  22.  
  23. [2] = {questStarted = 1511, questStorage = 65001, killsRequired = 150, raceName = "Goblins", rewards = {{enable = true, type = "exp", values = 300}, {enable = true, type = "money", values = 250}}},
  24.  
  25. [3] = {questStarted = 1512, questStorage = 65002, killsRequired = 300, raceName = "Rotworms", rewards = {{enable = true, type = "exp", values = 1000}, {enable = true, type = "money", values = 400}}},
  26.  
  27. [4] = {questStarted = 1513, questStorage = 65003, killsRequired = 500, raceName = "Cyclops", rewards = {{enable = true, type = "exp", values = 3000}, {enable = true, type = "money", values = 800}}},
  28.  
  29. [5] = {questStarted = 1514, questStorage = 65004, killsRequired = 300, raceName = "Crocodiles", rewards = {{enable = true, type = "exp", values = 800}, {enable = true, type = "boss", values = THESNAPPER_POSITION}, {enable = true, type = "points", values = 7}}},
  30.  
  31. [6] = {questStarted = 1515, questStorage = 65005, killsRequired = 300, raceName = "Tarantulas", rewards = {{enable = true, type = "money", values = 1500}, {enable = true, type = "boss", values = HIDE_POSITION}, {enable = true, type = "points", values = 2}}},
  32.  
  33. [7] = {questStarted = 1516, questStorage = 65006, killsRequired = 150, raceName = "Carniphilas", rewards = {{enable = true, type = "exp", values = 1500}, {enable = true, type = "points", values = 1}}},
  34.  
  35. [8] = {questStarted = 1517, questStorage = 65007, killsRequired = 200, raceName = "Stone Golems", rewards = {{enable = true, type = "exp", values = 2000}, {enable = true, type = "points", values = 1}}},
  36.  
  37. [9] = {questStarted = 1518, questStorage = 65008, killsRequired = 300, raceName = "Mammoths", rewards = {{enable = true, type = "exp", values = 4000}, {enable = true, type = "boss", values = THEBLOODTUSK_POSITION}, {enable = true, type = "points", values = 2}}},
  38.  
  39. [10] = {questStarted = 1519, questStorage = 65009, killsRequired = 300, raceName = "Ice Golems", rewards = {{enable = true, type = "exp", values = 15000}, {enable = true, type = "boss", values = SHARDHEAD_POSITION}, {enable = true, type = "points", values = 2}}},
  40.  
  41. [11] = {questStarted = 1520, questStorage = 65010, killsRequired = 300, raceName = "Quaras Scout", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 1}}},
  42.  
  43. [12] = {questStarted = 1521, questStorage = 65011, killsRequired = 300, raceName = "Quaras", rewards = {{enable = true, type = "exp", values = 12000}, {enable = true, type = "boss", values = THUL_POSITION}, {enable = true, type = "points", values = 2}}},
  44.  
  45. [13] = {questStarted = 1522, questStorage = 65012, killsRequired = 70, raceName = "Water Elementals", rewards = {{enable = true, type = "exp", values = 7000}, {enable = true, type = "points", values = 1}}},
  46.  
  47. [14] = {questStarted = 1523, questStorage = 65013, killsRequired = 70, raceName = "Earth Elementals", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 1}}},
  48.  
  49. [15] = {questStarted = 1524, questStorage = 65014, killsRequired = 70, raceName = "Energy Elementals", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "points", values = 1}}},
  50.  
  51. [16] = {questStarted = 1525, questStorage = 65015, killsRequired = 70, raceName = "Fire Elementals", rewards = {{enable = true, type = "exp", values = 7000}, {enable = true, type = "points", values = 1}}},
  52.  
  53. [17] = {questStarted = 1526, questStorage = 65016, killsRequired = 200, raceName = "Mutated Rats", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "boss", values = ESMERALDA_POSITION}, {enable = true, type = "points", values = 2}}},
  54.  
  55. [18] = {questStarted = 1527, questStorage = 65017, killsRequired = 500, raceName = "Giant Spiders", rewards = {{enable = true, type = "exp", values = 5000}, {enable = true, type = "boss", values = THEOLDWIDOW_POSITION}, {enable = true, type = "points", values = 2}}},
  56.  
  57. [19] = {questStarted = 1528, questStorage = 65018, killsRequired = 2000, raceName = "Hydras", rewards = {{enable = true, type = "boss", values = THEMANY_POSITION}, {enable = true, type = "points", values = 4}}},
  58.  
  59. [20] = {questStarted = 1529, questStorage = 65019, killsRequired = 2000, raceName = "Sea Serpents", rewards = {{enable = true, type = "boss", values = LEVIATHAN_POSITION}, {enable = true, type = "points", values = 4}}},
  60.  
  61. [21] = {questStarted = 1530, questStorage = 65020, killsRequired = 2000, raceName = "Behemoths", rewards = {{enable = true, type = "boss", values = STONECRACKER_POSITION}, {enable = true, type = "points", values = 4}}},
  62.  
  63. [22] = {questStarted = 1531, questStorage = 65021, killsRequired = 1500, raceName = "Serpents Spawn", rewards = {{enable = true, type = "teleport", values = THENOXIUSSPAWN_POSITION}, {enable = true, type = "points", values = 4}}},
  64.  
  65. [23] = {questStarted = 1532, questStorage = 65022, killsRequired = 500, raceName = "Green Djinns", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "boss", values = MERIKHTHESLAUGHTERER_POSITION}}},
  66.  
  67. [24] = {questStarted = 1533, questStorage = 65023, killsRequired = 500, raceName = "Blue Djinns", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "boss", values = FAHIMTHEWISE_POSITION}}},
  68.  
  69. [25] = {questStarted = 1534, questStorage = 65024, killsRequired = 3000, raceName = "Pirates1", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "money", values = 5000}, {enable = true, type = "boss", values = RANDOMPIRATEBOSS_POSITION}}},
  70.  
  71. [26] = {questStarted = 1535, questStorage = 65025, killsRequired = 3000, raceName = "Pirates2", rewards = {{enable = true, type = "exp", values = 10000}, {enable = true, type = "money", values = 5000}}},
  72.  
  73. [27] = {questStarted = 1536, questStorage = 65026, killsRequired = 5000, raceName = "Minotaurs", rewards = {{enable = true, type = "boss", values = THEHORNEDFOX_POSITION}}},
  74.  
  75. [28] = {questStarted = 1537, questStorage = 65027, killsRequired = 4000, raceName = "Magicians1", rewards = {{enable = true, type = "boss", values = NECROPHARUS_POSITION}}},
  76.  
  77. [29] = {questStarted = 1538, questStorage = 65028, killsRequired = 1000, raceName = "Magicians2", rewards = {{enable = true, type = "exp", values = 40000}}},
  78.  
  79. [30] = {questStarted = 1539, questStorage = 65029, killsRequired = 6666, raceName = "Demons", rewards = {{enable = true, type = "storage", values = {65535, 1}}}}
  80. }
  81.  
  82. local rankStorage = 32150
  83. local choose = {}
  84.  
  85. local keywordHandler = KeywordHandler:new()
  86. local npcHandler = NpcHandler:new(keywordHandler)
  87. NpcSystem.parseParameters(npcHandler)
  88. local talkState = {}
  89.  
  90. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  91. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  92. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  93. function onThink() npcHandler:onThink() end
  94.  
  95. function getTasksStarted(cid)
  96. local tmp = {}
  97. for k, v in pairs(tasks) do
  98. if getCreatureStorage(cid, v.questStarted) == 1 then
  99. table.insert(tmp, k)
  100. end
  101. end
  102. return tmp
  103. end
  104.  
  105. function getTaskByName(name)
  106. for k, v in pairs(tasks) do
  107. if v.raceName:lower() == name:lower() then
  108. return k
  109. end
  110. end
  111. return false
  112. end
  113.  
  114. function creatureSayCallback(cid, type, msg)
  115.  
  116. if(not npcHandler:isFocused(cid)) then
  117. return false
  118. end
  119. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
  120. if isInArray({"task", "tasks"}, msg:lower()) then
  121. selfSay("There you can see the following tasks, please tell me the number of the task that you want to do.", cid)
  122. local text = ""
  123. for i = 1, table.maxn(tasks) do
  124. text = text .. (text == "" and "" or "\n") .. i .. " - " .. tasks.raceName .. (getCreatureStorage(cid, tasks.questStarted) == 1 and " [...]" or getCreatureStorage(cid, tasks.questStarted) == 2 and " [x]" or "")
  125. end
  126. return doShowTextDialog(cid, 5956, text)
  127.  
  128. elseif getTaskByName(msg) or tasks[tonumber(msg)] then
  129. msg = (getTaskByName(msg) or tonumber(msg))
  130. if getCreatureStorage(cid, tasks[msg].questStarted) == 1 then
  131. selfSay("You already started this task.", cid)
  132. talkState[talkUser] = 0
  133. return true
  134. end
  135. if getCreatureStorage(cid, tasks[msg].questStarted) == 2 then
  136. selfSay("You already finished this task.", cid)
  137. talkState[talkUser] = 0
  138. return true
  139. end
  140. if tasks[msg].level and getPlayerLevel(cid) < tasks[msg].level then
  141. selfSay("You need level " .. tasks[msg].level .. " or higher to make this task.", cid)
  142. talkState[talkUser] = 0
  143. return true
  144. end
  145. selfSay("Are you sure that do you want to start the task number " .. msg .. "? In this task you will need to defeat " .. tasks[msg].killsRequired .. " " .. tasks[msg].raceName .. ".", cid)
  146. choose[cid] = msg
  147. talkState[talkUser] = 1
  148. elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
  149. doCreatureSetStorage(cid, tasks[choose[cid]].questStarted, 1)
  150. selfSay("You have started the task number " .. choose[cid] .. ", remember... in this task you will need to defeat " .. tasks[choose[cid]].killsRequired .. " " .. tasks[choose[cid]].raceName .. ". Good luck!", cid)
  151. talkState[talkUser] = 0
  152. return true
  153.  
  154. elseif msg:lower() == "report" then
  155. local t = getTasksStarted(cid)
  156. local response = "You are currently making " .. (#t > 1 and "these" or "this") .. " task" .. (#t > 1 and "s" or "") .. ":\n"
  157. if table.maxn(t) > 0 then
  158. for _, tsk in ipairs(t) do
  159. if getCreatureStorage(cid, tasks[tsk].questStorage) < 0 then doCreatureSetStorage(cid, tasks[tsk].questStorage, 0) end
  160. response = response .. " Name: " .. tasks[tsk].raceName .. " Kills: " .. getCreatureStorage(cid, tasks[tsk].questStorage) .. " - " .. tasks[tsk].killsRequired .. ".\n"
  161. end
  162. response = response .. "Please say report and the name of the task that do you want to report, example: 'Report Trolls'."
  163. return selfSay(response, cid)
  164. else
  165. return selfSay("You need to start at least one task first.", cid)
  166. end
  167. elseif string.sub(msg:lower(), 0, 6) == "report" then
  168. local t = getTaskByName(string.sub(msg, 8, string.len(msg)))
  169. if not t then
  170. return selfSay("That task does not exists.", cid)
  171. end
  172.  
  173. if getCreatureStorage(cid, tasks[t].questStarted) == 2 then
  174. return selfSay("You already finished this task.", cid)
  175. end
  176.  
  177. if getCreatureStorage(cid, tasks[t].questStarted) < 1 then
  178. return selfSay("You don't have started this task.", cid)
  179. end
  180.  
  181. if tasks[t].killsRequired > getCreatureStorage(cid, tasks[t].questStorage) then
  182. return selfSay("Current " .. getCreatureStorage(cid, tasks[t].questStorage) .. " " .. tasks[t].raceName .. " killed, you need to kill " .. tasks[t].killsRequired .. ".", cid)
  183. end
  184.  
  185. for i = 1, table.maxn(tasks[t].rewards) do
  186. if(tasks[t].rewards.enable) then
  187. if isInArray({"boss", "teleport", 1}, tasks[t].rewards.type) then
  188. doTeleportThing(cid, tasks[t].rewards.values)
  189. elseif isInArray({"exp", "experience", 2}, tasks[t].rewards.type) then
  190. doPlayerAddExperience(cid, tasks[t].rewards.values)
  191. elseif isInArray({"item", 3}, tasks[t].rewards.type) then
  192. doPlayerAddItem(cid, v.rewards.values[1], tasks[t].rewards.values[2])
  193. elseif isInArray({"money", 4}, tasks[t].rewards.type) then
  194. doPlayerAddMoney(cid, tasks[t].rewards.values)
  195. elseif isInArray({"storage", "stor", 5}, tasks[t].rewards.type) then
  196. doCreatureSetStorage(cid, tasks[t].rewards.values[1], tasks[t].rewards.values[2])
  197. elseif isInArray({"points", "rank", 2}, tasks[t].rewards.type) then
  198. doCreatureSetStorage(cid, rankStorage, getCreatureStorage(cid, rankStorage) + tasks[t].rewards.values)
  199. else
  200. print("[Warning - Npc::KillingInTheNameOf] Wrong reward type: " .. (tasks[t].rewards.type or "nil") .. ", reward could not be loaded.")
  201. end
  202. end
  203. end
  204. local rank = getCreatureStorage(cid, rankStorage)
  205. selfSay("Great!... you have finished the task number " .. t .. "" .. (rank > 4 and ", you are a " or "") .. "" .. (((rank > 4 and rank < 10) and ("Huntsman") or (rank > 9 and rank < 20) and ("Ranger") or (rank > 19 and rank < 30) and ("Big Game Hunter") or (rank > 29 and rank < 50) and ("Trophy Hunter") or (rank > 49) and ("Elite Hunter")) or "") .. ". Good job.", cid)
  206. return doCreatureSetStorage(cid, tasks[t].questStarted, 2)
  207. end
  208. return true
  209. end
  210.  
  211. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  212. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement