From cb52421dfb436796f1a7eb6ba67b35caddc7df3b Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Tue, 24 Oct 2023 11:18:44 +0200 Subject: [PATCH] atm support --- .luacheckrc | 3 ++- handlers/atm.lua | 36 ++++++++++++++++++++++++++++++++++++ init.lua | 4 ++++ mod.conf | 3 ++- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 handlers/atm.lua diff --git a/.luacheckrc b/.luacheckrc index a07aebe..55c56a2 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -3,7 +3,8 @@ globals = { "minetest", "technic", "mail", - "beerchat" + "beerchat", + "atm" } read_globals = { diff --git a/handlers/atm.lua b/handlers/atm.lua new file mode 100644 index 0000000..f27d700 --- /dev/null +++ b/handlers/atm.lua @@ -0,0 +1,36 @@ + +mtui.register_on_command("atm_transfer", function(data) + if not data.amount then + return { success = false, errmsg = "no amount specified" } + end + + if data.amount <= 0 then + return { success = false, errmsg = "invalid amount" } + end + + if not minetest.player_exists(data.source) then + return { success = false, errmsg = "source player does not exist" } + end + + if not minetest.player_exists(data.target) then + return { success = false, errmsg = "target player does not exist" } + end + atm.read_account(data.source) + atm.read_account(data.target) + + if atm.balance[data.source] < data.amount then + return { success = false, errmsg = "insufficient amount" } + end + + atm.balance[data.source] = atm.balance[data.source] - data.amount + atm.balance[data.target] = atm.balance[data.target] + data.amount + + atm.save_account(data.source) + atm.save_account(data.target) + + return { + success = true, + source_balance = atm.balance[data.source], + target_balance = atm.balance[data.target] + } +end) \ No newline at end of file diff --git a/init.lua b/init.lua index d117fa8..fb5e2af 100644 --- a/init.lua +++ b/init.lua @@ -50,6 +50,10 @@ if not minetest.get_modpath("xp_redo") then dofile(MP.."/player_stats.lua") end +if minetest.get_modpath("atm") then + dofile(MP.."/atm.lua") +end + if minetest.get_modpath("mail") then dofile(MP.."/mail.lua") end diff --git a/mod.conf b/mod.conf index 68dfa5e..e1799dd 100644 --- a/mod.conf +++ b/mod.conf @@ -11,5 +11,6 @@ mesecons_switch, mesecons_lightstone, mesecons_luacontroller, digilines, -mooncontroller +mooncontroller, +atm """ \ No newline at end of file