Advertisement
Guest User

Untitled

a guest
Dec 10th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.94 KB | None | 0 0
  1. dofile('data/lib/killingInTheNameOfQuest.lua')
  2. --dofile('data/lib/StorageList.lua')
  3. local keywordHandler = KeywordHandler:new()
  4. local npcHandler = NpcHandler:new(keywordHandler)
  5. NpcSystem.parseParameters(npcHandler)
  6. local talkState = {}
  7.  
  8. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  9. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  10. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  11. function onThink() npcHandler:onThink() end
  12.  
  13. local choose = {}
  14. local cancel = {}
  15. local available = {}
  16.  
  17. local grizzlyAdamsConfig = {
  18. ranks = {
  19. huntsMan_rank = {
  20. {id=11208, buy=0, sell=50, name='antlers'},
  21. {id=10549, buy=0, sell=100, name='bloody pincers'},
  22. {id=11183, buy=0, sell=35, name='crab pincers'},
  23. {id=10573, buy=0, sell=55, name='cyclops toe'},
  24. {id=10564, buy=0, sell=30, name='frosty ear of a troll'},
  25. {id=11193, buy=0, sell=600, name='hydra head'},
  26. {id=11366, buy=0, sell=80, name='lancer beetle shell'},
  27. {id=10578, buy=0, sell=420, name='mutated bat ear'},
  28. {id=11222, buy=0, sell=400, name='sabretooth'},
  29. {id=11367, buy=0, sell=20, name='sandcrawler shell'},
  30. {id=10547, buy=0, sell=280, name='scarab pincers'},
  31. {id=11365, buy=0, sell=60, name='terramite legs'},
  32. {id=11363, buy=0, sell=170, name='terramite shell'},
  33. {id=11184, buy=0, sell=30000, name='terrorbird beak'},
  34.  
  35. {id=7398, buy=0, sell=500, name='cyclops trophy'},
  36. {id=11315, buy=0, sell=15000, name='draken trophy'},
  37. {id=11330, buy=0, sell=8000, name='lizard trophy'},
  38. {id=7401, buy=0, sell=500, name='minotaur trophy'}
  39. },
  40.  
  41. bigGameHunter_rank = {
  42. {id=7397, buy=0, sell=3000, name='deer trophy'},
  43. {id=7400, buy=0, sell=3000, name='lion trophy'},
  44. {id=7394, buy=0, sell=3000, name='wolf trophy'}
  45. },
  46.  
  47. trophyHunter_rank = {
  48. {id=7393, buy=0, sell=40000, name='demon trophy'},
  49. {id=7396, buy=0, sell=20000, name='behemoth trophy'},
  50. {id=7399, buy=0, sell=10000, name='dragon lord trophy'},
  51.  
  52. {id=10518, buy=1000, sell=0, name='demon backpack'},
  53. },
  54. }
  55. }
  56.  
  57. local Topic = {}
  58. function greetCallback(cid)
  59. Topic[cid] = 0
  60. return true
  61. end
  62.  
  63. local function setNewTradeTable(table)
  64. local items = {}
  65. for _, v in ipairs(table) do
  66. items[v.id] = {itemId = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
  67. end
  68. return items
  69. end
  70.  
  71. local function setNewLineTable(oldTable, newTable)
  72. for k, v in pairs(oldTable) do
  73. table.insert(newTable, k, v)
  74. end
  75. return true
  76. end
  77.  
  78. function creatureSayCallback(cid, type, msg)
  79. local player = Player(cid)
  80. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
  81. if (msgcontains(msg, "hi") or msgcontains(msg, "hello")) and (not npcHandler:isFocused(cid)) then
  82. if (player:getStorageValue(JOIN_STOR) == -1) then
  83. npcHandler:say("Welcome "..getCreatureName(cid)..". Would you like to join the 'Paw and Fur - Hunting Elite'?", cid)
  84. npcHandler:addFocus(cid)
  85. talkState[talkUser] = 5
  86. else
  87. npcHandler:say("Welcome back old chap. What brings you here this time?", cid)
  88. npcHandler:addFocus(cid)
  89. talkState[talkUser] = 0
  90. end
  91. return true
  92. end
  93.  
  94. if(not npcHandler:isFocused(cid)) then
  95. return false
  96. end
  97.  
  98. if msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
  99. npcHandler:say("Happy hunting, old chap!", cid, TRUE)
  100. Topic[talkUser] = 0
  101. npcHandler:releaseFocus(cid)
  102. npcHandler:resetNpc(cid)
  103. end
  104.  
  105. if (isInArray({"yes", "join"}, msg:lower()) and talkState[talkUser] == 5) then
  106. player:setStorageValue(JOIN_STOR, 1)
  107. npcHandler:say("Great! A warm welcome to our newest member: "..getCreatureName(cid).."! Ask me for a {task} if you want to go on a hunt.", cid)
  108. talkState[talkUser] = 0
  109. elseif (msg:lower() == "no" and talkState[talkUser] == 5) then
  110. npcHandler:say("No problem old chap. Come back if you change your mind.", cid)
  111. end
  112.  
  113. if (player:getStorageValue(JOIN_STOR) == -1) then
  114. npcHandler:say("You'll have to {join} us to get more information.",cid)
  115. return false
  116. end
  117. if isInArray({"offer", "trade"}, msg:lower()) then
  118. if getPlayerRank(cid) >= 2 then
  119. if getPlayerRank(cid) == 2 or getPlayerRank(cid) == 3 then
  120. tradeRank = grizzlyAdamsConfig.ranks.huntsMan_rank
  121. elseif getPlayerRank(cid) == 4 then
  122. tradeRank = grizzlyAdamsConfig.ranks.bigGameHunter_rank
  123. setNewLineTable(grizzlyAdamsConfig.ranks.huntsMan_rank, grizzlyAdamsConfig.ranks.bigGameHunter_rank)
  124. elseif getPlayerRank(cid) == 5 or getPlayerRank(cid) == 6 then
  125. tradeRank = grizzlyAdamsConfig.ranks.trophyHunter_rank
  126. setNewLineTable(grizzlyAdamsConfig.ranks.huntsMan_rank, grizzlyAdamsConfig.ranks.bigGameHunter_rank)
  127. setNewLineTable(grizzlyAdamsConfig.ranks.huntsMan_rank, grizzlyAdamsConfig.ranks.trophyHunter_rank)
  128. end
  129. local items = setNewTradeTable(tradeRank)
  130. local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
  131. if ignoreCap == false and (player:getFreeCapacity() < getItemWeight(items[item].itemId, amount) or inBackpacks and player:getFreeCap() < (getItemWeight(items[item].itemId, amount) + getItemWeight(1988, 1))) then
  132. return player:sendTextMessage(MESSAGE_INFO_DESCR, 'You don\'t have enough cap.')
  133. end
  134. if items[item].buyPrice then
  135. player:removeMoney(amount * items[item].buyPrice)
  136. for i = 1, amount do
  137. if inBackpacks then
  138. local backpack = doCreateItemEx(1988, 1)
  139. doAddContainerItem(backpack, items[item].itemId, amount)
  140. else
  141. player:addItem(items[item].itemId, amount, true)
  142. end
  143. end
  144. return player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.')
  145. end
  146. return true
  147. end
  148.  
  149. local function onSell(cid, item, subType, amount, ignoreCap, inBackpacks)
  150. if items[item].sellPrice then
  151. player:addMoney(items[item].sellPrice * amount)
  152. player:removeItem(items[item].itemId, amount)
  153. return player:sendTextMessage(cid, MESSAGE_INFO_DESCR, 'You sold '..amount..'x '..items[item].realName..' for '..items[item].sellPrice * amount..' gold coins.')
  154. end
  155. return true
  156. end
  157. openShopWindow(cid, tradeRank, onBuy, onSell)
  158. return npcHandler:say('It\'s my offer.', player)
  159. else
  160. return npcHandler:say('You don\'t have any rank.', player)
  161. end
  162. end
  163.  
  164. if isInArray({"tasks", "task", "mission"}, msg:lower()) then
  165. local can = getTasksByPlayer(cid)
  166. if (player:getStorageValue(JOIN_STOR) == -1) then
  167. return (npcHandler:say("You'll have to {join}, to get any {tasks}.",cid))
  168. end
  169. if #can > 0 then
  170. local text = ""
  171. local sep = ", "
  172. table.sort(can, (function(a, b) return (a < b) end))
  173. local t = 0
  174. for _, id in ipairs(can) do
  175. t = t + 1
  176. if t == #can - 1 then
  177. sep = " and "
  178. elseif t == #can then
  179. sep = "."
  180. end
  181. text = text .. "{" .. (tasks[id].name or tasks[id].raceName) .. "}" .. sep
  182. end
  183. npcHandler:say("The current task" .. (#can > 1 and "s" or "") .. " that you can choose " .. (#can > 1 and "are" or "is") .. " " .. text, player)
  184. talkState[talkUser] = 0
  185. else
  186. npcHandler:say("I don't have any task for you right now.", player)
  187. end
  188. elseif msg ~= "" and canStartTask(cid, msg) then
  189. if #getPlayerStartedTasks(cid) >= tasksByPlayer then
  190. npcHandler:say("Sorry, but you already started " .. tasksByPlayer .. " tasks. You can check their {status} or {cancel} a task.", player)
  191. return true
  192. end
  193. local task = getTaskByName(msg)
  194. if task and player:getStorageValue(QUESTSTORAGE_BASE + task) > 0 then
  195. return false
  196. end
  197. npcHandler:say("In this task you must defeat " .. tasks[task].killsRequired .. " " .. tasks[task].raceName .. ". Are you sure that you want to start this task?", player)
  198. choose[cid] = task
  199. talkState[talkUser] = 1
  200. elseif msg:lower() == "yes" and talkState[talkUser] == 1 then
  201. player:setStorageValue(QUESTSTORAGE_BASE + choose[cid], 1)
  202. player:setStorageValue(KILLSSTORAGE_BASE + choose[cid], 0)
  203. npcHandler:say("Excellent! You can check the {status} of your task saying {report} to me. Also you can {cancel} tasks to.", player)
  204. choose[cid] = nil
  205. talkState[talkUser] = 0
  206. elseif (msg:lower() == "report" or msg:lower() == "status") then
  207. local started = getPlayerStartedTasks(cid)
  208. local finishedAtLeastOne = false
  209. local finished = 0
  210. if started and #started > 0 then
  211. for _, id in ipairs(started) do
  212. if player:getStorageValue(KILLSSTORAGE_BASE + id) >= tasks[id].killsRequired then
  213. for _, reward in ipairs(tasks[id].rewards) do
  214. local deny = false
  215. if reward.storage then
  216. if player:getStorageValue(reward.storage[1]) >= reward.storage[2] then
  217. deny = true
  218. end
  219. end
  220. if isInArray({REWARD_MONEY, "money"}, reward.type:lower()) and not deny then
  221. doPlayerAddMoney(cid, reward.value[1])
  222. elseif isInArray({REWARD_EXP, "exp", "experience"}, reward.type:lower()) and not deny then
  223. doPlayerAddExp(cid, reward.value[1], false, reward.value[1], false, true)
  224. doPlayerSendDefaultCancel(cid, "You gained " .. reward.value[1] .. " experience points.")
  225. elseif isInArray({REWARD_ACHIEVEMENT, "achievement", "ach"}, reward.type:lower()) and not deny then
  226. elseif isInArray({REWARD_STORAGE, "storage", "stor"}, reward.type:lower()) and not deny then
  227. player:setStorageValue(reward.value[1], reward.value[2])
  228. elseif isInArray({REWARD_POINT, "points", "point"}, reward.type:lower()) and not deny then
  229. player:setStorageValue(POINTSSTORAGE, player:getStorageValue(POINTSSTORAGE) + reward.value[1])
  230. elseif isInArray({REWARD_ITEM, "item", "items", "object"}, reward.type:lower()) and not deny then
  231. doPlayerAddItem(cid, reward.value[1], reward.value[2])
  232. end
  233.  
  234. if reward.storage then
  235. player:setStorageValue(reward.storage[1], reward.storage[2])
  236. end
  237. end
  238.  
  239. if tasks[id].norepeatable then
  240. player:setStorageValue(QUESTSTORAGE_BASE + id, 2)
  241. else
  242. player:setStorageValue(QUESTSTORAGE_BASE + id, 0)
  243. end
  244. player:setStorageValue(KILLSSTORAGE_BASE + id, 0)
  245. if player:getStorageValue(REPEATSTORAGE_BASE + id) < 1 then
  246. player:setStorageValue(REPEATSTORAGE_BASE + id, 0)
  247. end
  248. player:setStorageValue(REPEATSTORAGE_BASE + id, player:getStorageValue(REPEATSTORAGE_BASE + id) + 1)
  249. finishedAtLeastOne = true
  250. finished = finished + 1
  251. end
  252. end
  253. if (not finishedAtLeastOne) then
  254. local started = getPlayerStartedTasks(cid)
  255. if (started and #started > 0) then
  256. local text = ""
  257. local sep = ", "
  258. table.sort(started, (function(a, b) return (a < b) end))
  259. local t = 0
  260. for _, id in ipairs(started) do
  261. t = t + 1
  262. if (t == #started - 1) then
  263. sep = " and "
  264. elseif (t == #started) then
  265. sep = "."
  266. end
  267. text = text .. "{" .. (tasks[id].name or tasks[id].raceName) .. "}" .. sep
  268. end
  269. npcHandler:say("The current task" .. (#started > 1 and "s" or "") .. " that you started " .. (#started > 1 and "are" or "is") .. " " .. text, player)
  270. Topic[cid] = 1
  271. else
  272. npcHandler:say("Awesome! you finished " .. (finished > 1 and "various" or "a") .. " task" .. (finished > 1 and "s" or "") .. ". Talk to me again if you want to start a {task}.", player)
  273. end
  274. else
  275. npcHandler:say("You haven't started any task yet.", player)
  276. end
  277. end
  278. elseif msg:lower() == "started" then
  279. local started = getPlayerStartedTasks(cid)
  280. if started and #started > 0 then
  281. local text = ""
  282. local sep = ", "
  283. table.sort(started, (function(a, b) return (a < b) end))
  284. local t = 0
  285. for _, id in ipairs(started) do
  286. t = t + 1
  287. if t == #started - 1 then
  288. sep = " and "
  289. elseif t == #started then
  290. sep = "."
  291. end
  292. text = text .. "{" .. (tasks[id].name or tasks[id].raceName) .. "}" .. sep
  293. end
  294.  
  295. npcHandler:say("The current task" .. (#started > 1 and "s" or "") .. " that you started " .. (#started > 1 and "are" or "is") .. " " .. text, player)
  296. else
  297. npcHandler:say("You haven't started any task yet.", player)
  298. end
  299. elseif msg:lower() == "cancel" then
  300. local started = getPlayerStartedTasks(cid)
  301. local task = getTaskByName(msg)
  302. local text = ""
  303. local sep = ", "
  304. table.sort(started, (function(a, b) return (a < b) end))
  305. local t = 0
  306. for _, id in ipairs(started) do
  307. t = t + 1
  308. if t == #started - 1 then
  309. sep = " or "
  310. elseif t == #started then
  311. sep = "?"
  312. end
  313. text = text .. "{" .. (tasks[id].name or tasks[id].raceName) .. "}" .. sep
  314. end
  315. if started and #started > 0 then
  316. npcHandler:say("Cancelling a task will make the counter restart. Which of these tasks you want cancel?" .. (#started > 1 and "" or "") .. " " .. text, player)
  317. talkState[talkUser] = 2
  318. else
  319. npcHandler:say("You haven't started any task yet.", player)
  320. end
  321. elseif getTaskByName(msg) and talkState[talkUser] == 2 and isInArray(getPlayerStartedTasks(cid), getTaskByName(msg)) then
  322. local task = getTaskByName(msg)
  323. if player:getStorageValue(KILLSSTORAGE_BASE + task) > 0 then
  324. npcHandler:say("You currently killed " .. player:getStorageValue(KILLSSTORAGE_BASE + task) .. "/" .. tasks[task].killsRequired .. " " .. tasks[task].raceName .. ". Cancelling this task will restart the count. Are you sure you want to cancel this task?", player)
  325. else
  326. npcHandler:say("Are you sure you want to cancel this task?", player)
  327. end
  328. talkState[talkUser] = 3
  329. cancel[cid] = task
  330. elseif getTaskByName(msg) and Topic[cid] == 1 and isInArray(getPlayerStartedTasks(cid), getTaskByName(msg)) then
  331. local task = getTaskByName(msg)
  332. if player:getStorageValue(KILLSSTORAGE_BASE + task) > 0 then
  333. npcHandler:say("You currently killed " .. player:getStorageValue(KILLSSTORAGE_BASE + task) .. "/" .. tasks[task].killsRequired .. " " .. tasks[task].raceName .. ".", player)
  334. Topic[cid] = 0
  335. else
  336. npcHandler:say("You currently killed 0/" .. tasks[task].killsRequired .. " " .. tasks[task].raceName .. ".", player)
  337. end
  338. elseif msg:lower() == "yes" and talkState[talkUser] == 3 then
  339. player:setStorageValue(QUESTSTORAGE_BASE + cancel[cid], -1)
  340. player:setStorageValue(KILLSSTORAGE_BASE + cancel[cid], -1)
  341. npcHandler:say("You have cancelled the task " .. (tasks[cancel[cid]].name or tasks[cancel[cid]].raceName) .. ".", player)
  342. talkState[talkUser] = 0
  343. elseif isInArray({"points", "rank"}, msg:lower()) then
  344. if player:getStorageValue(POINTSSTORAGE) < 1 then
  345. npcHandler:say("At this time, you have 0 Paw & Fur points. You " .. (getPlayerRank(cid) == 6 and "are an Elite Hunter" or getPlayerRank(cid) == 5 and "are a Trophy Hunter" or getPlayerRank(cid) == 4 and "are a Big Game Hunter" or getPlayerRank(cid) == 3 and "are a Ranger" or getPlayerRank(cid) == 2 and "are a Huntsman" or getPlayerRank(cid) == 1 and "are a Member" or "haven't been ranked yet") .. ".", player)
  346. elseif player:getStorageValue(POINTSSTORAGE) >= 1 then
  347. npcHandler:say("At this time, you have " .. player:getStorageValue(POINTSSTORAGE) .. " Paw & Fur points. You " .. (getPlayerRank(cid) == 6 and "are an Elite Hunter" or getPlayerRank(cid) == 5 and "are a Trophy Hunter" or getPlayerRank(cid) == 4 and "are a Big Game Hunter" or getPlayerRank(cid) == 3 and "are a Ranger" or getPlayerRank(cid) == 2 and "are a Huntsman" or getPlayerRank(cid) == 1 and "are a Member" or "haven't been ranked yet") .. ".", player)
  348. end
  349. talkState[talkUser] = 0
  350. end
  351. end
  352.  
  353. npcHandler:setMessage(MESSAGE_FAREWELL, "Happy hunting, old chap!")
  354. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement