Advertisement
Kevick

Task System BY KEVICK

May 25th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. Vá em creaturescripts.xml e adicione isso:
  2.  
  3. <event type="kill" name="KillTask" event="script" value="task.lua"/>
  4. No login.lua adiciona isso com os demais:
  5.  
  6. registerCreatureEvent(cid, "KillTask")
  7. Agora crie um arquivo chamado task.lua e adicione isso:
  8.  
  9. local tasksss = {
  10. [1] = {name = "Blastoise", sto = 10212, count = 3, time_sto = 5457, time = 1*24*60*60, sto_count = 14129, money = 100, rewardid = 7621, rewardcount = 100, rewardexp = 10000, text = "Congratulations! You finished this task. In 24h, you will be able to do it again."},
  11. [2] = {name = "Charizard", sto = 10213, count = 5, time_sto = 5458, time = 1*24*60*60, sto_count = 14130, money = 100, rewardid = 7621, rewardcount = 100, rewardexp = 10000, text = "Congratulations! You finished this task. In 24h, you will be able to do it again."},
  12. }
  13.  
  14. function onKill(cid, target)
  15. for _, t in ipairs(tasksss) do
  16. local total_count = t.count
  17. local m_sto = t.sto
  18. local count_sto = t.sto_count
  19. if getPlayerStorageValue(cid, m_sto) ~= -1 then
  20. if getCreatureName(target) == t.name then
  21. if (total_count - getPlayerStorageValue(cid, count_sto)) == 1 then
  22. setPlayerStorageValue(cid, count_sto, getPlayerStorageValue(cid, count_sto) + 1)
  23. doPlayerSendTextMessage(cid, 20, "You are killed ".. getPlayerStorageValue(cid, count_sto) .." " .. t.name .. " and finished the task!")
  24. return true
  25. elseif (total_count - getPlayerStorageValue(cid, count_sto)) >= 1 then
  26. setPlayerStorageValue(cid, count_sto, getPlayerStorageValue(cid, count_sto) + 1)
  27. doPlayerSendTextMessage(cid, 20, "You are killed ".. getPlayerStorageValue(cid, count_sto) .." of ".. total_count .." " .. t.name .. " kills to finish the task.")
  28. return true
  29. end
  30. end
  31. end
  32. end
  33. return true
  34. end
  35. Agora vá em npc/scripts e crie um arquivo chamado task.lua e adicione isso:
  36.  
  37. local tasksss = {
  38. [1] = {name = "Blastoise", sto = 10212, count = 3, time_sto = 5457, time = 1*24*60*60, sto_count = 14129, money = 100, rewardid = 7621, rewardcount = 100, rewardexp = 10000, text = "Congratulations! You finished this task. In 24h, you will be able to do it again."},
  39. [2] = {name = "Charizard", sto = 10213, count = 5, time_sto = 5458, time = 1*24*60*60, sto_count = 14130, money = 100, rewardid = 7621, rewardcount = 100, rewardexp = 10000, text = "Congratulations! You finished this task. In 24h, you will be able to do it again."},
  40. }
  41.  
  42. local keywordHandler = KeywordHandler:new()
  43. local npcHandler = NpcHandler:new(keywordHandler)
  44. NpcSystem.parseParameters(npcHandler)
  45. local talkState = {}
  46. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  47. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  48. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  49. function onThink() npcHandler:onThink() end
  50. function creatureSayCallback(cid, type, msg)
  51. if(not npcHandler:isFocused(cid)) then
  52. return false
  53. end
  54. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  55. value = -1
  56. for i = 1, #tasksss do
  57. if msgcontains(msg, tasksss[i].name) and not value ~= -1 then
  58. value = i
  59. end
  60. end
  61. if value == -1 then
  62. selfSay('I don\'t have a this task!', cid)
  63. talkState[talkUser] = 0
  64. return true
  65. end
  66. local configss = tasksss[value]
  67. local name = configss.name
  68. local m_sto = configss.sto
  69. local time_sto = configss.time_sto
  70. local count_sto = configss.sto_count
  71. local total_count = configss.count
  72. local rest = total_count - getPlayerStorageValue(cid, count_sto)
  73. if getPlayerStorageValue(cid, time_sto) < os.time() then -- verifica se o player ainda está no prazo
  74. if getPlayerStorageValue(cid, m_sto) <= 0 then -- verifica se o player não pegou está task
  75. selfSay('Ready! Now you need kill a '.. total_count .. ' '.. name .. '!', cid)
  76. setPlayerStorageValue(cid, m_sto, 1)
  77. setPlayerStorageValue(cid, total_count, 0)
  78. talkState[talkUser] = 0
  79. else
  80. if rest <= 0 then -- Verifica se o player matou todos os monstros nescessários
  81. doPlayerAddItem(cid, configss.rewardid, configss.rewardcount)
  82. setPlayerStorageValue(cid, count_sto, 0)
  83. setPlayerStorageValue(cid, m_sto, -1)
  84. setPlayerStorageValue(cid, time_sto, os.time() + configss.time)
  85. doPlayerAddExperience(cid, configss.rewardexp)
  86. doSendAnimatedText(getCreaturePosition(cid), configss.rewardexp, 215)
  87. selfSay(configss.text, cid)
  88. talkState[talkUser] = 0
  89. else
  90. selfSay('You need to kill '..rest..' '..name..' to gain a reward.', cid)
  91. talkState[talkUser] = 0
  92. end
  93. end
  94. else
  95. selfSay('You already did this task, player. Wait '..math.ceil((getPlayerStorageValue(cid, time_sto) - os.time())/(60*60))..' hours to do it again.', cid)
  96. talkState[talkUser] = 0
  97. end
  98. end
  99. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  100. npcHandler:addModule(FocusModule:new())
  101. Pronto, agora volte para a pasta npc e crie um novo arquivo .xml chamado de Task e adicione isso lá:
  102.  
  103. <?xml version="1.0" encoding="UTF-8"?>
  104. <npc name="Npc Nome" script="task.lua" walkinterval="350000" floorchange="0" speed="0">
  105. <health now="150" max="150"/>
  106. <look type="369" head="91" body="102" legs="83" feet="0"/>
  107. <parameters>
  108. <parameter key="message_greet" value="You want gain a task of {Blastoise}?"/>
  109. </parameters>
  110. </npc>
  111. Pronto, agora o sistema de task está funcionando, e para adicionar um novo monstro pra fazer a task? Basta editar a tabela, mas não esqueça que tem que atualizar a tabela nos 2 scripts .lua !!
  112.  
  113. local tasksss = {
  114. [1] = {name = "Blastoise", sto = 10212, count = 3, time_sto = 5457, time = 1*24*60*60, sto_count = 14129, money = 100, rewardid = 7621, rewardcount = 100, rewardexp = 10000, text = "Congratulations! You finished this task. In 24h, you will be able to do it again."},
  115. [2] = {name = "Charizard", sto = 10213, count = 5, time_sto = 5458, time = 1*24*60*60, sto_count = 14130, money = 100, rewardid = 7621, rewardcount = 100, rewardexp = 10000, text = "Congratulations! You finished this task. In 24h, you will be able to do it again."},
  116. }
  117.  
  118. Para configurar siga as seguintes instruções:
  119.  
  120. Name = Nome da criatura da task
  121. sto = Coloque um valor a mais do valor anterior configurado
  122. count = quantidade de monstros a ser morto
  123. time_sto = Coloque um valor a mais do anterior
  124. time = tempo que poderá fazer a task novamente
  125. sto_count = Um valor a mais do valor anterior
  126. money = Quantidade de dinheiro que o player irá receber, caso coloque 0, não ira receber nada
  127. rewardid = itemid do item que player irá ganhar
  128. rewardcount = quantidade do item adicionado anteriormente
  129. rewardexp = quantidade de exp que player irá ganhar
  130. text = Texto que irá aparecer quando player terminar a task
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement