Skip to content

Commit

Permalink
atm support
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Oct 24, 2023
1 parent 3edb509 commit cb52421
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ globals = {
"minetest",
"technic",
"mail",
"beerchat"
"beerchat",
"atm"
}

read_globals = {
Expand Down
36 changes: 36 additions & 0 deletions handlers/atm.lua
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion mod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ mesecons_switch,
mesecons_lightstone,
mesecons_luacontroller,
digilines,
mooncontroller
mooncontroller,
atm
"""

0 comments on commit cb52421

Please sign in to comment.