diff options
author | gpcf <gpcf@gpcf.eu> | 2024-09-22 15:31:37 +0200 |
---|---|---|
committer | gpcf <gpcf@gpcf.eu> | 2024-09-22 15:31:37 +0200 |
commit | 925b6f62e4ce62aa4c06ee2a3a444eebf5b5c307 (patch) | |
tree | 220607d0a4c435eb6fa4494071004ff972746b09 /interest.lua | |
parent | 5b1a159c17df70b5275cdd92f0e515d46b073ee1 (diff) | |
download | atm-925b6f62e4ce62aa4c06ee2a3a444eebf5b5c307.tar.gz atm-925b6f62e4ce62aa4c06ee2a3a444eebf5b5c307.tar.bz2 atm-925b6f62e4ce62aa4c06ee2a3a444eebf5b5c307.zip |
Add welfare caps, move backend to json
Diffstat (limited to 'interest.lua')
-rw-r--r-- | interest.lua | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/interest.lua b/interest.lua index e492566..696b691 100644 --- a/interest.lua +++ b/interest.lua @@ -1,16 +1,27 @@ -- adapted from the income.lua file from the currency mod. local timer = 0 + +function atm.welfare_payout() + payout = false + for _,player in ipairs(minetest.get_connected_players()) do + local name = player:get_player_name() + local limit = atm.welfare[name] or atm.default_welfare + atm.ensure_init(name) + if limit > 5 then + atm.balance[name] = math.floor(atm.balance[name] + 5) + atm.welfare[name] = limit - 5 + payout = true + end + end + if payout then + atm.saveaccounts() + end +end + minetest.register_globalstep(function(dtime) timer = timer + dtime; if timer >= 1000 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] + 5) - end - end - atm.saveaccounts() + atm.welfare_payout() end end) |