Advertisement
Guest User

Untitled

a guest
Dec 14th, 2013
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.08 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. local talkState = {}
  5. local transaction = {}
  6. local transfer = {}
  7. local transfer_name = {}
  8.  
  9. function onCreatureAppear(cid)
  10. npcHandler:onCreatureAppear(cid)
  11. end
  12. function onCreatureDisappear(cid)
  13. npcHandler:onCreatureDisappear(cid)
  14. end
  15. function onCreatureSay(cid, type, msg)
  16. npcHandler:onCreatureSay(cid, type, msg)
  17. end
  18. function onThink()
  19. npcHandler:onThink()
  20. end
  21.  
  22. function creatureSayCallback(cid, type, msg)
  23. if(not npcHandler:isFocused(cid)) then
  24. return false
  25. end
  26. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  27.  
  28. local function getMoneyCount(s)
  29. local b, e = s:find("%d+")
  30. return b and e and tonumber(s:sub(b, e)) or -1
  31. end
  32.  
  33. local function doPlayerAddSafeMoney(cid, money)
  34. moneyAdd = money
  35. freeCap = getPlayerFreeCap(cid)
  36. crystalCoins = money >= 10000 and money / 10000 or 0
  37. money = money - crystalCoins * 10000
  38. platinumCoins = money >= 100 and money / 100 or 0
  39. money = money - platinumCoins * 100
  40. goldCoins = money
  41. if(freeCap >= (crystalCoins * 0.1 + platinumCoins * 0.1 + goldCoins * 0.1) and doPlayerAddMoney(cid, moneyAdd)) then
  42. return true
  43. else
  44. return false
  45. end
  46. end
  47.  
  48. -- Check Balance
  49. if(msgcontains(msg, "balance")) then
  50. balance = getPlayerBalance(cid)
  51. if(balance > 100000 and balance < 1000000) then
  52. msg = "You certainly have made a pretty penny. "
  53. elseif(balance > 1000000 and balance < 10000000) then
  54. msg = "Wow, you have reached the magic number of a million gp!!! "
  55. elseif(balance > 10000000) then
  56. msg = "I think you must be one of the richest inhabitants of Tibia! "
  57. elseif (balance < 100000) then
  58. msg = ""
  59. end
  60. npcHandler:say(msg .. "Your account balance is " .. balance .. " gold.", cid)
  61.  
  62. -- Deposit All
  63. elseif(msg == "deposit all") then
  64. if(getPlayerMoney(cid) > 0) then
  65. npcHandler:say("Do you really want to deposit " .. getPlayerMoney(cid) .. " to your bank account?", cid)
  66. transaction[talkUser] = getPlayerMoney(cid)
  67. talkState[talkUser] = 1
  68. else
  69. npcHandler:say("You don't have any money with you.", cid)
  70. transaction[talkUser] = 0
  71. talkState[talkUser] = 0
  72. end
  73.  
  74. -- Withdraw Money
  75. elseif(msgcontains(msg, "withdraw")) then
  76. npcHandler:say("How much money would you like to withdraw from your bank account?", cid)
  77. talkState[talkUser] = 2
  78. elseif(talkState[talkUser] == 2) then
  79. if tonumber(msg) == nil then
  80. npcHandler:say("Please tell me a {number} you want to withdraw.", cid)
  81. talkState[talkUser] = 2
  82. return true
  83. end
  84. if(tonumber(msg) > 0 and getMoneyCount(msg) <= getPlayerBalance(cid)) then
  85. npcHandler:say("Would you like to withdraw " .. getMoneyCount(msg) .. " gold from your bank account?", cid)
  86. transaction[talkUser] = getMoneyCount(msg)
  87. talkState[talkUser] = 3
  88. elseif (tonumber(msg) < 1) then
  89. npcHandler:say("Sure, you want nothing you get nothing!", cid)
  90. talkState[talkUser] = 0
  91. elseif(getMoneyCount(msg) < 1) then
  92. npcHandler:say("How much money would you like to withdraw from your bank account?", cid)
  93. elseif(getMoneyCount(msg) > getPlayerBalance(cid)) then
  94. npcHandler:say("You don't have enought money on your bank account.", cid)
  95. talkState[talkUser] = 0
  96. end
  97.  
  98. -- Deposit Money
  99. elseif(msgcontains(msg, "deposit")) then
  100. npcHandler:say("How much money would you like to deposit to your bank account?", cid)
  101. talkState[talkUser] = 4
  102. elseif(talkState[talkUser] == 4) then
  103. if tonumber(msg) == nil then
  104. npcHandler:say("Please tell me a {number} you want to deposit.", cid)
  105. talkState[talkUser] = 4
  106. return true
  107. end
  108. if(tonumber(msg) > 0 and getMoneyCount(msg) <= getPlayerMoney(cid)) then
  109. npcHandler:say("Would you like to deposit " .. getMoneyCount(msg) .. " gold to your bank account?", cid)
  110. transaction[talkUser] = getMoneyCount(msg)
  111. talkState[talkUser] = 5
  112. elseif(tonumber(msg) < 1) then
  113. npcHandler:say("You are joking, aren't you??", cid)
  114. talkState[talkUser] = 0
  115. elseif(getMoneyCount(msg) < 1) then
  116. npcHandler:say("How much money would you like to deposit to your bank account?", cid)
  117. elseif(getMoneyCount(msg) > getPlayerMoney(cid)) then
  118. npcHandler:say("You don't have enought money with you.", cid)
  119. talkState[talkUser] = 0
  120. end
  121.  
  122. -- Transfer Money
  123. elseif(msgcontains(msg, "transfer")) then
  124. npcHandler:say("Who do you want transfer money to?", cid)
  125. talkState[talkUser] = 6
  126. elseif(talkState[talkUser] == 6) then
  127. if(getPlayerGUIDByName(string.lower(msg)) > 0 and string.lower(msg) ~= string.lower(getCreatureName(cid))) then
  128. transfer[talkUser] = getPlayerGUIDByName(string.lower(msg))
  129. transfer_name[talkUser] = string.lower(msg)
  130. npcHandler:say("How much money would you like to transfer?", cid)
  131. talkState[talkUser] = 7
  132. else
  133. npcHandler:say("There is no such player.", cid)
  134. talkState[talkUser] = 0
  135. end
  136. elseif(talkState[talkUser] == 7) then
  137. if tonumber(msg) == nil then
  138. npcHandler:say("Please tell me a {number} you want to transfer.", cid)
  139. talkState[talkUser] = 7
  140. return true
  141. end
  142. if(tonumber(msg) > 0 and getMoneyCount(msg) <= getPlayerBalance(cid)) then
  143. npcHandler:say("Would you like to transfer " .. getMoneyCount(msg) .. " to " .. transfer_name[talkUser] .. "?", cid)
  144. transaction[talkUser] = getMoneyCount(msg)
  145. talkState[talkUser] = 8
  146. elseif(tonumber(msg) < 1) then
  147. npcHandler:say("Please think about it. Okay?", cid)
  148. talkState[talkUser] = 0
  149. elseif(getMoneyCount(msg) < 0) then
  150. npcHandler:say("How much money would you like to transfer?", cid)
  151. elseif(getMoneyCount(msg) > getPlayerMoney(cid)) then
  152. npcHandler:say("You don't have enought money on your bank account.", cid)
  153. talkState[talkUser] = 0
  154. end
  155.  
  156. -- Yes
  157. elseif(msgcontains(msg, "yes")) then
  158. if(talkState[talkUser] == 1) then
  159. if(getPlayerMoney(cid) == transaction[talkUser]) then
  160. doPlayerRemoveMoney(cid, transaction[talkUser])
  161. doPlayerSetBalance(cid, getPlayerBalance(cid)+ transaction[talkUser])
  162. npcHandler:say("You deposited " .. transaction[talkUser] .. " gold coins to your bank account.", cid)
  163. transaction[talkUser] = 0
  164. talkState[talkUser] = 0
  165. else
  166. npcHandler:say("You don't have enought money.", cid)
  167. transaction[talkUser] = 0
  168. talkState[talkUser] = 1
  169. end
  170. elseif(talkState[talkUser] == 3) then
  171. if(doPlayerAddSafeMoney(cid, transaction[talkUser])) then
  172. doPlayerSetBalance(cid, getPlayerBalance(cid)- transaction[talkUser])
  173. npcHandler:say("You withdrawed " .. transaction[talkUser] .. " gold coins from your bank account.", cid)
  174. else
  175. npcHandler:say("You don't have anought capacity or slots in backpack to withdraw " .. transaction[talkUser] .. " gold.", cid)
  176. end
  177. transaction[talkUser] = 0
  178. talkState[talkUser] = 0
  179. elseif(talkState[talkUser] == 5) then
  180. if(transaction[talkUser] <= getPlayerMoney(cid)) then
  181. doPlayerRemoveMoney(cid, transaction[talkUser])
  182. doPlayerSetBalance(cid, getPlayerBalance(cid)+ transaction[talkUser])
  183. npcHandler:say("You deposited " .. transaction[talkUser] .. " gold coins to your bank account.", cid)
  184. transaction[talkUser] = 0
  185. talkState[talkUser] = 0
  186. else
  187. npcHandler:say("You don't have enought money.", cid)
  188. transaction[talkUser] = 0
  189. talkState[talkUser] = 1
  190. end
  191. elseif(talkState[talkUser] == 8) then
  192. if(transaction[talkUser] <= getPlayerMoney(cid)) then
  193. doPlayerRemoveMoney(cid, transaction[talkUser])
  194. doPlayerSetBalance(cid, getPlayerBalance(cid)- transaction[talkUser])
  195. npcHandler:say("You transfered " .. transaction[talkUser] .. " gold coins to " .. transfer_name[talkUser] .. "'s bank account.", cid)
  196. if(getPlayerByName(""..transfer_name[talkUser].."")) then
  197. doPlayerSetBalance(getPlayerByName(""..transfer_name[talkUser]..""), getPlayerBalance(getPlayerByName(""..transfer_name[talkUser].."")) + transaction[talkUser])
  198. else
  199. transferGold(""..transfer_name[talkUser].."", transaction[talkUser])
  200. end
  201. transaction[talkUser] = 0
  202. transfer[talkUser] = 0
  203. transfer_name[talkUser] = ""
  204. talkState[talkUser] = 0
  205. else
  206. npcHandler:say("You don't have enought money.", cid)
  207. transaction[talkUser] = 0
  208. talkState[talkUser] = 1
  209. end
  210. end
  211. elseif(msgcontains(msg, "no")) then
  212. npcHandler:say("The customer is king! Come back anytime you want to if you wish to withdraw your money.", cid)
  213. talkState[talkUser] = 0
  214. end
  215. return true
  216. end
  217.  
  218. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  219. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement