Advertisement
Guest User

Untitled

a guest
Aug 11th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.79 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. local count = {}
  6. local transfer = {}
  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 voices = { {text = 'It\'s a wise idea to store your money in your bank account.'} }
  14. npcHandler:addModule(VoiceModule:new(voices))
  15.  
  16. local function greetCallback(cid)
  17. count[cid], transfer[cid] = nil, nil
  18. return true
  19. end
  20.  
  21. local function creatureSayCallback(cid, type, msg)
  22. if not npcHandler:isFocused(cid) then
  23. return false
  24. end
  25. local player = Player(cid)
  26. ---------------------------- help ------------------------
  27. if msgcontains(msg, 'bank account') then
  28. npcHandler:say({
  29. 'Every Tibian has one. The big advantage is that you can access your money in every branch of the Tibian Bank! ...',
  30. 'Would you like to know more about the {basic} functions of your bank account, the {advanced} functions, or are you already bored, perhaps?'
  31. }, cid)
  32. npcHandler.topic[cid] = 0
  33. return true
  34. ---------------------------- balance ---------------------
  35. elseif msgcontains(msg, 'balance') then
  36. npcHandler.topic[cid] = 0
  37. if player:getBankBalance() >= 100000000 then
  38. npcHandler:say('I think you must be one of the richest inhabitants in the world! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  39. return true
  40. elseif player:getBankBalance() >= 10000000 then
  41. npcHandler:say('You have made ten millions and it still grows! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  42. return true
  43. elseif player:getBankBalance() >= 1000000 then
  44. npcHandler:say('Wow, you have reached the magic number of a million gp!!! Your account balance is ' .. player:getBankBalance() .. ' gold!', cid)
  45. return true
  46. elseif player:getBankBalance() >= 100000 then
  47. npcHandler:say('You certainly have made a pretty penny. Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  48. return true
  49. else
  50. npcHandler:say('Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  51. return true
  52. end
  53. ---------------------------- deposit ---------------------
  54. elseif msgcontains(msg, 'deposit') then
  55. count[cid] = player:getMoney()
  56. if count[cid] < 1 then
  57. npcHandler:say('You do not have enough gold.', cid)
  58. npcHandler.topic[cid] = 0
  59. return false
  60. end
  61. if msgcontains(msg, 'all') then
  62. count[cid] = player:getMoney()
  63. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  64. npcHandler.topic[cid] = 2
  65. return true
  66. else
  67. if string.match(msg,'%d+') then
  68. count[cid] = getMoneyCount(msg)
  69. if count[cid] < 1 then
  70. npcHandler:say('You do not have enough gold.', cid)
  71. npcHandler.topic[cid] = 0
  72. return false
  73. end
  74. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  75. npcHandler.topic[cid] = 2
  76. return true
  77. else
  78. npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
  79. npcHandler.topic[cid] = 1
  80. return true
  81. end
  82. end
  83. if not isValidMoney(count[cid]) then
  84. npcHandler:say('Sorry, but you can\'t deposit that much.', cid)
  85. npcHandler.topic[cid] = 0
  86. return false
  87. end
  88. elseif npcHandler.topic[cid] == 1 then
  89. count[cid] = getMoneyCount(msg)
  90. if isValidMoney(count[cid]) then
  91. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  92. npcHandler.topic[cid] = 2
  93. return true
  94. else
  95. npcHandler:say('You do not have enough gold.', cid)
  96. npcHandler.topic[cid] = 0
  97. return true
  98. end
  99. elseif npcHandler.topic[cid] == 2 then
  100. if msgcontains(msg, 'yes') then
  101. if player:getMoney() >= tonumber(count[cid]) then
  102. player:depositMoney(count[cid])
  103. npcHandler:say('Alright, we have added the amount of ' .. count[cid] .. ' gold to your {balance}. You can {withdraw} your money anytime you want to.', cid)
  104. else
  105. npcHandler:say('You do not have enough gold.', cid)
  106. end
  107. elseif msgcontains(msg, 'no') then
  108. npcHandler:say('As you wish. Is there something else I can do for you?', cid)
  109. end
  110. npcHandler.topic[cid] = 0
  111. return true
  112. ---------------------------- withdraw --------------------
  113. elseif msgcontains(msg, 'withdraw') then
  114. if string.match(msg,'%d+') then
  115. count[cid] = getMoneyCount(msg)
  116. if isValidMoney(count[cid]) then
  117. npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  118. npcHandler.topic[cid] = 7
  119. else
  120. npcHandler:say('There is not enough gold on your account.', cid)
  121. npcHandler.topic[cid] = 0
  122. end
  123. return true
  124. else
  125. npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
  126. npcHandler.topic[cid] = 6
  127. return true
  128. end
  129. elseif npcHandler.topic[cid] == 6 then
  130. count[cid] = getMoneyCount(msg)
  131. if isValidMoney(count[cid]) then
  132. npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  133. npcHandler.topic[cid] = 7
  134. else
  135. npcHandler:say('There is not enough gold on your account.', cid)
  136. npcHandler.topic[cid] = 0
  137. end
  138. return true
  139. elseif npcHandler.topic[cid] == 7 then
  140. if msgcontains(msg, 'yes') then
  141. if player:getFreeCapacity() >= getMoneyWeight(count[cid]) then
  142. if not player:withdrawMoney(count[cid]) then
  143. npcHandler:say('There is not enough gold on your account.', cid)
  144. else
  145. npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
  146. end
  147. else
  148. npcHandler:say('Whoah, hold on, you have no room in your inventory to carry all those coins. I don\'t want you to drop it on the floor, maybe come back with a cart!', cid)
  149. end
  150. npcHandler.topic[cid] = 0
  151. elseif msgcontains(msg, 'no') then
  152. npcHandler:say('The customer is king! Come back anytime you want to if you wish to {withdraw} your money.', cid)
  153. npcHandler.topic[cid] = 0
  154. end
  155. return true
  156. ---------------------------- transfer --------------------
  157. elseif msgcontains(msg, 'transfer') then
  158. npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
  159. npcHandler.topic[cid] = 11
  160. elseif npcHandler.topic[cid] == 11 then
  161. count[cid] = getMoneyCount(msg)
  162. if player:getBankBalance() < count[cid] then
  163. npcHandler:say('There is not enough gold on your account.', cid)
  164. npcHandler.topic[cid] = 0
  165. return true
  166. end
  167. if isValidMoney(count[cid]) then
  168. npcHandler:say('Who would you like transfer ' .. count[cid] .. ' gold to?', cid)
  169. npcHandler.topic[cid] = 12
  170. else
  171. npcHandler:say('There is not enough gold on your account.', cid)
  172. npcHandler.topic[cid] = 0
  173. end
  174. elseif npcHandler.topic[cid] == 12 then
  175. transfer[cid] = msg
  176. if player:getName() == transfer[cid] then
  177. npcHandler:say('Fill in this field with person who receives your gold!', cid)
  178. npcHandler.topic[cid] = 0
  179. return true
  180. end
  181. if playerExists(transfer[cid]) then
  182. npcHandler:say('So you would like to transfer ' .. count[cid] .. ' gold to ' .. transfer[cid] .. '?', cid)
  183. npcHandler.topic[cid] = 13
  184. else
  185. npcHandler:say('This player does not exist.', cid)
  186. npcHandler.topic[cid] = 0
  187. end
  188. elseif npcHandler.topic[cid] == 13 then
  189. if msgcontains(msg, 'yes') then
  190. if not player:transferMoneyTo(transfer[cid], count[cid]) then
  191. npcHandler:say('You cannot transfer money to this account.', cid)
  192. else
  193. npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. transfer[cid] ..'.', cid)
  194. transfer[cid] = nil
  195. end
  196. elseif msgcontains(msg, 'no') then
  197. npcHandler:say('Alright, is there something else I can do for you?', cid)
  198. end
  199. npcHandler.topic[cid] = 0
  200. ---------------------------- money exchange --------------
  201. elseif msgcontains(msg, 'change gold') then
  202. npcHandler:say('How many platinum coins would you like to get?', cid)
  203. npcHandler.topic[cid] = 14
  204. elseif npcHandler.topic[cid] == 14 then
  205. if getMoneyCount(msg) < 1 then
  206. npcHandler:say('Sorry, you do not have enough gold coins.', cid)
  207. npcHandler.topic[cid] = 0
  208. else
  209. count[cid] = getMoneyCount(msg)
  210. npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your gold coins into ' .. count[cid] .. ' platinum coins?', cid)
  211. npcHandler.topic[cid] = 15
  212. end
  213. elseif npcHandler.topic[cid] == 15 then
  214. if msgcontains(msg, 'yes') then
  215. if player:removeItem(2148, count[cid] * 100) then
  216. player:addItem(2152, count[cid])
  217. npcHandler:say('Here you are.', cid)
  218. else
  219. npcHandler:say('Sorry, you do not have enough gold coins.', cid)
  220. end
  221. else
  222. npcHandler:say('Well, can I help you with something else?', cid)
  223. end
  224. npcHandler.topic[cid] = 0
  225. elseif msgcontains(msg, 'change platinum') then
  226. npcHandler:say('Would you like to change your platinum coins into gold or crystal?', cid)
  227. npcHandler.topic[cid] = 16
  228. elseif npcHandler.topic[cid] == 16 then
  229. if msgcontains(msg, 'gold') then
  230. npcHandler:say('How many platinum coins would you like to change into gold?', cid)
  231. npcHandler.topic[cid] = 17
  232. elseif msgcontains(msg, 'crystal') then
  233. npcHandler:say('How many crystal coins would you like to get?', cid)
  234. npcHandler.topic[cid] = 19
  235. else
  236. npcHandler:say('Well, can I help you with something else?', cid)
  237. npcHandler.topic[cid] = 0
  238. end
  239. elseif npcHandler.topic[cid] == 17 then
  240. if getMoneyCount(msg) < 1 then
  241. npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  242. npcHandler.topic[cid] = 0
  243. else
  244. count[cid] = getMoneyCount(msg)
  245. npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your platinum coins into ' .. count[cid] * 100 .. ' gold coins for you?', cid)
  246. npcHandler.topic[cid] = 18
  247. end
  248. elseif npcHandler.topic[cid] == 18 then
  249. if msgcontains(msg, 'yes') then
  250. if player:removeItem(2152, count[cid]) then
  251. player:addItem(2148, count[cid] * 100)
  252. npcHandler:say('Here you are.', cid)
  253. else
  254. npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  255. end
  256. else
  257. npcHandler:say('Well, can I help you with something else?', cid)
  258. end
  259. npcHandler.topic[cid] = 0
  260. elseif npcHandler.topic[cid] == 19 then
  261. if getMoneyCount(msg) < 1 then
  262. npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  263. npcHandler.topic[cid] = 0
  264. else
  265. count[cid] = getMoneyCount(msg)
  266. npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your platinum coins into ' .. count[cid] .. ' crystal coins for you?', cid)
  267. npcHandler.topic[cid] = 20
  268. end
  269. elseif npcHandler.topic[cid] == 20 then
  270. if msgcontains(msg, 'yes') then
  271. if player:removeItem(2152, count[cid] * 100) then
  272. player:addItem(2160, count[cid])
  273. npcHandler:say('Here you are.', cid)
  274. else
  275. npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  276. end
  277. else
  278. npcHandler:say('Well, can I help you with something else?', cid)
  279. end
  280. npcHandler.topic[cid] = 0
  281. elseif msgcontains(msg, 'change crystal') then
  282. npcHandler:say('How many crystal coins would you like to change into platinum?', cid)
  283. npcHandler.topic[cid] = 21
  284. elseif npcHandler.topic[cid] == 21 then
  285. if getMoneyCount(msg) < 1 then
  286. npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
  287. npcHandler.topic[cid] = 0
  288. else
  289. count[cid] = getMoneyCount(msg)
  290. npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your crystal coins into ' .. count[cid] * 100 .. ' platinum coins for you?', cid)
  291. npcHandler.topic[cid] = 22
  292. end
  293. elseif npcHandler.topic[cid] == 22 then
  294. if msgcontains(msg, 'yes') then
  295. if player:removeItem(2160, count[cid]) then
  296. player:addItem(2152, count[cid] * 100)
  297. npcHandler:say('Here you are.', cid)
  298. else
  299. npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
  300. end
  301. else
  302. npcHandler:say('Well, can I help you with something else?', cid)
  303. end
  304. npcHandler.topic[cid] = 0
  305. end
  306. return true
  307. end
  308.  
  309. keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
  310. keywordHandler:addKeyword({'change'}, StdModule.say, {npcHandler = npcHandler, text = 'There are three different coin types in Tibia: 100 gold coins equal 1 platinum coin, 100 platinum coins equal 1 crystal coin. So if you\'d like to change 100 gold into 1 platinum, simply say \'{change gold}\' and then \'1 platinum\'.'})
  311. keywordHandler:addKeyword({'bank'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
  312. keywordHandler:addKeyword({'advanced'}, StdModule.say, {npcHandler = npcHandler, text = 'Your bank account will be used automatically when you want to {rent} a house or place an offer on an item on the {market}. Let me know if you want to know about how either one works.'})
  313. keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, text = 'You can check the {balance} of your bank account, {deposit} money or {withdraw} it. You can also {transfer} money to other characters, provided that they have a vocation.'})
  314. keywordHandler:addKeyword({'functions'}, StdModule.say, {npcHandler = npcHandler, text = 'You can check the {balance} of your bank account, {deposit} money or {withdraw} it. You can also {transfer} money to other characters, provided that they have a vocation.'})
  315. keywordHandler:addKeyword({'basic'}, StdModule.say, {npcHandler = npcHandler, text = 'You can check the {balance} of your bank account, {deposit} money or {withdraw} it. You can also {transfer} money to other characters, provided that they have a vocation.'})
  316. keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'I work in this bank. I can change money for you and help you with your bank account.'})
  317. keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, text = "My name is Naji. My mother gave me that name because she knew a Paladin with that name. I'm a spare timer hunter by myself, you know! I want to join the {Paw and Fur - hunting elite}!"})
  318. keywordHandler:addKeyword({'paw and fur'}, StdModule.say, {npcHandler = npcHandler, text = "The Paw and Fur - Hunting Elite is a newly founded hunting society in Port Hope. It is said that they send you on hunting mission. Sounds great if you ask me."})
  319.  
  320. npcHandler:setMessage(MESSAGE_GREET, 'Welcome to the Tibian {bank}, |PLAYERNAME|! What can I do for you?')
  321. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  322. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  323. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement