• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent Bank Interest

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
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
SQL:
CREATE TABLE IF NOT EXISTS `bank_interest` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `day` int(11) NOT NULL DEFAULT '0',
  `month` int(10) unsigned NOT NULL DEFAULT '0',
  `year` int(11) NOT NULL DEFAULT '0',
  `given` int(11) NOT NULL DEFAULT '0',
  `highest` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

Now, create a file in globalevents/scripts and paste this:
Lua:
local minBalance = 100 --min balance required to gain interest.
local interest = 
{
	free = 2, --2%
	premmy = 2.2 --2.2%
}
local day = 30
local log = --save info in a log file?
{
	enabled = true,
	dir = "data/logs/bankInterest.txt"
}

function onThink(interval, lastExecution, thinkInterval)
	local t = os.date('*t')
	if t.month == 2 then --February
		day = 27
	end
	local total = 0
	local highest = {}
	local l = db.getResult("select * from bank_interest order by id desc;")
	local checkMonth = false
	if l:getID() ~= -1 and l:getRows() > 0 then
		checkMonth = true
	end
	if t.day == day then
		if checkMonth and t.month == l:getDataInt("month") then
			return true
		end
		local f = io.open(log.dir, "a+")
		local query = db.getResult("select * from players;")
		if log.enabled and f ~= nil then
			f:write("\n\n---------------------------------------------------", "\nStartup at " .. os.date() .. ":\n\n")
		end
		if query:getID() ~= -1 then
			while(true) do
				local balance = query:getDataInt("balance")
				if balance >= minBalance then
					total = total + 1
					local st = db.getResult("select * from accounts where id = " .. query:getDataInt("account_id") .. ";"):getDataInt("premdays")
					if log.enabled and f ~= nil then
						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"))
					end
					table.insert(highest, math.floor((query:getDataInt("balance") * (st > 0 and interest.premmy or interest.free) / 100)))
					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") .. ";")
				end
				if not query:next() then break end
			end
			table.sort(highest, function(a, b) return a > b end)
			db.executeQuery("insert into bank_interest values (null, " .. t.day .. ", " .. t.month .. ", " .. t.year .. ", " .. total .. ", " .. highest[1] .. ");")
		end
		if log.enabled and f ~= nil then
			f:write("\n---------------------------------------------------")
			f:close()
		end
	end
	return true
end

Paste this at globalevents.xml:
XML:
<globalevent name="bankInterest" interval="7200" event="script" value="bankInterest.lua"/>

Enjoy it and report bugs if you find it.
 
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?
 
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?

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:
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
 
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 :)
 
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.
 
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:
local minBalance = 5000 --min balance required to gain interest.
local interest =
{
free = 1.4, --1.4%
premmy = 2.0 --2.0%
}
local day = 30
local log = --save info in a log file?
{
enabled = true,
dir = "data/logs/bankInterest.txt"
}

function onThink(interval, lastExecution, thinkInterval)
local t = os.date('*t')
if t.month == 2 then --February
day = 27
end
local total = 0
local highest = {}
local l = db.getResult("select * from bank_interest order by id desc;")
local checkMonth = false
if l:getID() ~= -1 and l:getRows() > 0 then
checkMonth = true
end
if t.day == day then
if checkMonth and t.month == l:getDataInt("month") then
return true
end
local f = io.open(log.dir, "a+")
local query = db.getResult("select * from players;")
if log.enabled and f ~= nil then
f:write("\n\n---------------------------------------------------", "\nStartup at " .. os.date() .. ":\n\n")
end
if query:getID() ~= -1 then
while(true) do
local balance = query:getDataInt("balance")
if balance >= minBalance then
total = total + 1
local st = db.getResult("select * from accounts where id = " .. query:getDataInt("account_id") .. ";"):getDataInt("premdays")
if log.enabled and f ~= nil then
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"))
end
table.insert(highest, math.floor((query:getDataInt("balance") * (st > 0 and interest.premmy or interest.free) / 100)))
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") .. ";")
end
if not query:next() then break end
end
table.sort(highest, function(a, b) return a > b ) end
db.executeQuery("insert into bank_interest values (null, " .. t.day .. ", " .. t.month .. ", " .. t.year .. ", " .. total .. ", " .. highest[1] .. ");")
end
if log.enabled and f ~= nil then
f:write("\n---------------------------------------------------")
f:close()
end
end
return true

Ive looked but didnt see it and since my coding skills are wimpy could someone fix for me?
 
Here, read a little about Date & Time for Lua and how it's actually implemented, then just modify the script with the wished information
 
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
 
Back
Top