Oskar1121

Untitled

Oct 7th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.46 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. function onThink() npcHandler:onThink() end
  11.  
  12. local function getCount(s)
  13. local b, e = s:find('%d+')
  14. return b and e and math.min(4294967295, tonumber(s:sub(b, e))) or -1
  15. end
  16.  
  17. function greet(cid)
  18. Topic[cid], count[cid], transfer[cid] = nil, nil, nil
  19. return true
  20. end
  21.  
  22. function creatureSayCallback(cid, type, msg)
  23. if not npcHandler:isFocused(cid) then
  24. return false
  25. elseif msgcontains(msg, 'balance') then
  26. npcHandler:say('Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
  27. Topic[cid] = nil
  28. elseif msgcontains(msg, 'deposit') and msgcontains(msg, 'all') then
  29. if getPlayerMoney(cid) == 0 then
  30. npcHandler:say('You don\'t have any gold with you.', cid)
  31. Topic[cid] = nil
  32. else
  33. count[cid] = getPlayerMoney(cid)
  34. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  35. Topic[cid] = 2
  36. end
  37. elseif msgcontains(msg, 'deposit') then
  38. if getCount(msg) == 0 then
  39. npcHandler:say('You are joking, aren\'t you??', cid)
  40. Topic[cid] = nil
  41. elseif getCount(msg) ~= -1 then
  42. if getPlayerMoney(cid) >= getCount(msg) then
  43. count[cid] = getCount(msg)
  44. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  45. Topic[cid] = 2
  46. else
  47. npcHandler:say('You do not have enough gold.', cid)
  48. Topic[cid] = nil
  49. end
  50. elseif getPlayerMoney(cid) == 0 then
  51. npcHandler:say('You don\'t have any gold with you.', cid)
  52. Topic[cid] = nil
  53. else
  54. npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
  55. Topic[cid] = 1
  56. end
  57. elseif Topic[cid] == 1 then
  58. if getCount(msg) == -1 then
  59. npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
  60. Topic[cid] = 1
  61. elseif getPlayerMoney(cid) >= getCount(msg) then
  62. count[cid] = getCount(msg)
  63. npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  64. Topic[cid] = 2
  65. else
  66. npcHandler:say('You do not have enough gold.', cid)
  67. Topic[cid] = nil
  68. end
  69. elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
  70. if doPlayerRemoveMoney(cid, count[cid]) then
  71. doPlayerSetBalance(cid, getPlayerBalance(cid) + count[cid])
  72. 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)
  73. else
  74. npcHandler:say('I am inconsolable, but it seems you have lost your gold. I hope you get it back.', cid)
  75. end
  76. Topic[cid] = nil
  77. elseif msgcontains(msg, 'no') and Topic[cid] == 2 then
  78. npcHandler:say('As you wish. Is there something else I can do for you?', cid)
  79. Topic[cid] = nil
  80. elseif msgcontains(msg, 'withdraw') then
  81. if getCount(msg) == 0 then
  82. npcHandler:say('Sure, you want nothing you get nothing!', cid)
  83. Topic[cid] = nil
  84. elseif getCount(msg) ~= -1 then
  85. if getPlayerBalance(cid) >= getCount(msg) then
  86. count[cid] = getCount(msg)
  87. npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  88. Topic[cid] = 4
  89. else
  90. npcHandler:say('There is not enough gold on your account.', cid)
  91. Topic[cid] = nil
  92. end
  93. elseif getPlayerBalance(cid) == 0 then
  94. npcHandler:say('You don\'t have any money on your bank account.', cid)
  95. Topic[cid] = nil
  96. else
  97. npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
  98. Topic[cid] = 3
  99. end
  100. elseif Topic[cid] == 3 then
  101. if getCount(msg) == -1 then
  102. npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
  103. Topic[cid] = 3
  104. elseif getPlayerBalance(cid) >= getCount(msg) then
  105. count[cid] = getCount(msg)
  106. npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  107. Topic[cid] = 4
  108. else
  109. npcHandler:say('There is not enough gold on your account.', cid)
  110. Topic[cid] = nil
  111. end
  112. elseif msgcontains(msg, 'yes') and Topic[cid] == 4 then
  113. if getPlayerBalance(cid) >= count[cid] then
  114. doPlayerAddMoney(cid, count[cid])
  115. doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
  116. npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
  117. else
  118. npcHandler:say('There is not enough gold on your account.', cid)
  119. end
  120. Topic[cid] = nil
  121. elseif msgcontains(msg, 'no') and Topic[cid] == 4 then
  122. npcHandler:say('The customer is king! Come back anytime you want to if you wish to withdraw your money.', cid)
  123. Topic[cid] = nil
  124. elseif msgcontains(msg, 'change gold') then
  125. npcHandler:say('How many platinum coins would you like to get?', cid)
  126. Topic[cid] = 8
  127. elseif Topic[cid] == 8 then
  128. if getCount(msg) < 1 then
  129. npcHandler:say('Hmm, can I help you with something else?', cid)
  130. Topic[cid] = nil
  131. else
  132. count[cid] = math.min(500, getCount(msg))
  133. npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your gold coins into ' .. count[cid] .. ' platinum coins?', cid)
  134. Topic[cid] = 9
  135. end
  136. elseif Topic[cid] == 9 then
  137. if msgcontains(msg, 'yes') then
  138. if doPlayerRemoveItem(cid, 2148, count[cid] * 100) then
  139. npcHandler:say('Here you are.', cid)
  140. doPlayerAddItem(cid, 2152, count[cid])
  141. else
  142. npcHandler:say('Sorry, you do not have enough gold coins.', cid)
  143. end
  144. else
  145. npcHandler:say('Well, can I help you with something else?', cid)
  146. end
  147. Topic[cid] = nil
  148. elseif msgcontains(msg, 'change platinum') then
  149. npcHandler:say('Would you like to change your platinum coins into gold or crystal?', cid)
  150. Topic[cid] = 10
  151. elseif Topic[cid] == 10 then
  152. if msgcontains(msg, 'gold') then
  153. npcHandler:say('How many platinum coins would you like to change into gold?', cid)
  154. Topic[cid] = 11
  155. elseif msgcontains(msg, 'crystal') then
  156. npcHandler:say('How many crystal coins would you like to get?', cid)
  157. Topic[cid] = 13
  158. else
  159. npcHandler:say('Well, can I help you with something else?', cid)
  160. Topic[cid] = nil
  161. end
  162. elseif Topic[cid] == 11 then
  163. if getCount(msg) < 1 then
  164. npcHandler:say('Hmm, can I help you with something else?', cid)
  165. Topic[cid] = nil
  166. else
  167. count[cid] = math.min(500, getCount(msg))
  168. npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your platinum coins into ' .. count[cid] * 100 .. ' gold coins for you?', cid)
  169. Topic[cid] = 12
  170. end
  171. elseif Topic[cid] == 12 then
  172. if msgcontains(msg, 'yes') then
  173. if doPlayerRemoveItem(cid, 2152, count[cid]) then
  174. npcHandler:say('Here you are.', cid)
  175. doPlayerAddItem(cid, 2148, count[cid] * 100)
  176. else
  177. npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  178. end
  179. else
  180. npcHandler:say('Well, can I help you with something else?', cid)
  181. end
  182. Topic[cid] = nil
  183. elseif Topic[cid] == 13 then
  184. if getCount(msg) < 1 then
  185. npcHandler:say('Hmm, can I help you with something else?', cid)
  186. Topic[cid] = nil
  187. else
  188. count[cid] = math.min(500, getCount(msg))
  189. npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your platinum coins into ' .. count[cid] .. ' crystal coins for you?', cid)
  190. Topic[cid] = 14
  191. end
  192. elseif Topic[cid] == 14 then
  193. if msgcontains(msg, 'yes') then
  194. if doPlayerRemoveItem(cid, 2152, count[cid] * 100) then
  195. npcHandler:say('Here you are.', cid)
  196. doPlayerAddItem(cid, 2160, count[cid])
  197. else
  198. npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  199. end
  200. else
  201. npcHandler:say('Well, can I help you with something else?', cid)
  202. end
  203. Topic[cid] = nil
  204. elseif msgcontains(msg, 'change crystal') then
  205. npcHandler:say('How many crystal coins would you like to change into platinum?', cid)
  206. Topic[cid] = 15
  207. elseif Topic[cid] == 15 then
  208. if getCount(msg) == -1 or getCount(msg) == 0 then
  209. npcHandler:say('Hmm, can I help you with something else?', cid)
  210. Topic[cid] = nil
  211. else
  212. count[cid] = math.min(500, getCount(msg))
  213. npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your crystal coins into ' .. count[cid] * 100 .. ' platinum coins for you?', cid)
  214. Topic[cid] = 16
  215. end
  216. elseif Topic[cid] == 16 then
  217. if msgcontains(msg, 'yes') then
  218. if doPlayerRemoveItem(cid, 2160, count[cid]) then
  219. npcHandler:say('Here you are.', cid)
  220. doPlayerAddItem(cid, 2152, count[cid] * 100)
  221. else
  222. npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
  223. end
  224. else
  225. npcHandler:say('Well, can I help you with something else?', cid)
  226. end
  227. Topic[cid] = nil
  228. elseif msgcontains(msg, 'change') then
  229. 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)
  230. Topic[cid] = nil
  231. elseif msgcontains(msg, 'bank') then
  232. npcHandler:say('We can change money for you. You can also access your bank account.', cid)
  233. Topic[cid] = nil
  234. end
  235. return true
  236. end
  237.  
  238. npcHandler:setCallback(CALLBACK_GREET, greet)
  239. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  240. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment