aboutsummaryrefslogtreecommitdiff
path: root/welfare.lua
diff options
context:
space:
mode:
authorgpcf <gpcf@gpcf.eu>2024-09-22 21:21:09 +0200
committergpcf <gpcf@gpcf.eu>2024-09-22 21:21:09 +0200
commit1dcf3af5ab71dccad7b12f4240b62ee695a6dd9a (patch)
tree8f790a7ee6b66160efb9afe94e63399c18234e52 /welfare.lua
parentace14bc0c24ff0fb1901727a088d651e2473cac5 (diff)
downloadatm-1dcf3af5ab71dccad7b12f4240b62ee695a6dd9a.tar.gz
atm-1dcf3af5ab71dccad7b12f4240b62ee695a6dd9a.tar.bz2
atm-1dcf3af5ab71dccad7b12f4240b62ee695a6dd9a.zip
Add command to view financesHEADmaster
Diffstat (limited to 'welfare.lua')
-rw-r--r--welfare.lua63
1 files changed, 63 insertions, 0 deletions
diff --git a/welfare.lua b/welfare.lua
new file mode 100644
index 0000000..964c2f6
--- /dev/null
+++ b/welfare.lua
@@ -0,0 +1,63 @@
+-- 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.welfare_cap
+ atm.ensure_init(name)
+ if limit > atm.welfare_amount then
+ atm.balance[name] = math.floor(atm.balance[name] + atm.welfare_amount)
+ atm.welfare[name] = limit - atm.welfare_amount
+ 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.welfare_payout()
+ end
+end)
+
+
+minetest.register_chatcommand("give_welfare", {
+ description = "Put a player on welfare payments",
+ params = "<player> <amount>",
+ privs = { kick = true },
+ func = function (name, params)
+ local plname, amount = params:match("(%S+)%s+(%d+)")
+ if not plname then
+ return false, "Invalid parameters: "..params
+ end
+ if not atm.balance[plname] then
+ return false, plname.." does not have a bank account!"
+ end
+ atm.welfare[plname] = tonumber(amount) or atm.welfare_cap
+ minetest.log("action", "[ATM] Player "..plname.." put on welfare by "..name)
+ minetest.chat_send_player(name, "Player "..plname.." put on welfare successfully.")
+ return true
+ end,
+})
+
+minetest.register_chatcommand("view_finances", {
+ description = "view a player's finances",
+ params = "<player>",
+ privs = { kick = true },
+ func = function (name, plname)
+ if not atm.balance[plname] then
+ return false, plname.." does not have a bank account!"
+ end
+ minetest.chat_send_player(name, "Account balance: "..atm.balance[plname])
+ if atm.welfare[plname] then
+ minetest.chat_send_player(name, "Remaining welfare: "..atm.welfare[plname])
+ end
+ return true
+ end
+})