Advertisement
Guest User

Untitled

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