Advertisement
Guest User

Untitled

a guest
May 23rd, 2023
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.96 KB | None | 0 0
  1. -- Custom Modules, created to help us in this datapack
  2. local travelDiscounts = {
  3. ['postman'] = {price = 10, storage = Storage.postman.Rank, value = 3},
  4. ['new frontier'] = {price = 50, storage = Storage.TheNewFrontier.Mission03, value = 1}
  5. }
  6.  
  7. function StdModule.travelDiscount(player, discounts)
  8. local discountPrice, discount = 0
  9. if type(discounts) == 'string' then
  10. discount = travelDiscounts[discounts]
  11. if discount and player:getStorageValue(discount.storage) >= discount.value then
  12. return discount.price
  13. end
  14. else
  15. for i = 1, #discounts do
  16. discount = travelDiscounts[discounts[i]]
  17. if discount and player:getStorageValue(discount.storage) >= discount.value then
  18. discountPrice = discountPrice + discount.price
  19. end
  20. end
  21. end
  22.  
  23. return discountPrice
  24. end
  25.  
  26. function StdModule.kick(cid, message, keywords, parameters, node)
  27. local npcHandler = parameters.npcHandler
  28. if npcHandler == nil then
  29. error("StdModule.travel called without any npcHandler instance.")
  30. end
  31.  
  32. if not npcHandler:isFocused(cid) then
  33. return false
  34. end
  35.  
  36. npcHandler:releaseFocus(cid)
  37. npcHandler:say(parameters.text or "Off with you!", cid)
  38.  
  39. local destination = parameters.destination
  40. if type(destination) == 'table' then
  41. destination = destination[math.random(#destination)]
  42. end
  43.  
  44. Player(cid):teleportTo(destination, true)
  45.  
  46. npcHandler:resetNpc(cid)
  47. return true
  48. end
  49.  
  50. local GreetModule = {}
  51. function GreetModule.greet(cid, message, keywords, parameters)
  52. if not parameters.npcHandler:isInRange(cid) then
  53. return true
  54. end
  55.  
  56. if parameters.npcHandler:isFocused(cid) then
  57. return true
  58. end
  59.  
  60. local parseInfo = { [TAG_PLAYERNAME] = Player(cid):getName() }
  61. parameters.npcHandler:say(parameters.npcHandler:parseMessage(parameters.text, parseInfo), cid, true)
  62. parameters.npcHandler:addFocus(cid)
  63. return true
  64. end
  65.  
  66. function GreetModule.farewell(cid, message, keywords, parameters)
  67. if not parameters.npcHandler:isFocused(cid) then
  68. return false
  69. end
  70.  
  71. local parseInfo = { [TAG_PLAYERNAME] = Player(cid):getName() }
  72. parameters.npcHandler:say(parameters.npcHandler:parseMessage(parameters.text, parseInfo), cid, true)
  73. parameters.npcHandler:resetNpc(cid)
  74. parameters.npcHandler:releaseFocus(cid)
  75. return true
  76. end
  77.  
  78. -- Adds a keyword which acts as a greeting word
  79. function KeywordHandler:addGreetKeyword(keys, parameters, condition, action)
  80. local keys = keys
  81. keys.callback = FocusModule.messageMatcherDefault
  82. return self:addKeyword(keys, GreetModule.greet, parameters, condition, action)
  83. end
  84.  
  85. -- Adds a keyword which acts as a farewell word
  86. function KeywordHandler:addFarewellKeyword(keys, parameters, condition, action)
  87. local keys = keys
  88. keys.callback = FocusModule.messageMatcherDefault
  89. return self:addKeyword(keys, GreetModule.farewell, parameters, condition, action)
  90. end
  91.  
  92. -- Adds a keyword which acts as a spell word
  93. function KeywordHandler:addSpellKeyword(keys, parameters)
  94. local keys = keys
  95. keys.callback = FocusModule.messageMatcherDefault
  96.  
  97. local npcHandler, spellName, price, vocationId = parameters.npcHandler, parameters.spellName, parameters.price, parameters.vocation
  98. local spellKeyword = self:addKeyword(keys, StdModule.say, {npcHandler = npcHandler, text = string.format("Do you want to learn the spell '%s' for %s?", spellName, price > 0 and price .. ' gold' or 'free')},
  99. function(player)
  100. local baseVocationId = player:getVocation():getBase():getId()
  101. if type(vocationId) == 'table' then
  102. return isInArray(vocationId, baseVocationId)
  103. else
  104. return vocationId == baseVocationId
  105. end
  106. end
  107. )
  108.  
  109. spellKeyword:addChildKeyword({'yes'}, StdModule.learnSpell, {npcHandler = npcHandler, spellName = spellName, level = parameters.level, price = price})
  110. spellKeyword:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'Maybe next time.', reset = true})
  111. end
  112.  
  113. local hints = {
  114. [-1] = 'If you don\'t know the meaning of an icon on the right side, move the mouse cursor on it and wait a moment.',
  115. [0] = 'Send private messages to other players by right-clicking on the player or the player\'s name and select \'Message to ....\'. You can also open a \'private message channel\' and type in the name of the player.',
  116. [1] = 'Use the shortcuts \'SHIFT\' to look, \'CTRL\' for use and \'ALT\' for attack when clicking on an object or player.',
  117. [2] = 'If you already know where you want to go, click on the automap and your character will walk there automatically if the location is reachable and not too far away.',
  118. [3] = 'To open or close skills, battle or VIP list, click on the corresponding button to the right.',
  119. [4] = '\'Capacity\' restricts the amount of things you can carry with you. It raises with each level.',
  120. [5] = 'Always have a look on your health bar. If you see that you do not regenerate health points anymore, eat something.',
  121. [6] = 'Always eat as much food as possible. This way, you\'ll regenerate health points for a longer period of time.',
  122. [7] = 'After you have killed a monster, you have 10 seconds in which the corpse is not moveable and no one else but you can loot it.',
  123. [8] = 'Be careful when you approach three or more monsters because you only can block the attacks of two. In such a situation even a few rats can do severe damage or even kill you.',
  124. [9] = 'There are many ways to gather food. Many creatures drop food but you can also pick blueberries or bake your own bread. If you have a fishing rod and worms in your inventory, you can also try to catch a fish.',
  125. [10] = {'Baking bread is rather complex. First of all you need a scythe to harvest wheat. Then you use the wheat with a millstone to get flour. ...', 'This can be be used on water to get dough, which can be used on an oven to bake bread. Use milk instead of water to get cake dough.'},
  126. [11] = 'Dying hurts! Better run away than risk your life. You are going to lose experience and skill points when you die.',
  127. [12] = 'When you switch to \'Offensive Fighting\', you deal out more damage but you also get hurt more easily.',
  128. [13] = 'When you are on low health and need to run away from a monster, switch to \'Defensive Fighting\' and the monster will hit you less severely.',
  129. [14] = 'Many creatures try to run away from you. Select \'Chase Opponent\' to follow them.',
  130. [15] = 'The deeper you enter a dungeon, the more dangerous it will be. Approach every dungeon with utmost care or an unexpected creature might kill you. This will result in losing experience and skill points.',
  131. [16] = 'Due to the perspective, some objects in Tibia are not located at the spot they seem to appear (ladders, windows, lamps). Try clicking on the floor tile the object would lie on.',
  132. [17] = 'If you want to trade an item with another player, right-click on the item and select \'Trade with ...\', then click on the player with whom you want to trade.',
  133. [18] = 'Stairs, ladders and dungeon entrances are marked as yellow dots on the automap.',
  134. [19] = 'You can get food by killing animals or monsters. You can also pick blueberries or bake your own bread. If you are too lazy or own too much money, you can also buy food.',
  135. [20] = 'Quest containers can be recognised easily. They don\'t open up regularly but display a message \'You have found ....\'. They can only be opened once.',
  136. [21] = 'Better run away than risk to die. You\'ll lose experience and skill points each time you die.',
  137. [22] = 'You can form a party by right-clicking on a player and selecting \'Invite to Party\'. The party leader can also enable \'Shared Experience\' by right-clicking on him- or herself.',
  138. [23] = 'You can assign spells, the use of items, or random text to \'hotkeys\'. You find them under \'Options\'.',
  139. [24] = 'You can also follow other players. Just right-click on the player and select \'Follow\'.',
  140. [25] = 'You can found a party with your friends by right-clicking on a player and selecting \'Invite to Party\'. If you are invited to a party, right-click on yourself and select \'Join Party\'.',
  141. [26] = 'Only found parties with people you trust. You can attack people in your party without getting a skull. This is helpful for training your skills, but can be abused to kill people without having to fear negative consequences.',
  142. [27] = 'The leader of a party has the option to distribute gathered experience among all players in the party. If you are the leader, right-click on yourself and select \'Enable Shared Experience\'.',
  143. [28] = 'There is nothing more I can tell you. If you are still in need of some {hints}, I can repeat them for you.'
  144. }
  145.  
  146. function StdModule.rookgaardHints(cid, message, keywords, parameters, node)
  147. local npcHandler = parameters.npcHandler
  148. if npcHandler == nil then
  149. error("StdModule.say called without any npcHandler instance.")
  150. end
  151.  
  152. if not npcHandler:isFocused(cid) then
  153. return false
  154. end
  155.  
  156. local player = Player(cid)
  157. local hintId = player:getStorageValue(Storage.RookgaardHints)
  158. npcHandler:say(hints[hintId], cid)
  159. if hintId >= #hints then
  160. player:setStorageValue(Storage.RookgaardHints, -1)
  161. else
  162. player:setStorageValue(Storage.RookgaardHints, hintId + 1)
  163. end
  164. return true
  165. end
  166.  
  167. -- VoiceModule
  168. VoiceModule = {
  169. voices = nil,
  170. voiceCount = 0,
  171. lastVoice = 0,
  172. timeout = nil,
  173. chance = nil,
  174. npcHandler = nil
  175. }
  176.  
  177. -- Creates a new instance of VoiceModule
  178. function VoiceModule:new(voices, timeout, chance)
  179. local obj = {}
  180. setmetatable(obj, self)
  181. self.__index = self
  182.  
  183. obj.voices = voices
  184. for i = 1, #obj.voices do
  185. local voice = obj.voices[i]
  186. if voice.yell then
  187. voice.yell = nil
  188. voice.talktype = TALKTYPE_YELL
  189. else
  190. voice.talktype = TALKTYPE_SAY
  191. end
  192. end
  193.  
  194. obj.voiceCount = #voices
  195. obj.timeout = timeout or 10
  196. obj.chance = chance or 25
  197. return obj
  198. end
  199.  
  200. function VoiceModule:init(handler)
  201. return true
  202. end
  203.  
  204. function VoiceModule:callbackOnThink()
  205. if self.lastVoice < os.time() then
  206. self.lastVoice = os.time() + self.timeout
  207. if math.random(100) < self.chance then
  208. local voice = self.voices[math.random(self.voiceCount)]
  209. Npc():say(voice.text, voice.talktype)
  210. end
  211. end
  212. return true
  213. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement