Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.43 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 getMoneyCount(msg) ~= nil then
  80.             talkState[talkUser] = 0
  81.             return true
  82.         end
  83.                 if(tonumber(msg) > 0 and getMoneyCount(msg) <= getPlayerBalance(cid)) then
  84.                         npcHandler:say("Would you like to withdraw " .. getMoneyCount(msg) .. " gold from your bank account?", cid)
  85.                         transaction[talkUser] = getMoneyCount(msg)
  86.                         talkState[talkUser] = 3
  87.                   elseif (tonumber(msg) < 1) then
  88.                            npcHandler:say("Sure, you want nothing you get nothing!", cid)
  89.                            talkState[talkUser] = 0
  90.                 elseif(getMoneyCount(msg) < 1) then
  91.                         npcHandler:say("How much money would you like to withdraw from your bank account?", cid)
  92.                 elseif(getMoneyCount(msg) > getPlayerBalance(cid)) then
  93.                         npcHandler:say("You don't have enought money on your bank account.", cid)
  94.                         talkState[talkUser] = 0
  95.                 end
  96.                
  97.         -- Deposit Money
  98.         elseif(msgcontains(msg, "deposit")) then
  99.                 npcHandler:say("How much money would you like to deposit to your bank account?", cid)
  100.               talkState[talkUser] = 4
  101.         elseif(talkState[talkUser] == 4) then
  102.                 if(tonumber(msg) > 0 and getMoneyCount(msg) <= getPlayerMoney(cid)) then
  103.                         npcHandler:say("Would you like to deposit " .. getMoneyCount(msg) .. " gold to your bank account?", cid)
  104.                         transaction[talkUser] = getMoneyCount(msg)
  105.                         talkState[talkUser] = 5
  106.                   elseif(tonumber(msg) < 1) then
  107.                            npcHandler:say("You are joking, aren't you??", cid)
  108.                            talkState[talkUser] = 0
  109.                 elseif(getMoneyCount(msg) < 1) then
  110.                         npcHandler:say("How much money would you like to deposit to your bank account?", cid)
  111.                 elseif(getMoneyCount(msg) > getPlayerMoney(cid)) then
  112.                         npcHandler:say("You don't have enought money with you.", cid)
  113.                         talkState[talkUser] = 0
  114.                 end
  115.                
  116.         -- Transfer Money
  117.         elseif(msgcontains(msg, "transfer")) then
  118.                 npcHandler:say("Who do you want transfer money to?", cid)
  119.                 talkState[talkUser] = 6
  120.         elseif(talkState[talkUser] == 6) then
  121.                 if(getPlayerGUIDByName(string.lower(msg)) > 0 and string.lower(msg) ~= string.lower(getCreatureName(cid))) then
  122.                         transfer[talkUser] = getPlayerGUIDByName(string.lower(msg))
  123.                         transfer_name[talkUser] = string.lower(msg)
  124.                         npcHandler:say("How much money would you like to transfer?", cid)
  125.                         talkState[talkUser] = 7
  126.                 else
  127.                         npcHandler:say("There is no such player.", cid)
  128.                         talkState[talkUser] = 0
  129.                 end
  130.         elseif(talkState[talkUser] == 7) then
  131.                 if(tonumber(msg) > 0 and getMoneyCount(msg) <= getPlayerBalance(cid)) then
  132.                         npcHandler:say("Would you like to transfer " .. getMoneyCount(msg) .. " to " .. transfer_name[talkUser] .. "?", cid)
  133.                         transaction[talkUser] = getMoneyCount(msg)
  134.                         talkState[talkUser] = 8
  135.                 elseif(tonumber(msg) < 1) then
  136.                         npcHandler:say("Please think about it. Okay?", cid)
  137.                         talkState[talkUser] = 0
  138.                 elseif(getMoneyCount(msg) < 0) then
  139.                         npcHandler:say("How much money would you like to transfer?", cid)
  140.                 elseif(getMoneyCount(msg) > getPlayerMoney(cid)) then
  141.                         npcHandler:say("You don't have enought money on your bank account.", cid)
  142.                         talkState[talkUser] = 0
  143.                 end
  144.                
  145.         -- Yes
  146.         elseif(msgcontains(msg, "yes")) then  
  147.                 if(talkState[talkUser] == 1) then
  148.                         if(getPlayerMoney(cid) == transaction[talkUser]) then
  149.                                 doPlayerRemoveMoney(cid, transaction[talkUser])
  150.                                 doPlayerSetBalance(cid, getPlayerBalance(cid)+ transaction[talkUser])
  151.                                 npcHandler:say("You deposited " .. transaction[talkUser] .. " gold coins to your bank account.", cid)
  152.                                 transaction[talkUser] = 0
  153.                                 talkState[talkUser] = 0
  154.                         else
  155.                                 npcHandler:say("You don't have enought money.", cid)
  156.                                 transaction[talkUser] = 0
  157.                                 talkState[talkUser] = 1
  158.                         end
  159.                 elseif(talkState[talkUser] == 3) then
  160.                         if(doPlayerAddSafeMoney(cid, transaction[talkUser])) then
  161.                                 doPlayerSetBalance(cid, getPlayerBalance(cid)- transaction[talkUser])
  162.                                 npcHandler:say("You withdrawed " .. transaction[talkUser] .. " gold coins from your bank account.", cid)
  163.                         else
  164.                                 npcHandler:say("You don't have anought capacity or slots in backpack to withdraw " .. transaction[talkUser] .. " gold.", cid)
  165.                         end
  166.                         transaction[talkUser] = 0
  167.                         talkState[talkUser] = 0
  168.                 elseif(talkState[talkUser] == 5) then
  169.                         if(transaction[talkUser] <= getPlayerMoney(cid)) then
  170.                                 doPlayerRemoveMoney(cid, transaction[talkUser])
  171.                                 doPlayerSetBalance(cid, getPlayerBalance(cid)+ transaction[talkUser])
  172.                                 npcHandler:say("You deposited " .. transaction[talkUser] .. " gold coins to your bank account.", cid)
  173.                                 transaction[talkUser] = 0
  174.                                 talkState[talkUser] = 0
  175.                         else
  176.                                 npcHandler:say("You don't have enought money.", cid)
  177.                                 transaction[talkUser] = 0
  178.                                 talkState[talkUser] = 1
  179.                         end
  180.                 elseif(talkState[talkUser] == 8) then
  181.                         if(transaction[talkUser] <= getPlayerMoney(cid)) then
  182.                                 doPlayerRemoveMoney(cid, transaction[talkUser])
  183.                                 doPlayerSetBalance(cid, getPlayerBalance(cid)- transaction[talkUser])
  184.                                 npcHandler:say("You transfered " .. transaction[talkUser] .. " gold coins to " .. transfer_name[talkUser] .. "'s bank account.", cid)
  185.                                     if(getPlayerByName(""..transfer_name[talkUser].."")) then
  186.                                         doPlayerSetBalance(getPlayerByName(""..transfer_name[talkUser]..""), getPlayerBalance(getPlayerByName(""..transfer_name[talkUser].."")) + transaction[talkUser])
  187.                                     else
  188.                                         transferGold(""..transfer_name[talkUser].."", transaction[talkUser])
  189.                                     end
  190.                                 transaction[talkUser] = 0
  191.                                 transfer[talkUser] = 0
  192.                                 transfer_name[talkUser] = ""
  193.                                 talkState[talkUser] = 0
  194.                         else
  195.                                 npcHandler:say("You don't have enought money.", cid)
  196.                                 transaction[talkUser] = 0
  197.                                 talkState[talkUser] = 1
  198.                         end
  199.                 end  
  200.         elseif(msgcontains(msg, "no")) then
  201.                 npcHandler:say("The customer is king! Come back anytime you want to if you wish to withdraw your money.", cid)
  202.                 talkState[talkUser] = 0
  203.         end
  204.         return true
  205. end
  206.  
  207. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  208. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement