SHARE
TWEET

Untitled

a guest Sep 7th, 2018 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = 'Don\'t forget to deposit your money here in the The Forgotten Bank before you head out for adventure.'} }
  14. if VoiceModule then
  15.     npcHandler:addModule(VoiceModule:new(voices))
  16. end
  17.  
  18. ---------------------------- PLAYER BANK FUNCTIONS --------
  19. function getMoneyCount(string)
  20.     local b, e = string:find("%d+")
  21.     local money = b and e and tonumber(string:sub(b, e)) or -1
  22.     if isValidMoney(money) then
  23.         return money
  24.     end
  25.     return -1
  26. end
  27.  
  28. function getMoneyWeight(money)
  29.     local gold = money
  30.     local crystal = math.floor(gold / 10000)
  31.     gold = gold - crystal * 10000
  32.     local platinum = math.floor(gold / 100)
  33.     gold = gold - platinum * 100
  34.     return (ItemType(2160):getWeight() * crystal) + (ItemType(2152):getWeight() * platinum) + (ItemType(2148):getWeight() * gold)
  35. end
  36.  
  37. function isValidMoney(money)
  38.     return isNumber(money) and money > 0 and money < 4294967296
  39. end
  40.  
  41. function isNumber(str)
  42.     return tonumber(str) ~= nil
  43. end
  44.  
  45. function playerExists(name)
  46.     local resultId = db.storeQuery('SELECT `name` FROM `players` WHERE `name` = ' .. db.escapeString(name))
  47.     if resultId then
  48.         result.free(resultId)
  49.         return true
  50.     end
  51.     return false
  52. end
  53. ---------------------------- /PLAYER BANK FUNCTIONS -------
  54.  
  55. ---------------------------- GUILD BANK FUNCTIONS ---------
  56. local receiptFormat = 'Date: %s\nType: %s\nGold Amount: %d\nReceipt Owner: %s\nRecipient: %s\n\n%s'
  57. local function getReceipt(info)
  58.     local receipt = Game.createItem(info.success and 24301 or 24302)
  59.     receipt:setAttribute(ITEM_ATTRIBUTE_TEXT, receiptFormat:format(os.date('%d. %b %Y - %H:%M:%S'), info.type, info.amount, info.owner, info.recipient, info.message))
  60.  
  61.     return receipt
  62. end
  63.  
  64. local function getGuildIdByName(name, func)
  65.     db.asyncStoreQuery('SELECT `id` FROM `guilds` WHERE `name` = ' .. db.escapeString(name),
  66.         function(resultId)
  67.             if resultId then
  68.                 func(result.getNumber(resultId, 'id'))
  69.                 result.free(resultId)
  70.             else
  71.                 func(nil)
  72.             end
  73.         end
  74.     )
  75. end
  76.  
  77. local function getGuildBalance(id)
  78.     local guild = Guild(id)
  79.     if guild then
  80.         return guild:getBankBalance()
  81.     else
  82.         local balance
  83.         local resultId = db.storeQuery('SELECT `balance` FROM `guilds` WHERE `id` = ' .. id)
  84.         if resultId then
  85.             balance = result.getNumber(resultId, 'balance')
  86.             result.free(resultId)
  87.         end
  88.  
  89.         return balance
  90.     end
  91. end
  92.  
  93. local function setGuildBalance(id, balance)
  94.     local guild = Guild(id)
  95.     if guild then
  96.         guild:setBankBalance(balance)
  97.     else
  98.         db.query('UPDATE `guilds` SET `balance` = ' .. balance .. ' WHERE `id` = ' .. id)
  99.     end
  100. end
  101.  
  102. local function transferFactory(playerName, amount, fromGuildId, info)
  103.     return function(toGuildId)
  104.         if not toGuildId then
  105.             local player = Player(playerName)
  106.             if player then
  107.                 info.success = false
  108.                 info.message = 'We are sorry to inform you that we could not fulfil your request, because we could not find the recipient guild.'
  109.                 local inbox = player:getInbox()
  110.                 local receipt = getReceipt(info)
  111.                 inbox:addItemEx(receipt, INDEX_WHEREEVER, FLAG_NOLIMIT)
  112.             end
  113.         else
  114.             local fromBalance = getGuildBalance(fromGuildId)
  115.             if fromBalance < amount then
  116.                 info.success = false
  117.                 info.message = 'We are sorry to inform you that we could not fulfill your request, due to a lack of the required sum on your guild account.'
  118.             else
  119.                 info.success = true
  120.                 info.message = 'We are happy to inform you that your transfer request was successfully carried out.'
  121.                 setGuildBalance(fromGuildId, fromBalance - amount)
  122.                 setGuildBalance(toGuildId, getGuildBalance(toGuildId) + amount)
  123.             end
  124.  
  125.             local player = Player(playerName)
  126.             if player then
  127.                 local inbox = player:getInbox()
  128.                 local receipt = getReceipt(info)
  129.                 inbox:addItemEx(receipt, INDEX_WHEREEVER, FLAG_NOLIMIT)
  130.             end
  131.         end
  132.     end
  133. end
  134. --------------------------- /GUILD BANK FUNCTIONS --------
  135.  
  136. local function greetCallback(cid)
  137.     count[cid], transfer[cid] = nil, nil
  138.     return true
  139. end
  140.  
  141. local function creatureSayCallback(cid, type, msg)
  142.     if not npcHandler:isFocused(cid) then
  143.         return false
  144.     end
  145.     local player = Player(cid)
  146. ---------------------------- HELP ------------------------
  147.     if msgcontains(msg, 'bank account') then
  148.         npcHandler:say({
  149.             'Every Tibian has one. The big advantage is that you can access your money in every branch of the Tibian Bank! ...',
  150.             'Would you like to know more about the {basic} functions of your bank account or are you already bored, perhaps?'
  151.         }, cid)
  152.         npcHandler.topic[cid] = 0
  153.         return true
  154. ---------------------------- BALANCE ---------------------
  155. ---------------------------- guild balance ---------------
  156.     elseif msgcontains(msg, 'guild balance') then
  157.         npcHandler.topic[cid] = 0
  158.         if not player:getGuild() then
  159.             npcHandler:say('You are not a member of a guild.', cid)
  160.             return false
  161.         end          
  162.         npcHandler:say('Your guild account balance is ' .. player:getGuild():getBankBalance() .. ' gold.', cid)
  163.         return true
  164. ---------------------------- player balance --------------
  165.     elseif msgcontains(msg, 'balance') then
  166.         npcHandler.topic[cid] = 0
  167.         if player:getBankBalance() >= 100000000 then
  168.             npcHandler:say('I think you must be one of the richest inhabitants in the world! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  169.             return true
  170.         elseif player:getBankBalance() >= 10000000 then
  171.             npcHandler:say('You have made ten millions and it still grows! Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  172.             return true
  173.         elseif player:getBankBalance() >= 1000000 then
  174.             npcHandler:say('Wow, you have reached the magic number of a million gp!!! Your account balance is ' .. player:getBankBalance() .. ' gold!', cid)
  175.             return true
  176.         elseif player:getBankBalance() >= 100000 then
  177.             npcHandler:say('You certainly have made a pretty penny. Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  178.             return true
  179.         else
  180.             npcHandler:say('Your account balance is ' .. player:getBankBalance() .. ' gold.', cid)
  181.             return true
  182.         end
  183. ---------------------------- DEPOSIT ---------------------
  184. ---------------------------- guild deposit ---------------
  185.     elseif msgcontains(msg, 'guild deposit') then
  186.         if not player:getGuild() then
  187.             npcHandler:say('You are not a member of a guild.', cid)
  188.             npcHandler.topic[cid] = 0
  189.             return false
  190.         end
  191.        -- count[cid] = player:getMoney()
  192.        -- if count[cid] < 1 then
  193.            -- npcHandler:say('You do not have enough gold.', cid)
  194.            -- npcHandler.topic[cid] = 0
  195.            -- return false
  196.         --end
  197.         if string.match(msg, '%d+') then
  198.             count[cid] = getMoneyCount(msg)
  199.             if count[cid] < 1 then
  200.                 npcHandler:say('You do not have enough gold.', cid)
  201.                 npcHandler.topic[cid] = 0
  202.                 return false
  203.             end
  204.             npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold to your {guild account}?', cid)
  205.             npcHandler.topic[cid] = 23
  206.             return true
  207.         else
  208.             npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
  209.             npcHandler.topic[cid] = 22
  210.             return true
  211.         end
  212.     elseif npcHandler.topic[cid] == 22 then
  213.         count[cid] = getMoneyCount(msg)
  214.         if isValidMoney(count[cid]) then
  215.             npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold to your {guild account}?', cid)
  216.             npcHandler.topic[cid] = 23
  217.             return true
  218.         else
  219.             npcHandler:say('You do not have enough gold.', cid)
  220.             npcHandler.topic[cid] = 0
  221.             return true
  222.         end
  223.     elseif npcHandler.topic[cid] == 23 then
  224.         if msgcontains(msg, 'yes') then      
  225.             npcHandler:say('Alright, we have placed an order to deposit the amount of ' .. count[cid] .. ' gold to your guild account. Please check your inbox for confirmation.', cid)
  226.             local guild = player:getGuild()
  227.             local info = {
  228.                 type = 'Guild Deposit',
  229.                 amount = count[cid],
  230.                 owner = player:getName() .. ' of ' .. guild:getName(),
  231.                 recipient = guild:getName()
  232.             }
  233.             local playerBalance = player:getBankBalance()
  234.             if playerBalance < tonumber(count[cid]) then
  235.                 info.message = 'We are sorry to inform you that we could not fulfill your request, due to a lack of the required sum on your bank account.'
  236.                 info.success = false
  237.             else
  238.                 info.message = 'We are happy to inform you that your transfer request was successfully carried out.'
  239.                 info.success = true
  240.                 guild:setBankBalance(guild:getBankBalance() + tonumber(count[cid]))
  241.                 player:setBankBalance(playerBalance - tonumber(count[cid]))                      
  242.             end
  243.  
  244.             local inbox = player:getInbox()
  245.             local receipt = getReceipt(info)
  246.             inbox:addItemEx(receipt, INDEX_WHEREEVER, FLAG_NOLIMIT)
  247.         elseif msgcontains(msg, 'no') then
  248.             npcHandler:say('As you wish. Is there something else I can do for you?', cid)
  249.         end
  250.         npcHandler.topic[cid] = 0
  251.         return true
  252. ---------------------------- player deposit --------------
  253.     elseif msgcontains(msg, 'deposit') then
  254.         count[cid] = player:getMoney()
  255.         if count[cid] < 1 then
  256.             npcHandler:say('You do not have enough gold.', cid)
  257.             npcHandler.topic[cid] = 0
  258.             return false
  259.         end
  260.         if msgcontains(msg, 'all') then
  261.             count[cid] = player:getMoney()
  262.             npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  263.             npcHandler.topic[cid] = 2
  264.             return true
  265.         else
  266.             if string.match(msg,'%d+') then
  267.  
  268.                 count[cid] = getMoneyCount(msg)
  269.                 if count[cid] < 1 then
  270.                     npcHandler:say('You do not have enough gold.', cid)
  271.                     npcHandler.topic[cid] = 0
  272.                     return false
  273.                 end
  274.                 npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  275.                 npcHandler.topic[cid] = 2
  276.                 return true
  277.             else
  278.                 npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
  279.                 npcHandler.topic[cid] = 1
  280.                 return true
  281.             end
  282.         end
  283.         if not isValidMoney(count[cid]) then
  284.             npcHandler:say('Sorry, but you can\'t deposit that much.', cid)
  285.             npcHandler.topic[cid] = 0
  286.             return false
  287.         end
  288.     elseif npcHandler.topic[cid] == 1 then
  289.         count[cid] = getMoneyCount(msg)
  290.         if isValidMoney(count[cid]) then
  291.             npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
  292.             npcHandler.topic[cid] = 2
  293.             return true
  294.         else
  295.             npcHandler:say('You do not have enough gold.', cid)
  296.             npcHandler.topic[cid] = 0
  297.             return true
  298.         end
  299.     elseif npcHandler.topic[cid] == 2 then
  300.         if msgcontains(msg, 'yes') then
  301.             if player:getMoney() >= tonumber(count[cid]) then
  302.                 player:depositMoney(count[cid])
  303.                 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)
  304.             else
  305.                 npcHandler:say('You do not have enough gold.', cid)
  306.             end
  307.         elseif msgcontains(msg, 'no') then
  308.             npcHandler:say('As you wish. Is there something else I can do for you?', cid)
  309.         end
  310.         npcHandler.topic[cid] = 0
  311.         return true
  312. ---------------------------- WITHDRAW --------------------
  313. ---------------------------- guild withdraw --------------
  314.     elseif msgcontains(msg, 'guild withdraw') then
  315.         if not player:getGuild() then
  316.             npcHandler:say('I am sorry but it seems you are currently not in any guild.', cid)
  317.             npcHandler.topic[cid] = 0
  318.             return false
  319.         elseif player:getGuildLevel() < 2 then
  320.             npcHandler:say('Only guild leaders or vice leaders can withdraw money from the guild account.', cid)
  321.             npcHandler.topic[cid] = 0
  322.             return false
  323.         end
  324.  
  325.         if string.match(msg,'%d+') then
  326.             count[cid] = getMoneyCount(msg)
  327.             if isValidMoney(count[cid]) then
  328.                 npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your guild account?', cid)
  329.                 npcHandler.topic[cid] = 25
  330.             else
  331.                 npcHandler:say('There is not enough gold on your guild account.', cid)
  332.                 npcHandler.topic[cid] = 0
  333.             end
  334.             return true
  335.         else
  336.             npcHandler:say('Please tell me how much gold you would like to withdraw from your guild account.', cid)
  337.             npcHandler.topic[cid] = 24
  338.             return true
  339.         end
  340.     elseif npcHandler.topic[cid] == 24 then
  341.         count[cid] = getMoneyCount(msg)
  342.         if isValidMoney(count[cid]) then
  343.             npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your guild account?', cid)
  344.             npcHandler.topic[cid] = 25
  345.         else
  346.             npcHandler:say('There is not enough gold on your guild account.', cid)
  347.             npcHandler.topic[cid] = 0
  348.         end
  349.         return true
  350.     elseif npcHandler.topic[cid] == 25 then
  351.         if msgcontains(msg, 'yes') then
  352.             local guild = player:getGuild()
  353.             local balance = guild:getBankBalance()
  354.             npcHandler:say('We placed an order to withdraw ' .. count[cid] .. ' gold from your guild account. Please check your inbox for confirmation.', cid)
  355.             local info = {
  356.                 type = 'Guild Withdraw',
  357.                 amount = count[cid],
  358.                 owner = player:getName() .. ' of ' .. guild:getName(),
  359.                 recipient = player:getName()
  360.             }
  361.             if balance < tonumber(count[cid]) then
  362.                 info.message = 'We are sorry to inform you that we could not fulfill your request, due to a lack of the required sum on your guild account.'
  363.                 info.success = false
  364.             else
  365.                 info.message = 'We are happy to inform you that your transfer request was successfully carried out.'
  366.                 info.success = true
  367.                 guild:setBankBalance(balance - tonumber(count[cid]))
  368.                 local playerBalance = player:getBankBalance()
  369.                 player:setBankBalance(playerBalance + tonumber(count[cid]))                      
  370.             end
  371.  
  372.             local inbox = player:getInbox()
  373.             local receipt = getReceipt(info)
  374.             inbox:addItemEx(receipt, INDEX_WHEREEVER, FLAG_NOLIMIT)
  375.             npcHandler.topic[cid] = 0
  376.         elseif msgcontains(msg, 'no') then
  377.             npcHandler:say('As you wish. Is there something else I can do for you?', cid)
  378.             npcHandler.topic[cid] = 0
  379.         end
  380.         return true
  381. ---------------------------- player withdraw -------------
  382.     elseif msgcontains(msg, 'withdraw') then
  383.         if string.match(msg,'%d+') then
  384.             count[cid] = getMoneyCount(msg)
  385.             if isValidMoney(count[cid]) then
  386.                 npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  387.                 npcHandler.topic[cid] = 7
  388.             else
  389.                 npcHandler:say('There is not enough gold on your account.', cid)
  390.                 npcHandler.topic[cid] = 0
  391.             end
  392.             return true
  393.         else
  394.             npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
  395.             npcHandler.topic[cid] = 6
  396.             return true
  397.         end
  398.     elseif npcHandler.topic[cid] == 6 then
  399.         count[cid] = getMoneyCount(msg)
  400.         if isValidMoney(count[cid]) then
  401.             npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
  402.             npcHandler.topic[cid] = 7
  403.         else
  404.             npcHandler:say('There is not enough gold on your account.', cid)
  405.             npcHandler.topic[cid] = 0
  406.         end
  407.         return true
  408.     elseif npcHandler.topic[cid] == 7 then
  409.         if msgcontains(msg, 'yes') then
  410.             if player:getFreeCapacity() >= getMoneyWeight(count[cid]) then
  411.                 if not player:withdrawMoney(count[cid]) then
  412.                     npcHandler:say('There is not enough gold on your account.', cid)
  413.                 else
  414.                     npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
  415.                 end
  416.             else
  417.                 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)
  418.             end
  419.             npcHandler.topic[cid] = 0
  420.         elseif msgcontains(msg, 'no') then
  421.             npcHandler:say('The customer is king! Come back anytime you want to if you wish to {withdraw} your money.', cid)
  422.             npcHandler.topic[cid] = 0
  423.         end
  424.         return true
  425. ---------------------------- TRANSFER --------------------
  426. ---------------------------- guild transfer --------------
  427.     elseif msgcontains(msg, 'guild transfer') then
  428.         if not player:getGuild() then
  429.             npcHandler:say('I am sorry but it seems you are currently not in any guild.', cid)
  430.             npcHandler.topic[cid] = 0
  431.             return false
  432.         elseif player:getGuildLevel() < 2 then
  433.             npcHandler:say('Only guild leaders or vice leaders can transfer money from the guild account.', cid)
  434.             npcHandler.topic[cid] = 0
  435.             return false
  436.         end
  437.  
  438.         if string.match(msg, '%d+') then
  439.             count[cid] = getMoneyCount(msg)
  440.             if isValidMoney(count[cid]) then
  441.                 transfer[cid] = string.match(msg, 'to%s*(.+)$')
  442.                 if transfer[cid] then
  443.                     npcHandler:say('So you would like to transfer ' .. count[cid] .. ' gold from your guild account to guild ' .. transfer[cid] .. '?', cid)
  444.                     npcHandler.topic[cid] = 28
  445.                 else
  446.                     npcHandler:say('Which guild would you like to transfer ' .. count[cid] .. ' gold to?', cid)
  447.                     npcHandler.topic[cid] = 27
  448.                 end
  449.             else
  450.                 npcHandler:say('There is not enough gold on your guild account.', cid)
  451.                 npcHandler.topic[cid] = 0
  452.             end
  453.         else
  454.             npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
  455.             npcHandler.topic[cid] = 26
  456.         end
  457.         return true
  458.     elseif npcHandler.topic[cid] == 26 then
  459.         count[cid] = getMoneyCount(msg)
  460.         if player:getGuild():getBankBalance() < count[cid] then
  461.             npcHandler:say('There is not enough gold on your guild account.', cid)
  462.             npcHandler.topic[cid] = 0
  463.             return true
  464.         end
  465.         if isValidMoney(count[cid]) then
  466.             npcHandler:say('Which guild would you like to transfer ' .. count[cid] .. ' gold to?', cid)
  467.             npcHandler.topic[cid] = 27
  468.         else
  469.             npcHandler:say('There is not enough gold on your account.', cid)
  470.             npcHandler.topic[cid] = 0
  471.         end
  472.         return true
  473.     elseif npcHandler.topic[cid] == 27 then
  474.         transfer[cid] = msg
  475.         if player:getGuild():getName() == transfer[cid] then
  476.             npcHandler:say('Fill in this field with person who receives your gold!', cid)
  477.             npcHandler.topic[cid] = 0
  478.             return true
  479.         end
  480.         npcHandler:say('So you would like to transfer ' .. count[cid] .. ' gold from your guild account to guild ' .. transfer[cid] .. '?', cid)
  481.         npcHandler.topic[cid] = 28
  482.         return true
  483.     elseif npcHandler.topic[cid] == 28 then
  484.         if msgcontains(msg, 'yes') then
  485.             npcHandler:say('We have placed an order to transfer ' .. count[cid] .. ' gold from your guild account to guild ' .. transfer[cid] .. '. Please check your inbox for confirmation.', cid)
  486.             local guild = player:getGuild()
  487.             local balance = guild:getBankBalance()
  488.             local info = {
  489.                 type = 'Guild to Guild Transfer',
  490.                 amount = count[cid],
  491.                 owner = player:getName() .. ' of ' .. guild:getName(),
  492.                 recipient = transfer[cid]
  493.             }
  494.             if balance < tonumber(count[cid]) then
  495.                 info.message = 'We are sorry to inform you that we could not fulfill your request, due to a lack of the required sum on your guild account.'
  496.                 info.success = false
  497.                 local inbox = player:getInbox()
  498.                 local receipt = getReceipt(info)
  499.                 inbox:addItemEx(receipt, INDEX_WHEREEVER, FLAG_NOLIMIT)
  500.             else
  501.                 getGuildIdByName(transfer[cid], transferFactory(player:getName(), tonumber(count[cid]), guild:getId(), info))                
  502.             end
  503.             npcHandler.topic[cid] = 0
  504.         elseif msgcontains(msg, 'no') then
  505.             npcHandler:say('Alright, is there something else I can do for you?', cid)
  506.         end
  507.         npcHandler.topic[cid] = 0
  508. ---------------------------- player transfer -------------
  509.     elseif msgcontains(msg, 'transfer') then
  510.         npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
  511.         npcHandler.topic[cid] = 11
  512.     elseif npcHandler.topic[cid] == 11 then
  513.         count[cid] = getMoneyCount(msg)
  514.         if player:getBankBalance() < count[cid] then
  515.             npcHandler:say('There is not enough gold on your account.', cid)
  516.             npcHandler.topic[cid] = 0
  517.             return true
  518.         end
  519.         if isValidMoney(count[cid]) then
  520.             npcHandler:say('Who would you like transfer ' .. count[cid] .. ' gold to?', cid)
  521.             npcHandler.topic[cid] = 12
  522.         else
  523.             npcHandler:say('There is not enough gold on your account.', cid)
  524.             npcHandler.topic[cid] = 0
  525.         end
  526.     elseif npcHandler.topic[cid] == 12 then
  527.         transfer[cid] = msg
  528.         if player:getName() == transfer[cid] then
  529.             npcHandler:say('Fill in this field with person who receives your gold!', cid)
  530.             npcHandler.topic[cid] = 0
  531.             return true
  532.         end
  533.         if playerExists(transfer[cid]) then
  534.         local arrayDenied = {"accountmanager", "rooksample", "druidsample", "sorcerersample", "knightsample", "paladinsample"}
  535.             if isInArray(arrayDenied, string.gsub(transfer[cid]:lower(), " ", "")) then
  536.                 npcHandler:say('This player does not exist.', cid)
  537.                 npcHandler.topic[cid] = 0
  538.                 return true
  539.             end
  540.             npcHandler:say('So you would like to transfer ' .. count[cid] .. ' gold to ' .. transfer[cid] .. '?', cid)
  541.             npcHandler.topic[cid] = 13
  542.         else
  543.             npcHandler:say('This player does not exist.', cid)
  544.             npcHandler.topic[cid] = 0
  545.         end
  546.     elseif npcHandler.topic[cid] == 13 then
  547.         if msgcontains(msg, 'yes') then
  548.             if not player:transferMoneyTo(transfer[cid], count[cid]) then
  549.                 npcHandler:say('You cannot transfer money to this account.', cid)
  550.             else
  551.                 npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. transfer[cid] ..'.', cid)
  552.                 transfer[cid] = nil
  553.             end
  554.         elseif msgcontains(msg, 'no') then
  555.             npcHandler:say('Alright, is there something else I can do for you?', cid)
  556.         end
  557.         npcHandler.topic[cid] = 0
  558.  
  559.         elseif msgcontains(msg, 'change gold') then
  560.         npcHandler:say('How many platinum coins would you like to get?', cid)
  561.         npcHandler.topic[cid] = 14
  562.     elseif npcHandler.topic[cid] == 14 then
  563.         if getMoneyCount(msg) < 1 then
  564.             npcHandler:say('Sorry, you do not have enough gold coins.', cid)
  565.             npcHandler.topic[cid] = 0
  566.         else
  567.             count[cid] = getMoneyCount(msg)
  568.             npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your gold coins into ' .. count[cid] .. ' platinum coins?', cid)
  569.             npcHandler.topic[cid] = 15
  570.         end
  571.     elseif npcHandler.topic[cid] == 15 then
  572.         if msgcontains(msg, 'yes') then
  573.             if player:removeItem(2148, count[cid] * 100) then
  574.                 player:addItem(2152, count[cid])
  575.                 npcHandler:say('Here you are.', cid)
  576.             else
  577.                 npcHandler:say('Sorry, you do not have enough gold coins.', cid)
  578.             end
  579.         else
  580.             npcHandler:say('Well, can I help you with something else?', cid)
  581.         end
  582.         npcHandler.topic[cid] = 0
  583.     elseif msgcontains(msg, 'change platinum') then
  584.         npcHandler:say('Would you like to change your platinum coins into gold or crystal?', cid)
  585.         npcHandler.topic[cid] = 16
  586.     elseif npcHandler.topic[cid] == 16 then
  587.         if msgcontains(msg, 'gold') then
  588.             npcHandler:say('How many platinum coins would you like to change into gold?', cid)
  589.             npcHandler.topic[cid] = 17
  590.         elseif msgcontains(msg, 'crystal') then
  591.             npcHandler:say('How many crystal coins would you like to get?', cid)
  592.             npcHandler.topic[cid] = 19
  593.         else
  594.             npcHandler:say('Well, can I help you with something else?', cid)
  595.             npcHandler.topic[cid] = 0
  596.         end
  597.     elseif npcHandler.topic[cid] == 17 then
  598.         if getMoneyCount(msg) < 1 then
  599.             npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  600.             npcHandler.topic[cid] = 0
  601.         else
  602.             count[cid] = getMoneyCount(msg)
  603.             npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your platinum coins into ' .. count[cid] * 100 .. ' gold coins for you?', cid)
  604.             npcHandler.topic[cid] = 18
  605.         end
  606.     elseif npcHandler.topic[cid] == 18 then
  607.         if msgcontains(msg, 'yes') then
  608.             if player:removeItem(2152, count[cid]) then
  609.                 player:addItem(2148, count[cid] * 100)
  610.                 npcHandler:say('Here you are.', cid)
  611.             else
  612.                 npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  613.             end
  614.         else
  615.             npcHandler:say('Well, can I help you with something else?', cid)
  616.         end
  617.         npcHandler.topic[cid] = 0
  618.     elseif npcHandler.topic[cid] == 19 then
  619.         if getMoneyCount(msg) < 1 then
  620.             npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  621.             npcHandler.topic[cid] = 0
  622.         else
  623.             count[cid] = getMoneyCount(msg)
  624.             npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your platinum coins into ' .. count[cid] .. ' crystal coins for you?', cid)
  625.             npcHandler.topic[cid] = 20
  626.         end
  627.     elseif npcHandler.topic[cid] == 20 then
  628.         if msgcontains(msg, 'yes') then
  629.             if player:removeItem(2152, count[cid] * 100) then
  630.                 player:addItem(2160, count[cid])
  631.                 npcHandler:say('Here you are.', cid)
  632.             else
  633.                 npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
  634.             end
  635.         else
  636.             npcHandler:say('Well, can I help you with something else?', cid)
  637.         end
  638.         npcHandler.topic[cid] = 0
  639.     elseif msgcontains(msg, 'change crystal') then
  640.         npcHandler:say('How many crystal coins would you like to change into platinum?', cid)
  641.         npcHandler.topic[cid] = 21
  642.     elseif npcHandler.topic[cid] == 21 then
  643.         if getMoneyCount(msg) < 1 then
  644.             npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
  645.             npcHandler.topic[cid] = 0
  646.         else
  647.             count[cid] = getMoneyCount(msg)
  648.             npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your crystal coins into ' .. count[cid] * 100 .. ' platinum coins for you?', cid)
  649.             npcHandler.topic[cid] = 22
  650.         end
  651.     elseif npcHandler.topic[cid] == 22 then
  652.         if msgcontains(msg, 'yes') then
  653.             if player:removeItem(2160, count[cid])  then
  654.                 player:addItem(2152, count[cid] * 100)
  655.                 npcHandler:say('Here you are.', cid)
  656.             else
  657.                 npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
  658.             end
  659.         else
  660.             npcHandler:say('Well, can I help you with something else?', cid)
  661.         end
  662.         npcHandler.topic[cid] = 0
  663.     end
  664.     return true
  665. end
  666.  
  667. --keywordHandler:addKeyword({'money'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
  668. --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\'.'})
  669. --keywordHandler:addKeyword({'bank'}, StdModule.say, {npcHandler = npcHandler, text = 'We can {change} money for you. You can also access your {bank account}.'})
  670. 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.'})
  671. 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.'})
  672. 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 and pay the rent of your house or itens on the market.'})
  673. keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'I work in this bank. I can help you with your {bank account}.'})
  674.  
  675. npcHandler:setMessage(MESSAGE_GREET, "Yes? What may I do for you, |PLAYERNAME|? Check out your {bank account}, perhaps?")
  676. npcHandler:setMessage(MESSAGE_FAREWELL, "Have a nice day.")
  677. npcHandler:setMessage(MESSAGE_WALKAWAY, "Have a nice day.")
  678. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  679. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  680. npcHandler:addModule(FocusModule:new())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top