From 1dcf3af5ab71dccad7b12f4240b62ee695a6dd9a Mon Sep 17 00:00:00 2001 From: gpcf Date: Sun, 22 Sep 2024 21:21:09 +0200 Subject: Add command to view finances --- init.lua | 2 +- interest.lua | 48 --------------------------------------------- welfare.lua | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 49 deletions(-) delete mode 100644 interest.lua create mode 100644 welfare.lua diff --git a/init.lua b/init.lua index 3ccba60..3157894 100644 --- a/init.lua +++ b/init.lua @@ -601,7 +601,7 @@ minetest.register_craft({ } }) -dofile(modpath .. "/interest.lua") +dofile(modpath .. "/welfare.lua") atm.readaccounts() minetest.register_on_shutdown(atm.saveaccounts) diff --git a/interest.lua b/interest.lua deleted file mode 100644 index ffcc0fc..0000000 --- a/interest.lua +++ /dev/null @@ -1,48 +0,0 @@ --- 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 = " ", - 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, -}) - 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 = " ", + 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 = "", + 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 +}) -- cgit v1.2.3