ralke23

bank.lua

May 2nd, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.46 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.          local arrayDenied = {"accountmanager", "rooksample", "druidsample", "sorcerersample", "knightsample", "paladinsample"}
  183.             if isInArray(arrayDenied, string.gsub(transfer[cid]:lower(), " ", "")) then
  184.                 npcHandler:say('This player does not exist.', cid)
  185.                 npcHandler.topic[cid] = 0
  186.                 return true
  187.             end
  188.             npcHandler:say('So you would like to transfer ' .. count[cid] .. ' gold to ' .. transfer[cid] .. '?', cid)
  189.             npcHandler.topic[cid] = 13
  190.         else
  191.             npcHandler:say('This player does not exist.', cid)
  192.             npcHandler.topic[cid] = 0
  193.         end
  194.     elseif npcHandler.topic[cid] == 13 then
  195.         if msgcontains(msg, 'yes') then
  196.             if not player:transferMoneyTo(transfer[cid], count[cid]) then
  197.                 npcHandler:say('You cannot transfer money to this account.', cid)
  198.             else
  199.                 npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. transfer[cid] ..'.', cid)
  200.                 transfer[cid] = nil
  201.             end
  202.         elseif msgcontains(msg, 'no') then
  203.             npcHandler:say('Alright, is there something else I can do for you?', cid)
  204.         end
  205.         npcHandler.topic[cid] = 0
  206. ---------------------------- money exchange --------------
  207.     elseif msgcontains(msg, 'change gold') then
  208.         npcHandler:say('How many platinum coins would you like to get?', cid)
  209.         npcHandler.topic[cid] = 14
  210.     elseif npcHandler.topic[cid] == 14 then
  211.         if getMoneyCount(msg) < 1 then
  212.             npcHandler:say('Sorry, you do not have enough gold coins.', cid)
  213.             npcHandler.topic[cid] = 0
  214.         else
  215.             count[cid] = getMoneyCount(msg)
  216.             npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your gold coins into ' .. count[cid] .. ' platinum coins?', cid)
  217.             npcHandler.topic[cid] = 15
  218.         end
  219.     elseif npcHandler.topic[cid] == 15 then
  220.         if msgcontains(msg, 'yes') then
  221.             if player:removeItem(2148, count[cid] * 100) then
  222.                 player:addItem(2152, count[cid])
  223.                 npcHandler:say('Here you are.', cid)
  224.             else
  225.                 npcHandler:say('Sorry, you do not have enough gold coins.', cid)
  226.             end
  227.         else
  228.             npcHandler:say('Well, can I help you with something else?', cid)
  229.         end
  230.         npcHandler.topic[cid] = 0
  231.     elseif msgcontains(msg, 'change platinum') then
  232.         npcHandler:say('Would you like to change your platinum coins into gold or crystal?', cid)
  233.         npcHandler.topic[cid] = 16
  234.     elseif npcHandler.topic[cid] == 16 then
  235.         if msgcontains(msg, 'gold') then
  236.             npcHandler:say('How many platinum coins would you like to change into gold?', cid)
  237.             npcHandler.topic[cid] = 17
  238.         elseif msgcontains(msg, 'crystal') then
  239.             npcHandler:say('How many crystal coins would you like to get?', cid)
  240.             npcHandler.topic[cid] = 19
  241.         else
  242.             npcHandler:say('Well, can I help you with something else?', cid)
  243.             npcHandler.topic[cid] = 0
  244.         end
  245.     elseif npcHandler.topic[cid] == 17 then
  246.         if getMoneyCount(msg) < 1 then
  247.             npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  248.             npcHandler.topic[cid] = 0
  249.         else
  250.             count[cid] = getMoneyCount(msg)
  251.             npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your platinum coins into ' .. count[cid] * 100 .. ' gold coins for you?', cid)
  252.             npcHandler.topic[cid] = 18
  253.         end
  254.     elseif npcHandler.topic[cid] == 18 then
  255.         if msgcontains(msg, 'yes') then
  256.             if player:removeItem(2152, count[cid]) then
  257.                 player:addItem(2148, count[cid] * 100)
  258.                 npcHandler:say('Here you are.', cid)
  259.             else
  260.                 npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  261.             end
  262.         else
  263.             npcHandler:say('Well, can I help you with something else?', cid)
  264.         end
  265.         npcHandler.topic[cid] = 0
  266.     elseif npcHandler.topic[cid] == 19 then
  267.         if getMoneyCount(msg) < 1 then
  268.             npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  269.             npcHandler.topic[cid] = 0
  270.         else
  271.             count[cid] = getMoneyCount(msg)
  272.             npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your platinum coins into ' .. count[cid] .. ' crystal coins for you?', cid)
  273.             npcHandler.topic[cid] = 20
  274.         end
  275.     elseif npcHandler.topic[cid] == 20 then
  276.         if msgcontains(msg, 'yes') then
  277.             if player:removeItem(2152, count[cid] * 100) then
  278.                 player:addItem(2160, count[cid])
  279.                 npcHandler:say('Here you are.', cid)
  280.             else
  281.                 npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  282.             end
  283.         else
  284.             npcHandler:say('Well, can I help you with something else?', cid)
  285.         end
  286.         npcHandler.topic[cid] = 0
  287.     elseif msgcontains(msg, 'change crystal') then
  288.         npcHandler:say('How many crystal coins would you like to change into platinum?', cid)
  289.         npcHandler.topic[cid] = 21
  290.     elseif npcHandler.topic[cid] == 21 then
  291.         if getMoneyCount(msg) < 1 then
  292.             npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
  293.             npcHandler.topic[cid] = 0
  294.         else
  295.             count[cid] = getMoneyCount(msg)
  296.             npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your crystal coins into ' .. count[cid] * 100 .. ' platinum coins for you?', cid)
  297.             npcHandler.topic[cid] = 22
  298.         end
  299.     elseif npcHandler.topic[cid] == 22 then
  300.         if msgcontains(msg, 'yes') then
  301.             if player:removeItem(2160, count[cid])  then
  302.                 player:addItem(2152, count[cid] * 100)
  303.                 npcHandler:say('Here you are.', cid)
  304.             else
  305.                 npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
  306.             end
  307.         else
  308.             npcHandler:say('Well, can I help you with something else?', cid)
  309.         end
  310.         npcHandler.topic[cid] = 0
  311.     end
  312.     return true
  313. end
  314.  
  315. keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
  316. 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\'.'})
  317. keywordHandler:addKeyword({'bank'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
  318. 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.'})
  319. 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.'})
  320. 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.'})
  321. 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.'})
  322. 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.'})
  323. 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}!"})
  324. 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."})
  325.  
  326. npcHandler:setMessage(MESSAGE_GREET, 'Welcome to the Tibian {bank}, |PLAYERNAME|! What can I do for you?')
  327. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  328. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  329. npcHandler:addModule(FocusModule:new())
Add Comment
Please, Sign In to add comment