Advertisement
Kaiquegabriel

npc lua

Jul 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. domodlib('task_func')
  2.  
  3. local keywordHandler = KeywordHandler:new()
  4.  
  5. local npcHandler = NpcHandler:new(keywordHandler)
  6.  
  7. NpcSystem.parseParameters(npcHandler)
  8.  
  9. local talkState = {}
  10.  
  11. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  12.  
  13. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  14.  
  15. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  16.  
  17. function onThink() npcHandler:onThink() end
  18.  
  19. function creatureSayCallback(cid, type, msg)
  20.  
  21. if(not npcHandler:isFocused(cid)) then
  22.  
  23. return false
  24.  
  25. end
  26.  
  27. local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
  28.  
  29. local msg = string.lower(msg)
  30.  
  31. if isInArray({"task","tasks"}, msg) then
  32.  
  33. npcHandler:say("Hmm.. you need an task mission, yah? I can give you acess to kill {rat}, {troll}, {rotworm}, {cyclops}, {thornback tortoise}, {tarantula}, {monkey}, {mammoth}, {carniphila}, {minotaur}, {stone golem}, {dragon}, {bonebeast}, {ice golem}, {crystal spider}, {nightmare}, {hydra}, {giant spider}, {ancient scarab}, {bonebeast}, {nightmare}, {serpent spawn}, {medusa}, {} and {}. What creature you want to hunt?", cid)
  34.  
  35. talkState[talkUser] = 1
  36.  
  37. elseif talkState[talkUser] == 1 then
  38.  
  39. if tasktabble[msg] then
  40.  
  41. if CheckTask(cid) ~= true then
  42.  
  43. local contagem = getPlayerStorageValue(cid, tasktabble[msg].storage)
  44.  
  45. if (contagem == -1) then contagem = 1 end
  46.  
  47. if not tonumber(contagem) then npcHandler:say('Sorry, you finished task of '..msg, cid) return true end
  48.  
  49. setPlayerStorageValue(cid, tasktabble[msg].storage_start, 1)
  50.  
  51. npcHandler:say("Great! you started the "..msg.." task and need to kill "..string.sub(((contagem)-1)-tasktabble[msg].count, 2).." ."..msg, cid)
  52.  
  53. talkState[talkUser] = 0
  54.  
  55. else
  56.  
  57. npcHandler:say('Sorry, you are in a task!', cid)
  58.  
  59. talkState[talkUser] = 0
  60.  
  61. end
  62.  
  63. else
  64.  
  65. npcHandler:say('I need the correct information about the creature, please use {!task} to see all tasks availables.', cid)
  66.  
  67. talkState[talkUser] = 1
  68.  
  69. end
  70.  
  71. elseif isInArray({"receber","reward","report"}, msg) then
  72.  
  73. if CheckTask(cid) then
  74.  
  75. for k, v in pairs(tasktabble) do
  76.  
  77. racetype = k
  78.  
  79. if getPlayerStorageValue(cid,v.storage_start) >= 1 then
  80.  
  81. local contagem = getPlayerStorageValue(cid, v.storage)
  82.  
  83. if (contagem == -1) then contagem = 1 end
  84.  
  85. if not tonumber(contagem) then npcHandler:say('You only can receive the itens one time per task!', cid) return true end
  86.  
  87. if (((contagem)-1) >= v.count) then
  88.  
  89. for _, check in pairs(configbosses_task) do
  90.  
  91. if string.lower(check.race) == string.lower(racetype) then
  92.  
  93. local on = getPlayersOnline()
  94.  
  95. for i=1, #on do
  96.  
  97. if HavePlayerPosition(on[i], check.FromPosToPos[1],check.FromPosToPos[2]) then
  98.  
  99. selfSay('aguarde alguns instantes, tem pessoas fazendo a task.', cid) return true
  100.  
  101. end
  102.  
  103. end
  104.  
  105. doTeleportThing(cid, check.Playerpos)
  106.  
  107. local function checkArea(cid)
  108.  
  109. if not isCreature(cid) then return LUA_ERROR end
  110.  
  111. if HavePlayerPosition(cid, check.FromPosToPos[1],check.FromPosToPos[2]) then
  112.  
  113. doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
  114.  
  115. end
  116.  
  117. end
  118.  
  119. addEvent(checkArea, check.time*60*1000, cid)
  120.  
  121. end
  122.  
  123. end
  124.  
  125. local str = ""
  126.  
  127. if v.exp ~= nil then doPlayerAddExp(cid, v.exp ) str = str.."".. (str == "" and "" or "and ") .." "..v.exp.." experience points" end
  128.  
  129. if v.money ~= nil then doPlayerAddMoney(cid, v.money) str = str.."".. (str == "" and "" or "and ") ..""..v.money.." gps" end
  130.  
  131. if v.reward ~= nil then doAddItemsFromList(cid,v.reward) str = str.."".. (str == "" and "" or ", ") ..""..getItemsFromList(v.reward) end
  132.  
  133. npcHandler:say("Thank you for helping! Your reward is:"..(str == "" and "nothing" or ""..str.."").." for finish the task "..k, cid)
  134.  
  135. setPlayerStorageValue(cid, v.storage, "Finished")
  136.  
  137. setPlayerStorageValue(cid, v.storage_start, 0)
  138.  
  139. setPlayerStorageValue(cid, 521456, getPlayerStorageValue(cid, 521456) == -1 and 1 or getPlayerStorageValue(cid, 521456)+1)
  140.  
  141. finisheAllTask(cid)
  142.  
  143. else
  144.  
  145. npcHandler:say('Sorry, you killed only '..((contagem)-1)..' de '..v.count..' '..k, cid)
  146.  
  147. end
  148.  
  149. end
  150.  
  151. end
  152.  
  153. else
  154.  
  155. npcHandler:say("You are not in a task to receive an reward.", cid)
  156.  
  157. end
  158.  
  159. elseif isInArray({"sair","leave","exit"}, msg) then
  160.  
  161. if CheckTask(cid) then
  162.  
  163. talkState[talkUser] = 2
  164.  
  165. for k, v in pairs(tasktabble) do
  166.  
  167. if getPlayerStorageValue(cid,v.storage_start) >= 1 then
  168.  
  169. storagesair = v.storage_start
  170.  
  171. local contagem = getPlayerStorageValue(cid, v.storage)
  172.  
  173. if (contagem == -1) then contagem = 1 end
  174.  
  175. npcHandler:say('You have an progress off '..k..' and have killed '..((contagem)-1)..' '..k..' really want to leave from this task?', cid)
  176.  
  177. end
  178.  
  179. end
  180.  
  181. else
  182.  
  183. npcHandler:say("You are not in a task.", cid)
  184.  
  185. end
  186.  
  187. elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
  188.  
  189. setPlayerStorageValue(cid, storagesair, 0)
  190.  
  191. npcHandler:say("Você foi retirado da task com sucesso!", cid)
  192.  
  193. elseif msg == "no" then
  194.  
  195. selfSay("Ok.", cid)
  196.  
  197. talkState[talkUser] = 0
  198.  
  199. npcHandler:releaseFocus(cid)
  200.  
  201. end
  202.  
  203. return TRUE
  204.  
  205. end
  206.  
  207. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  208.  
  209. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement