Advertisement
Guest User

Untitled

a guest
Oct 4th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.65 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. 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 greetCallback(cid)
  23.     count[cid], transfer[cid] = nil, nil
  24.     return true
  25. end
  26.  
  27. local function creatureSayCallback(cid, type, msg)
  28.     if not npcHandler:isFocused(cid) then
  29.         return false
  30.     end
  31.     local player = Player(cid)
  32. ---------------------------- help ------------------------
  33.     if msgcontains(msg, 'bank account') then
  34.         npcHandler:say({
  35.             'Every Tibian has one. The big advantage is that you can access your money in every branch of the Tibian Bank! ...',
  36.             'Would you like to know more about the {basic} functions of your bank account, the {advanced} functions, or are you already bored, perhaps?'
  37.         }, cid)
  38.         npcHandler.topic[cid] = 0
  39.         return true
  40. ---------------------------- balance ---------------------
  41.     elseif msgcontains(msg, 'balance') then
  42.         npcHandler.topic[cid] = 0
  43.         if player:getBankBalance() >= 100000000 then
  44.             npcHandler:say('I think you must be one of the richest inhabitants in the world! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  45.             return true
  46.         elseif player:getBankBalance() >= 10000000 then
  47.             npcHandler:say('You have made ten millions and it still grows! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  48.             return true
  49.         elseif player:getBankBalance() >= 1000000 then
  50.             npcHandler:say('Wow, you have reached the magic number of a million gp!!! Your account balance is ' .. player:getBankBalance() .. ' gold!', cid)
  51.             return true
  52.         elseif player:getBankBalance() >= 100000 then
  53.             npcHandler:say('You certainly have made a pretty penny. Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  54.             return true
  55.         else
  56.             npcHandler:say('Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  57.             return true
  58.         end
  59. ---------------------------- deposit ---------------------
  60.     elseif msgcontains(msg, 'deposit') then
  61.         count[cid] = player:getMoney()
  62.         if count[cid] < 1 then
  63.             npcHandler:say('You do not have enough gold.', cid)
  64.             npcHandler.topic[cid] = 0
  65.             return false
  66.         end
  67.         if msgcontains(msg, 'all') then
  68.             count[cid] = player:getMoney()
  69.             npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  70.             npcHandler.topic[cid] = 2
  71.             return true
  72.         else
  73.             if string.match(msg,'%d+') then
  74.                 count[cid] = getMoneyCount(msg)
  75.                 if count[cid] < 1 then
  76.                     npcHandler:say('You do not have enough gold.', cid)
  77.                     npcHandler.topic[cid] = 0
  78.                     return false
  79.                 end
  80.                 npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  81.                 npcHandler.topic[cid] = 2
  82.                 return true
  83.             else
  84.                 npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
  85.                 npcHandler.topic[cid] = 1
  86.                 return true
  87.             end
  88.         end
  89.         if not isValidMoney(count[cid]) then
  90.             npcHandler:say('Sorry, but you can\'t deposit that much.', cid)
  91.             npcHandler.topic[cid] = 0
  92.             return false
  93.         end
  94.     elseif npcHandler.topic[cid] == 1 then
  95.         count[cid] = getMoneyCount(msg)
  96.         if isValidMoney(count[cid]) then
  97.             npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  98.             npcHandler.topic[cid] = 2
  99.             return true
  100.         else
  101.             npcHandler:say('You do not have enough gold.', cid)
  102.             npcHandler.topic[cid] = 0
  103.             return true
  104.         end
  105.     elseif npcHandler.topic[cid] == 2 then
  106.         if msgcontains(msg, 'yes') then
  107.             if player:getMoney() >= tonumber(count[cid]) then
  108.                 player:depositMoney(count[cid])
  109.                 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)
  110.             else
  111.                 npcHandler:say('You do not have enough gold.', cid)
  112.             end
  113.         elseif msgcontains(msg, 'no') then
  114.             npcHandler:say('As you wish. Is there something else I can do for you?', cid)
  115.         end
  116.         npcHandler.topic[cid] = 0
  117.         return true
  118. ---------------------------- withdraw --------------------
  119.     elseif msgcontains(msg, 'withdraw') then
  120.         if string.match(msg,'%d+') then
  121.             count[cid] = getMoneyCount(msg)
  122.             if isValidMoney(count[cid]) then
  123.                 npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  124.                 npcHandler.topic[cid] = 7
  125.             else
  126.                 npcHandler:say('There is not enough gold on your account.', cid)
  127.                 npcHandler.topic[cid] = 0
  128.             end
  129.             return true
  130.         else
  131.             npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
  132.             npcHandler.topic[cid] = 6
  133.             return true
  134.         end
  135.     elseif npcHandler.topic[cid] == 6 then
  136.         count[cid] = getMoneyCount(msg)
  137.         if isValidMoney(count[cid]) then
  138.             npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  139.             npcHandler.topic[cid] = 7
  140.         else
  141.             npcHandler:say('There is not enough gold on your account.', cid)
  142.             npcHandler.topic[cid] = 0
  143.         end
  144.         return true
  145.     elseif npcHandler.topic[cid] == 7 then
  146.         if msgcontains(msg, 'yes') then
  147.             if player:getFreeCapacity() >= getMoneyWeight(count[cid]) then
  148.                 if not player:withdrawMoney(count[cid]) then
  149.                     npcHandler:say('There is not enough gold on your account.', cid)
  150.                 else
  151.                     npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
  152.                 end
  153.             else
  154.                 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)
  155.             end
  156.             npcHandler.topic[cid] = 0
  157.         elseif msgcontains(msg, 'no') then
  158.             npcHandler:say('The customer is king! Come back anytime you want to if you wish to {withdraw} your money.', cid)
  159.             npcHandler.topic[cid] = 0
  160.         end
  161.         return true
  162. ---------------------------- transfer --------------------
  163.     elseif msgcontains(msg, 'transfer') then
  164.         npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
  165.         npcHandler.topic[cid] = 11
  166.     elseif npcHandler.topic[cid] == 11 then
  167.         count[cid] = getMoneyCount(msg)
  168.         if player:getBankBalance() < count[cid] then
  169.             npcHandler:say('There is not enough gold on your account.', cid)
  170.             npcHandler.topic[cid] = 0
  171.             return true
  172.         end
  173.         if isValidMoney(count[cid]) then
  174.             npcHandler:say('Who would you like transfer ' .. count[cid] .. ' gold to?', cid)
  175.             npcHandler.topic[cid] = 12
  176.         else
  177.             npcHandler:say('There is not enough gold on your account.', cid)
  178.             npcHandler.topic[cid] = 0
  179.         end
  180.     elseif npcHandler.topic[cid] == 12 then
  181.         transfer[cid] = msg
  182.         if player:getName() == transfer[cid] then
  183.             npcHandler:say('Fill in this field with person who receives your gold!', cid)
  184.             npcHandler.topic[cid] = 0
  185.             return true
  186.         end
  187.         if playerExists(transfer[cid]) then
  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, onlyFocus = true, text = 'We can {change} money for you. You can also access your {bank account}.'})
  316. keywordHandler:addKeyword({'change'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, 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, onlyFocus = true, text = 'We can {change} money for you. You can also access your {bank account}.'})
  318. keywordHandler:addKeyword({'advanced'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, 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, onlyFocus = true, 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, onlyFocus = true, 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, onlyFocus = true, 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, onlyFocus = true, text = 'I work in this bank. I can change money for you and help you with your bank account.'})
  323.  
  324. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  325. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  326. npcHandler:setMessage(MESSAGE_GREET, "Welcome |PLAYERNAME|! What business do you have in the Kormaran bank today?")
  327. npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye, |PLAYERNAME|.")
  328. npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, |PLAYERNAME|.")
  329. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement