GlobalEvent Bank Interest

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by Darkhaos, Dec 28, 2011.

  1. Darkhaos

    Darkhaos (:

    Joined:
    Apr 17, 2008
    Messages:
    1,922
    Likes Received:
    172
    Best Answers:
    0
    With this script players will receive an interest in their bank account each month (30th, 27th for February).

    • You can configure the amount of interest gained for free and premium accounts.
    • The info about every interest given can be readed in a log file, declared by yourself.

    The script works in a global event with an interval of two hours, but relax, players won't receive interest every 2 hours, just once at day and at month.

    First, execute this in MySQL
    Code (SQL):
    1. CREATE TABLE IF NOT EXISTS `bank_interest` (
    2.   `id` INT(11) NOT NULL AUTO_INCREMENT,
    3.   `day` INT(11) NOT NULL DEFAULT '0',
    4.   `month` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    5.   `year` INT(11) NOT NULL DEFAULT '0',
    6.   `given` INT(11) NOT NULL DEFAULT '0',
    7.   `highest` INT(11) NOT NULL DEFAULT '0',
    8.   PRIMARY KEY (`id`),
    9.   UNIQUE KEY `id` (`id`)
    10. ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
    Now, create a file in globalevents/scripts and paste this:
    Code (Lua):
    1. local minBalance = 100 --min balance required to gain interest.
    2. local interest =
    3. {
    4.     free = 2, --2%
    5.     premmy = 2.2 --2.2%
    6. }
    7. local day = 30
    8. local log = --save info in a log file?
    9. {
    10.     enabled = true,
    11.     dir = "data/logs/bankInterest.txt"
    12. }
    13.  
    14. function onThink(interval, lastExecution, thinkInterval)
    15.     local t = os.date('*t')
    16.     if t.month == 2 then --February
    17.         day = 27
    18.     end
    19.     local total = 0
    20.     local highest = {}
    21.     local l = db.getResult("select * from bank_interest order by id desc;")
    22.     local checkMonth = false
    23.     if l:getID() ~= -1 and l:getRows() > 0 then
    24.         checkMonth = true
    25.     end
    26.     if t.day == day then
    27.         if checkMonth and t.month == l:getDataInt("month") then
    28.             return true
    29.         end
    30.         local f = io.open(log.dir, "a+")
    31.         local query = db.getResult("select * from players;")
    32.         if log.enabled and f ~= nil then
    33.             f:write("\n\n---------------------------------------------------", "\nStartup at " .. os.date() .. ":\n\n")
    34.         end
    35.         if query:getID() ~= -1 then
    36.             while(true) do
    37.                 local balance = query:getDataInt("balance")
    38.                 if balance >= minBalance then
    39.                     total = total + 1
    40.                     local st = db.getResult("select * from accounts where id = " .. query:getDataInt("account_id") .. ";"):getDataInt("premdays")
    41.                     if log.enabled and f ~= nil then
    42.                         f:write("\n>> Added " .. math.floor((query:getDataInt("balance") * (st > 0 and interest.premmy or interest.free) / 100)) .. " gold to the account balance of " .. query:getDataString("name"))
    43.                     end
    44.                     table.insert(highest, math.floor((query:getDataInt("balance") * (st > 0 and interest.premmy or interest.free) / 100)))
    45.                     db.executeQuery("update players set balance = balance + " .. math.floor((query:getDataInt("balance") * (st > 0 and interest.premmy or interest.free) / 100)) .. " where id = " .. query:getDataInt("id") .. ";")
    46.                 end
    47.                 if not query:next() then break end
    48.             end
    49.             table.sort(highest, function(a, b) return a > b end)
    50.             db.executeQuery("insert into bank_interest values (null, " .. t.day .. ", " .. t.month .. ", " .. t.year .. ", " .. total .. ", " .. highest[1] .. ");")
    51.         end
    52.         if log.enabled and f ~= nil then
    53.             f:write("\n---------------------------------------------------")
    54.             f:close()
    55.         end
    56.     end
    57.     return true
    58. end
    59.  
    Paste this at globalevents.xml:
    Code (XML):
    1. <globalevent name="bankInterest" interval="7200" event="script" value="bankInterest.lua"/>
    Enjoy it and report bugs if you find it.
     
    Mooosie likes this.
  2. MartyX

    MartyX I'm renewing

    Joined:
    Jun 6, 2007
    Messages:
    1,199
    Likes Received:
    138
    Best Answers:
    3
    WOW ... wonderful
     
  3. Mooosie

    Mooosie - Lua Scripter -

    Joined:
    Aug 2, 2008
    Messages:
    702
    Likes Received:
    27
    Best Answers:
    0
    Nice bro1 :D
     
  4. Amiroslo

    Amiroslo http://VAPus.net

    Joined:
    Jul 28, 2009
    Messages:
    6,468
    Likes Received:
    444
    Best Answers:
    3
    i didnt get that, what does it do o.o
     
  5. Seminari

    Seminari Banned User

    Joined:
    Dec 13, 2009
    Messages:
    1,496
    Likes Received:
    35
    Best Answers:
    0
    is working like this:
    player deposit 99999 money to bank
    next withdraw 3500 money
    etc. etc.
    and this scripts every 2 hours updating balance and transactions to database? and we can add to website "players transactions" ? yes? or how it's working?
     
  6. Darkhaos

    Darkhaos (:

    Joined:
    Apr 17, 2008
    Messages:
    1,922
    Likes Received:
    172
    Best Answers:
    0
    No every two hours, it works like a bank in real life. Each month you receive a % of the money that you have in your bank account.

    The globalevent works every hour, but the money will be added only once time per month.

    Example, i have 1000000 gold in my balance and i'm a free account player. At December 30, i'll receive 20k (2% of 1.000.000).
    Next month (January), i'll have 1.020.000, at January 30, i'll receive 20400gp. (2% of 1.020.000).

    @Transactions

    Yes, i made it on my server, i added a new table to database and then edited my bank npc, so every transaction that players do, are stored in database.
     
    Last edited: Dec 29, 2011
  7. Mauzim

    Mauzim Member

    Joined:
    Jan 3, 2011
    Messages:
    568
    Likes Received:
    9
    Best Answers:
    0
    hey i have idea :)
    PLAYERS GET WEEKLY MONEY FOR GAME TIME IN THIS WEEK EXAMPLE 1H = 1K WHEN PLAYER PLAY 10H AT GIVEN WEEK, AT THE END OF THE WEEK GET 10K
     
  8. Fresh

    Fresh KtoĊ› mi kupi premiuma ?

    Joined:
    Oct 21, 2009
    Messages:
    1,374
    Likes Received:
    83
    Best Answers:
    0
    Nice script for anti-idle bots :)
    Anti-idle for 24h = 24k .
     
  9. Mauzim

    Mauzim Member

    Joined:
    Jan 3, 2011
    Messages:
    568
    Likes Received:
    9
    Best Answers:
    0
    and what ?:p its only idea but if u want more players online you can try do that script and turn on anty bot system :)
     
  10. Mauzim

    Mauzim Member

    Joined:
    Jan 3, 2011
    Messages:
    568
    Likes Received:
    9
    Best Answers:
    0
  11. Darkhaos

    Darkhaos (:

    Joined:
    Apr 17, 2008
    Messages:
    1,922
    Likes Received:
    172
    Best Answers:
    0
    Player won't get money for every hour online, don't be stupid and read the main post.
     
  12. HeberPcL

    HeberPcL [PowerOT.com.br]

    Joined:
    Aug 21, 2007
    Messages:
    1,275
    Likes Received:
    39
    Best Answers:
    0
    Nice Idea.

    Thanks!
     
  13. soul4soul

    soul4soul Well-Known Member

    Joined:
    Aug 13, 2007
    Messages:
    1,783
    Likes Received:
    41
    Best Answers:
    0
    I like the idea and thought about creating it myself. Its a good system i like it but it would only be good on low rate OTs. On most OTs players already have too much money and it means nothing.
     
  14. johanivarsson

    johanivarsson New Member

    Joined:
    Nov 21, 2010
    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    What line do i change to make it give interest each day for example :D?
     
  15. Frillinde

    Frillinde Founder: Another Realm

    Joined:
    Jan 16, 2012
    Messages:
    148
    Likes Received:
    3
    Best Answers:
    0
    using crying damson 3.6pl1 I get the following error when starting the server:
    [01/02/2012 21:00:16] [Error - LuaScriptInterface::loadFile] data/globalevents/scripts/bankInterest.lua:49: 'end' expected near ')'
    [01/02/2012 21:00:16] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/bankInterest.lua)
    [01/02/2012 21:00:16] data/globalevents/scripts/bankInterest.lua:49: 'end' expected near ')'

    My code:
    Ive looked but didnt see it and since my coding skills are wimpy could someone fix for me?
     
  16. Bogart

    Bogart ...has super panda powers

    Joined:
    Jun 21, 2009
    Messages:
    7,785
    Likes Received:
    423
    Best Answers:
    6
    You failed at copying, you didn't copy the last end.
     
  17. Frillinde

    Frillinde Founder: Another Realm

    Joined:
    Jan 16, 2012
    Messages:
    148
    Likes Received:
    3
    Best Answers:
    0
    ty that was the problem
     
  18. Kavalor

    Kavalor (Real)Creator of ChaosOT Premium User

    Joined:
    Dec 13, 2007
    Messages:
    196
    Likes Received:
    9
    Best Answers:
    0
     
  19. Okke

    Okke whatever

    Joined:
    Jul 19, 2015
    Messages:
    587
    Likes Received:
    282
    Best Answers:
    6
    Here, read a little about Date & Time for Lua and how it's actually implemented, then just modify the script with the wished information
     
  20. Kavalor

    Kavalor (Real)Creator of ChaosOT Premium User

    Joined:
    Dec 13, 2007
    Messages:
    196
    Likes Received:
    9
    Best Answers:
    0
    Id like to jave date and time not in it at all and let it run every time i call it on the global event because that is a lot more along the lines of what i need but i am away now and when i get gome ill do that if i can
     

Share This Page

Loading...