aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2016-06-25 23:22:36 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2016-06-25 23:22:36 +0200
commit9d601cb4d6bf3abccfecd2b810c59ba3e64f3300 (patch)
tree1695b973131461289ae1235274db514b39a07bfd
parentb4317fceb6dadf7973acb1bbebfb1b970bdbe7a0 (diff)
downloadatm-9d601cb4d6bf3abccfecd2b810c59ba3e64f3300.tar.gz
atm-9d601cb4d6bf3abccfecd2b810c59ba3e64f3300.tar.bz2
atm-9d601cb4d6bf3abccfecd2b810c59ba3e64f3300.zip
Added interest mechanism
-rw-r--r--init.lua2
-rw-r--r--interest.lua16
2 files changed, 18 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index bc1970d..12a828c 100644
--- a/init.lua
+++ b/init.lua
@@ -1,6 +1,7 @@
atm = {}
atm.balance = {}
atm.pth = minetest.get_worldpath().."/atm_accounts"
+local modpath = minetest.get_modpath("atm")
function atm.showform (player)
atm.readaccounts()
@@ -186,3 +187,4 @@ minetest.register_craft({
{"default:steel_ingot", "default:mese_crystal", "default:steel_ingot"}
}
})
+dofile(modpath .. "/interest.lua")
diff --git a/interest.lua b/interest.lua
new file mode 100644
index 0000000..b8f8d0c
--- /dev/null
+++ b/interest.lua
@@ -0,0 +1,16 @@
+-- adapted from the income.lua file from the currency mod.
+local timer = 0
+minetest.register_globalstep(function(dtime)
+ timer = timer + dtime;
+ if timer >= 3000 then
+ timer = 0
+ atm.readaccounts()
+ for _,player in ipairs(minetest.get_connected_players()) do
+ local name = player:get_player_name()
+ if not (atm.balance[name] == nil) then
+ atm.balance[name] = math.floor(atm.balance[name] * 1.05)
+ end
+ end
+ atm.saveaccounts()
+ end
+end)