Advertisement
Guest User

Untitled

a guest
Feb 27th, 2016
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.91 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. local Topic, count, transfer = {}, {}, {}
  6.  
  7. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  8. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  9. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  10.  
  11. local lastSound = 0
  12. function onThink()
  13. if lastSound < os.time() then
  14. lastSound = (os.time() + 5)
  15. if math.random(100) < 25 then
  16. Npc():say("Better deposit your money in the bank where it's safe.", TALKTYPE_SAY)
  17. end
  18. end
  19. npcHandler:onThink()
  20. end
  21.  
  22. local function getCount(s)
  23. local b, e = s:find('%d+')
  24. return b and e and math.min(4294967295, tonumber(s:sub(b, e))) or -1
  25. end
  26.  
  27. local function findPlayer(name)
  28. local q = db.getResult('SELECT name FROM players WHERE name=' .. db.escapeString(name) .. ' LIMIT 1'), nil
  29. if q:getID() == -1 then
  30. return
  31. end
  32. local r = q:getDataString('name')
  33. q:free()
  34. return r
  35. end
  36.  
  37. function greet(cid)
  38. Topic[cid], count[cid], transfer[cid] = nil, nil, nil
  39. return true
  40. end
  41.  
  42. function creatureSayCallback(cid, type, msg)
  43. if not npcHandler:isFocused(cid) then
  44. return false
  45. elseif msgcontains(msg, 'balance') then
  46. npcHandler:say('Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
  47. Topic[cid] = nil
  48. elseif msgcontains(msg, 'deposit') and msgcontains(msg, 'all') then
  49. if getPlayerMoney(cid) == 0 then
  50. npcHandler:say('You don\'t have any gold with you.', cid)
  51. Topic[cid] = nil
  52. else
  53. count[cid] = getPlayerMoney(cid)
  54. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  55. Topic[cid] = 2
  56. end
  57. elseif msgcontains(msg, 'deposit') then
  58. if getCount(msg) == 0 then
  59. npcHandler:say('You are joking, aren\'t you??', cid)
  60. Topic[cid] = nil
  61. elseif getCount(msg) ~= -1 then
  62. if getPlayerMoney(cid) >= getCount(msg) then
  63. count[cid] = getCount(msg)
  64. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  65. Topic[cid] = 2
  66. else
  67. npcHandler:say('You do not have enough gold.', cid)
  68. Topic[cid] = nil
  69. end
  70. elseif getPlayerMoney(cid) == 0 then
  71. npcHandler:say('You don\'t have any gold with you.', cid)
  72. Topic[cid] = nil
  73. else
  74. npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
  75. Topic[cid] = 1
  76. end
  77. elseif Topic[cid] == 1 then
  78. if getCount(msg) == -1 then
  79. npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
  80. Topic[cid] = 1
  81. elseif getPlayerMoney(cid) >= getCount(msg) then
  82. count[cid] = getCount(msg)
  83. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  84. Topic[cid] = 2
  85. else
  86. npcHandler:say('You do not have enough gold.', cid)
  87. Topic[cid] = nil
  88. end
  89. elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
  90. if doPlayerRemoveMoney(cid, count[cid]) then
  91. doPlayerSetBalance(cid, getPlayerBalance(cid) + count[cid])
  92. 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)
  93. else
  94. npcHandler:say('I am inconsolable, but it seems you have lost your gold. I hope you get it back.', cid)
  95. end
  96. Topic[cid] = nil
  97. elseif msgcontains(msg, 'no') and Topic[cid] == 2 then
  98. npcHandler:say('As you wish. Is there something else I can do for you?', cid)
  99. Topic[cid] = nil
  100. elseif msgcontains(msg, 'withdraw') then
  101. if getCount(msg) == 0 then
  102. npcHandler:say('Sure, you want nothing you get nothing!', cid)
  103. Topic[cid] = nil
  104. elseif getCount(msg) ~= -1 then
  105. if getPlayerBalance(cid) >= getCount(msg) then
  106. count[cid] = getCount(msg)
  107. npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  108. Topic[cid] = 4
  109. else
  110. npcHandler:say('There is not enough gold on your account.', cid)
  111. Topic[cid] = nil
  112. end
  113. elseif getPlayerBalance(cid) == 0 then
  114. npcHandler:say('You don\'t have any money on your bank account.', cid)
  115. Topic[cid] = nil
  116. else
  117. npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
  118. Topic[cid] = 3
  119. end
  120. elseif Topic[cid] == 3 then
  121. if getCount(msg) == -1 then
  122. npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
  123. Topic[cid] = 3
  124. elseif getPlayerBalance(cid) >= getCount(msg) then
  125. count[cid] = getCount(msg)
  126. npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  127. Topic[cid] = 4
  128. else
  129. npcHandler:say('There is not enough gold on your account.', cid)
  130. Topic[cid] = nil
  131. end
  132. elseif msgcontains(msg, 'yes') and Topic[cid] == 4 then
  133. if getPlayerBalance(cid) >= count[cid] then
  134. doPlayerAddMoney(cid, count[cid])
  135. doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
  136. npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
  137. else
  138. npcHandler:say('There is not enough gold on your account.', cid)
  139. end
  140. Topic[cid] = nil
  141. elseif msgcontains(msg, 'no') and Topic[cid] == 4 then
  142. npcHandler:say('The customer is king! Come back anytime you want to if you wish to withdraw your money.', cid)
  143. Topic[cid] = nil
  144. elseif msgcontains(msg, 'transfer') then
  145. if getCount(msg) == 0 then
  146. npcHandler:say('Please think about it. Okay?', cid)
  147. Topic[cid] = nil
  148. elseif getCount(msg) ~= -1 then
  149. count[cid] = getCount(msg)
  150. if getPlayerBalance(cid) >= count[cid] then
  151. npcHandler:say('Who would you like to transfer ' .. count[cid] .. ' gold to?', cid)
  152. Topic[cid] = 6
  153. else
  154. npcHandler:say('There is not enough gold on your account.', cid)
  155. Topic[cid] = nil
  156. end
  157. else
  158. npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
  159. Topic[cid] = 5
  160. end
  161. elseif Topic[cid] == 5 then
  162. if getCount(msg) == -1 then
  163. npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
  164. Topic[cid] = 5
  165. else
  166. count[cid] = getCount(msg)
  167. if getPlayerBalance(cid) >= count[cid] then
  168. npcHandler:say('Who would you like to transfer ' .. count[cid] .. ' gold to?', cid)
  169. Topic[cid] = 6
  170. else
  171. npcHandler:say('There is not enough gold on your account.', cid)
  172. Topic[cid] = nil
  173. end
  174. end
  175. elseif Topic[cid] == 6 then
  176. local v = getPlayerByName(msg)
  177. if getPlayerBalance(cid) >= count[cid] then
  178. if v then
  179. transfer[cid] = msg
  180. npcHandler:say('Would you really like to transfer ' .. count[cid] .. ' gold to ' .. getPlayerName(v) .. '?', cid)
  181. Topic[cid] = 7
  182. elseif findPlayer(msg):lower() == msg:lower() then
  183. transfer[cid] = msg
  184. npcHandler:say('Would you really like to transfer ' .. count[cid] .. ' gold to ' .. findPlayer(msg) .. '?', cid)
  185. Topic[cid] = 7
  186. else
  187. npcHandler:say('This player does not exist.', cid)
  188. Topic[cid] = nil
  189. end
  190. else
  191. npcHandler:say('There is not enough gold on your account.', cid)
  192. Topic[cid] = nil
  193. end
  194. elseif Topic[cid] == 7 and msgcontains(msg, 'yes') then
  195. if getPlayerBalance(cid) >= count[cid] then
  196. local v = getPlayerByName(transfer[cid])
  197. if v then
  198. doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
  199. doPlayerSetBalance(v, getPlayerBalance(v) + count[cid])
  200. npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. getPlayerName(v) .. '.', cid)
  201. elseif findPlayer(transfer[cid]):lower() == transfer[cid]:lower() then
  202. doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
  203. db.executeQuery('UPDATE players SET balance=balance+' .. count[cid] .. ' WHERE name=' .. db.escapeString(transfer[cid]) .. ' LIMIT 1')
  204. npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. findPlayer(transfer[cid]) .. '.', cid)
  205. else
  206. npcHandler:say('This player does not exist.', cid)
  207. end
  208. else
  209. npcHandler:say('There is not enough gold on your account.', cid)
  210. end
  211. Topic[cid] = nil
  212. elseif Topic[cid] == 7 and msgcontains(msg, 'no') then
  213. npcHandler:say('Alright, is there something else I can do for you?', cid)
  214. Topic[cid] = nil
  215. elseif msgcontains(msg, 'change gold') then
  216. npcHandler:say('How many platinum coins would you like to get?', cid)
  217. Topic[cid] = 8
  218. elseif Topic[cid] == 8 then
  219. if getCount(msg) < 1 then
  220. npcHandler:say('Hmm, can I help you with something else?', cid)
  221. Topic[cid] = nil
  222. else
  223. count[cid] = math.min(500, getCount(msg))
  224. npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your gold coins into ' .. count[cid] .. ' platinum coins?', cid)
  225. Topic[cid] = 9
  226. end
  227. elseif Topic[cid] == 9 then
  228. if msgcontains(msg, 'yes') then
  229. if doPlayerRemoveItem(cid, 2148, count[cid] * 100) then
  230. npcHandler:say('Here you are.', cid)
  231. doPlayerAddItem(cid, 2152, count[cid])
  232. else
  233. npcHandler:say('Sorry, you do not have enough gold coins.', cid)
  234. end
  235. else
  236. npcHandler:say('Well, can I help you with something else?', cid)
  237. end
  238. Topic[cid] = nil
  239. elseif msgcontains(msg, 'change platinum') then
  240. npcHandler:say('Would you like to change your platinum coins into gold or crystal?', cid)
  241. Topic[cid] = 10
  242. elseif Topic[cid] == 10 then
  243. if msgcontains(msg, 'gold') then
  244. npcHandler:say('How many platinum coins would you like to change into gold?', cid)
  245. Topic[cid] = 11
  246. elseif msgcontains(msg, 'crystal') then
  247. npcHandler:say('How many crystal coins would you like to get?', cid)
  248. Topic[cid] = 13
  249. else
  250. npcHandler:say('Well, can I help you with something else?', cid)
  251. Topic[cid] = nil
  252. end
  253. elseif Topic[cid] == 11 then
  254. if getCount(msg) < 1 then
  255. npcHandler:say('Hmm, can I help you with something else?', cid)
  256. Topic[cid] = nil
  257. else
  258. count[cid] = math.min(500, getCount(msg))
  259. npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your platinum coins into ' .. count[cid] * 100 .. ' gold coins for you?', cid)
  260. Topic[cid] = 12
  261. end
  262. elseif Topic[cid] == 12 then
  263. if msgcontains(msg, 'yes') then
  264. if doPlayerRemoveItem(cid, 2152, count[cid]) then
  265. npcHandler:say('Here you are.', cid)
  266. doPlayerAddItem(cid, 2148, count[cid] * 100)
  267. else
  268. npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  269. end
  270. else
  271. npcHandler:say('Well, can I help you with something else?', cid)
  272. end
  273. Topic[cid] = nil
  274. elseif Topic[cid] == 13 then
  275. if getCount(msg) < 1 then
  276. npcHandler:say('Hmm, can I help you with something else?', cid)
  277. Topic[cid] = nil
  278. else
  279. count[cid] = math.min(500, getCount(msg))
  280. npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your platinum coins into ' .. count[cid] .. ' crystal coins for you?', cid)
  281. Topic[cid] = 14
  282. end
  283. elseif Topic[cid] == 14 then
  284. if msgcontains(msg, 'yes') then
  285. if doPlayerRemoveItem(cid, 2152, count[cid] * 100) then
  286. npcHandler:say('Here you are.', cid)
  287. doPlayerAddItem(cid, 2160, count[cid])
  288. else
  289. npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  290. end
  291. else
  292. npcHandler:say('Well, can I help you with something else?', cid)
  293. end
  294. Topic[cid] = nil
  295. elseif msgcontains(msg, 'change crystal') then
  296. npcHandler:say('How many crystal coins would you like to change into platinum?', cid)
  297. Topic[cid] = 15
  298. elseif Topic[cid] == 15 then
  299. if getCount(msg) == -1 or getCount(msg) == 0 then
  300. npcHandler:say('Hmm, can I help you with something else?', cid)
  301. Topic[cid] = nil
  302. else
  303. count[cid] = math.min(500, getCount(msg))
  304. npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your crystal coins into ' .. count[cid] * 100 .. ' platinum coins for you?', cid)
  305. Topic[cid] = 16
  306. end
  307. elseif Topic[cid] == 16 then
  308. if msgcontains(msg, 'yes') then
  309. if doPlayerRemoveItem(cid, 2160, count[cid]) then
  310. npcHandler:say('Here you are.', cid)
  311. doPlayerAddItem(cid, 2152, count[cid] * 100)
  312. else
  313. npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
  314. end
  315. else
  316. npcHandler:say('Well, can I help you with something else?', cid)
  317. end
  318. Topic[cid] = nil
  319. elseif msgcontains(msg, 'change') then
  320. npcHandler:say('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\'.', cid)
  321. Topic[cid] = nil
  322. elseif msgcontains(msg, 'bank') then
  323. npcHandler:say('We can change money for you. You can also access your bank account.', cid)
  324. Topic[cid] = nil
  325. end
  326. return true
  327. end
  328.  
  329. keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
  330. 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\'.'})
  331. keywordHandler:addKeyword({'bank'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
  332. 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.'})
  333. 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.'})
  334. 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.'})
  335. 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.'})
  336. 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.'})
  337.  
  338.  
  339. npcHandler:setCallback(CALLBACK_GREET, greet)
  340. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  341. npcHandler:setMessage(MESSAGE_GREET, "Welcome |PLAYERNAME|! What business do you have in the bank today? Please let me know if you need any {help}.")
  342. npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye, |PLAYERNAME|.")
  343. npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, |PLAYERNAME|.")
  344. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement