mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-12-22 22:22:25 +01:00
move functions to function file
This commit is contained in:
parent
f4393dc1ea
commit
ae0ef1162e
2
bank.lua
2
bank.lua
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
-- Copyright (C) 2021, 2022 Ale
|
||||
-- Copyright (C) 2021, 2023 Ale
|
||||
|
||||
-- This file is part of Emeraldbank Minetest Mod.
|
||||
|
||||
|
125
forms.lua
125
forms.lua
@ -2,128 +2,3 @@
|
||||
-- atm interface
|
||||
|
||||
local S = core.get_translator(core.get_current_modname())
|
||||
|
||||
function atm.showform (player)
|
||||
atm.ensure_init(player:get_player_name())
|
||||
local formspec =
|
||||
"size[9,8.75]"..
|
||||
"label[0.5,0;"..S("Your account balance: $@1", atm.balance[player:get_player_name()]).."]" ..
|
||||
"label[0.5,0.75;"..S("Deposit:").."]" ..
|
||||
-- "label[0.5,0.75;1s]" ..
|
||||
-- "label[1.5,0.75;5s]" ..
|
||||
-- "label[2.5,0.75;10s]" ..
|
||||
-- "label[3.5,0.75;50s]" ..
|
||||
-- "label[4.5,0.75;100s]" ..
|
||||
"label[7.5,0.75;"..S("Withdraw:").."]" ..
|
||||
-- "label[6.5,0.75;1s]" ..
|
||||
-- "label[7.5,0.75;5s]" ..
|
||||
-- "label[8.5,0.75;10s]" ..
|
||||
-- "label[9.5,0.75;50s]" ..
|
||||
-- "label[10.5,0.75;100s]" ..
|
||||
"item_image_button[0.5,1.25;1,1;".. "mcl_core:emerald" ..";i1;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[1.5,1.25;1,1;".. "currency:minegeld_5" ..";i5;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[2.5,1.25;1,1;".. "currency:minegeld_10" ..";i10;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[3.5,1.25;1,1;".. "currency:minegeld_50" ..";i50;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[4.5,1.25;1,1;".. "currency:minegeld_100" ..";i100;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
"item_image_button[7.5,1.25;1,1;".. "mcl_core:emerald" ..";i-1;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[7.5,1.25;1,1;".. "currency:minegeld_5" ..";i-5;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[8.5,1.25;1,1;".. "currency:minegeld_10" ..";i-10;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[9.5,1.25;1,1;".. "currency:minegeld_50" ..";i-50;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[10.5,1.25;1,1;".. "currency:minegeld_100" ..";i-100;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
"item_image_button[0.5,2.25;1,1;".. "mcl_core:emerald" ..";t10;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[1.5,2.25;1,1;".. "currency:minegeld_5" ..";t50;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[2.5,2.25;1,1;".. "currency:minegeld_10" ..";t100;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[3.5,2.25;1,1;".. "currency:minegeld_50" ..";t500;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[4.5,2.25;1,1;".. "currency:minegeld_100" ..";t1000;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
"item_image_button[7.5,2.25;1,1;".. "mcl_core:emerald" ..";t-10;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[7.5,2.25;1,1;".. "currency:minegeld_5" ..";t-50;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[8.5,2.25;1,1;".. "currency:minegeld_10" ..";t-100;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[9.5,2.25;1,1;".. "currency:minegeld_50" ..";t-500;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[10.5,2.25;1,1;".. "currency:minegeld_100" ..";t-1000;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
"item_image_button[0.5,3.25;1,1;".. "mcl_core:emerald" ..";c100;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[1.5,3.25;1,1;".. "currency:minegeld_5" ..";c500;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[2.5,3.25;1,1;".. "currency:minegeld_10" ..";c1000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[3.5,3.25;1,1;".. "currency:minegeld_50" ..";c5000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[4.5,3.25;1,1;".. "currency:minegeld_100" ..";c10000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
"item_image_button[7.5,3.25;1,1;".. "mcl_core:emerald" ..";c-100;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[7.5,3.25;1,1;".. "currency:minegeld_5" ..";c-500;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[8.5,3.25;1,1;".. "currency:minegeld_10" ..";c-1000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[9.5,3.25;1,1;".. "currency:minegeld_50" ..";c-5000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[10.5,3.25;1,1;".. "currency:minegeld_100" ..";c-10000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "button_exit[5.5,3;1,2;Quit;Quit]" ..
|
||||
"button[3.5,3;2,1;wt;"..S("Wire Transfer").."]"..
|
||||
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
mcl_formspec.get_itemslot_bg(0,7.74,9,1)..
|
||||
"listring[current_player;main]"
|
||||
|
||||
minetest.after((0.1), function(gui)
|
||||
return minetest.show_formspec(player:get_player_name(), "atm.form", gui)
|
||||
end, formspec)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- wire transfer interface
|
||||
|
||||
function atm.showform_wt (player)
|
||||
atm.ensure_init(player:get_player_name())
|
||||
local formspec =
|
||||
"size[8,6]"..
|
||||
"button[5.75,0;2,1;transactions;"..S("Transactions >").."]" ..
|
||||
"label[2.5,0;"..S("Wire Transfer System").."]" ..
|
||||
"label[2,0.5;"..S("Your account balance: $@1", atm.balance[player:get_player_name()]).. "]" ..
|
||||
"field[0.5,1.5;5,1;dstn;"..S("Recepient:")..";]"..
|
||||
"field[6,1.5;2,1;amnt;"..S("Amount:")..";]"..
|
||||
"field[0.5,3;7.5,1;desc;"..S("Description:")..";]"..
|
||||
"button_exit[0.2,5;1,1;Quit;"..S("Quit").."]" ..
|
||||
"button[4.7,5;3,1;pay;"..S("Complete the payment").."]"
|
||||
minetest.after((0.1), function(gui)
|
||||
return minetest.show_formspec(player:get_player_name(), "atm.form.wt", gui)
|
||||
end, formspec)
|
||||
end
|
||||
|
||||
function atm.showform_wtconf (player, dstn, amnt, desc)
|
||||
atm.ensure_init(player:get_player_name())
|
||||
local formspec =
|
||||
"size[8,6]"..
|
||||
"label[2.5,0;"..S("Wire Transfer System").."]" ..
|
||||
"label[2,0.5;"..S("Your account balance: $@1", atm.balance[player:get_player_name()]).. "]" ..
|
||||
"label[2.5,1;"..S("TRANSACTION SUMMARY:").."]"..
|
||||
"label[0.5,1.5;"..S("Recepient:").." "..dstn.."]"..
|
||||
"label[0.5,2;"..S("Amount:").." " .. amnt .. "]"..
|
||||
"label[0.5,2.5;"..S("Description:").." " .. desc .. "]"..
|
||||
"button_exit[0.2,5;1,1;Quit;"..S("Quit").."]" ..
|
||||
"button[4.7,5;3,1;cnfrm;"..S("Confirm transfer").."]"
|
||||
minetest.after((0.1), function(gui)
|
||||
return minetest.show_formspec(player:get_player_name(), "atm.form.wtc", gui)
|
||||
end, formspec)
|
||||
end
|
||||
|
||||
function atm.showform_wtlist (player, tlist)
|
||||
atm.ensure_init(player:get_player_name())
|
||||
|
||||
local textlist = ''
|
||||
|
||||
if not tlist then
|
||||
textlist = S("no transactions registered").."\n"
|
||||
else
|
||||
for _, entry in ipairs(tlist) do
|
||||
textlist = textlist .. entry.date .. " $" .. entry.sum .. " " .. S("from") .. " " .. entry.from .. ": " .. entry.desc .. "\n"
|
||||
end
|
||||
end
|
||||
|
||||
local formspec =
|
||||
"size[8,6]"..
|
||||
"button[5.75,0;2,1;transfer;"..S("< Transfer money").."]" ..
|
||||
"label[2.5,0;"..S("Wire Transfer System").."]" ..
|
||||
"label[2,0.5;"..S("Your account balance: $@1", atm.balance[player:get_player_name()]).. "]" ..
|
||||
"textarea[0.5,1.25;7.5,4;hst;"..S("Transaction list")..";" .. textlist .. "]" ..
|
||||
"button_exit[0.2,5;1,1;Quit;"..S("Quit").."]" ..
|
||||
"button[4.7,5;3,1;clr;"..S("Clear transactions").."]"
|
||||
minetest.after((0.1), function(gui)
|
||||
return minetest.show_formspec(player:get_player_name(), "atm.form.wtl", gui)
|
||||
end, formspec)
|
||||
end
|
||||
|
310
functions.lua
310
functions.lua
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
-- Copyright (C) 2021, 2022 Ale
|
||||
-- Copyright (C) 2021, 2023 Ale
|
||||
|
||||
-- This file is part of Emeraldbank Minetest Mod.
|
||||
|
||||
@ -258,3 +258,311 @@ function emeraldbank.upgrade_shop(pos)
|
||||
|
||||
emeraldbank.refresh_vendor(pos)
|
||||
end
|
||||
|
||||
|
||||
function atm.showform (player)
|
||||
atm.ensure_init(player:get_player_name())
|
||||
local formspec =
|
||||
"size[9,8.75]"..
|
||||
"label[0.5,0;"..S("Your account balance: $@1", atm.balance[player:get_player_name()]).."]" ..
|
||||
"label[0.5,0.75;"..S("Deposit:").."]" ..
|
||||
-- "label[0.5,0.75;1s]" ..
|
||||
-- "label[1.5,0.75;5s]" ..
|
||||
-- "label[2.5,0.75;10s]" ..
|
||||
-- "label[3.5,0.75;50s]" ..
|
||||
-- "label[4.5,0.75;100s]" ..
|
||||
"label[7.5,0.75;"..S("Withdraw:").."]" ..
|
||||
-- "label[6.5,0.75;1s]" ..
|
||||
-- "label[7.5,0.75;5s]" ..
|
||||
-- "label[8.5,0.75;10s]" ..
|
||||
-- "label[9.5,0.75;50s]" ..
|
||||
-- "label[10.5,0.75;100s]" ..
|
||||
"item_image_button[0.5,1.25;1,1;".. "mcl_core:emerald" ..";i1;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[1.5,1.25;1,1;".. "currency:minegeld_5" ..";i5;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[2.5,1.25;1,1;".. "currency:minegeld_10" ..";i10;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[3.5,1.25;1,1;".. "currency:minegeld_50" ..";i50;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[4.5,1.25;1,1;".. "currency:minegeld_100" ..";i100;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
"item_image_button[7.5,1.25;1,1;".. "mcl_core:emerald" ..";i-1;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[7.5,1.25;1,1;".. "currency:minegeld_5" ..";i-5;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[8.5,1.25;1,1;".. "currency:minegeld_10" ..";i-10;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[9.5,1.25;1,1;".. "currency:minegeld_50" ..";i-50;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
-- "item_image_button[10.5,1.25;1,1;".. "currency:minegeld_100" ..";i-100;\n\n\b\b\b\b\b" .. "x1" .."]" ..
|
||||
"item_image_button[0.5,2.25;1,1;".. "mcl_core:emerald" ..";t10;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[1.5,2.25;1,1;".. "currency:minegeld_5" ..";t50;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[2.5,2.25;1,1;".. "currency:minegeld_10" ..";t100;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[3.5,2.25;1,1;".. "currency:minegeld_50" ..";t500;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[4.5,2.25;1,1;".. "currency:minegeld_100" ..";t1000;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
"item_image_button[7.5,2.25;1,1;".. "mcl_core:emerald" ..";t-10;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[7.5,2.25;1,1;".. "currency:minegeld_5" ..";t-50;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[8.5,2.25;1,1;".. "currency:minegeld_10" ..";t-100;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[9.5,2.25;1,1;".. "currency:minegeld_50" ..";t-500;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
-- "item_image_button[10.5,2.25;1,1;".. "currency:minegeld_100" ..";t-1000;\n\n\b\b\b\b" .. "x10" .."]" ..
|
||||
"item_image_button[0.5,3.25;1,1;".. "mcl_core:emerald" ..";c100;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[1.5,3.25;1,1;".. "currency:minegeld_5" ..";c500;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[2.5,3.25;1,1;".. "currency:minegeld_10" ..";c1000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[3.5,3.25;1,1;".. "currency:minegeld_50" ..";c5000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[4.5,3.25;1,1;".. "currency:minegeld_100" ..";c10000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
"item_image_button[7.5,3.25;1,1;".. "mcl_core:emerald" ..";c-100;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[7.5,3.25;1,1;".. "currency:minegeld_5" ..";c-500;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[8.5,3.25;1,1;".. "currency:minegeld_10" ..";c-1000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[9.5,3.25;1,1;".. "currency:minegeld_50" ..";c-5000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "item_image_button[10.5,3.25;1,1;".. "currency:minegeld_100" ..";c-10000;\n\n\b\b\b" .. "x100" .."]" ..
|
||||
-- "button_exit[5.5,3;1,2;Quit;Quit]" ..
|
||||
"button[3.5,3;2,1;wt;"..S("Wire Transfer").."]"..
|
||||
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
mcl_formspec.get_itemslot_bg(0,7.74,9,1)..
|
||||
"listring[current_player;main]"
|
||||
|
||||
minetest.after((0.1), function(gui)
|
||||
return minetest.show_formspec(player:get_player_name(), "atm.form", gui)
|
||||
end, formspec)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- wire transfer interface
|
||||
|
||||
function atm.showform_wt (player)
|
||||
atm.ensure_init(player:get_player_name())
|
||||
local formspec =
|
||||
"size[8,6]"..
|
||||
"button[5.75,0;2,1;transactions;"..S("Transactions >").."]" ..
|
||||
"label[2.5,0;"..S("Wire Transfer System").."]" ..
|
||||
"label[2,0.5;"..S("Your account balance: $@1", atm.balance[player:get_player_name()]).. "]" ..
|
||||
"field[0.5,1.5;5,1;dstn;"..S("Recepient:")..";]"..
|
||||
"field[6,1.5;2,1;amnt;"..S("Amount:")..";]"..
|
||||
"field[0.5,3;7.5,1;desc;"..S("Description:")..";]"..
|
||||
"button_exit[0.2,5;1,1;Quit;"..S("Quit").."]" ..
|
||||
"button[4.7,5;3,1;pay;"..S("Complete the payment").."]"
|
||||
minetest.after((0.1), function(gui)
|
||||
return minetest.show_formspec(player:get_player_name(), "atm.form.wt", gui)
|
||||
end, formspec)
|
||||
end
|
||||
|
||||
function atm.showform_wtconf (player, dstn, amnt, desc)
|
||||
atm.ensure_init(player:get_player_name())
|
||||
local formspec =
|
||||
"size[8,6]"..
|
||||
"label[2.5,0;"..S("Wire Transfer System").."]" ..
|
||||
"label[2,0.5;"..S("Your account balance: $@1", atm.balance[player:get_player_name()]).. "]" ..
|
||||
"label[2.5,1;"..S("TRANSACTION SUMMARY:").."]"..
|
||||
"label[0.5,1.5;"..S("Recepient:").." "..dstn.."]"..
|
||||
"label[0.5,2;"..S("Amount:").." " .. amnt .. "]"..
|
||||
"label[0.5,2.5;"..S("Description:").." " .. desc .. "]"..
|
||||
"button_exit[0.2,5;1,1;Quit;"..S("Quit").."]" ..
|
||||
"button[4.7,5;3,1;cnfrm;"..S("Confirm transfer").."]"
|
||||
minetest.after((0.1), function(gui)
|
||||
return minetest.show_formspec(player:get_player_name(), "atm.form.wtc", gui)
|
||||
end, formspec)
|
||||
end
|
||||
|
||||
function atm.showform_wtlist (player, tlist)
|
||||
atm.ensure_init(player:get_player_name())
|
||||
|
||||
local textlist = ''
|
||||
|
||||
if not tlist then
|
||||
textlist = S("no transactions registered").."\n"
|
||||
else
|
||||
for _, entry in ipairs(tlist) do
|
||||
textlist = textlist .. entry.date .. " $" .. entry.sum .. " " .. S("from") .. " " .. entry.from .. ": " .. entry.desc .. "\n"
|
||||
end
|
||||
end
|
||||
|
||||
local formspec =
|
||||
"size[8,6]"..
|
||||
"button[5.75,0;2,1;transfer;"..S("< Transfer money").."]" ..
|
||||
"label[2.5,0;"..S("Wire Transfer System").."]" ..
|
||||
"label[2,0.5;"..S("Your account balance: $@1", atm.balance[player:get_player_name()]).. "]" ..
|
||||
"textarea[0.5,1.25;7.5,4;hst;"..S("Transaction list")..";" .. textlist .. "]" ..
|
||||
"button_exit[0.2,5;1,1;Quit;"..S("Quit").."]" ..
|
||||
"button[4.7,5;3,1;clr;"..S("Clear transactions").."]"
|
||||
minetest.after((0.1), function(gui)
|
||||
return minetest.show_formspec(player:get_player_name(), "atm.form.wtl", gui)
|
||||
end, formspec)
|
||||
end
|
||||
|
||||
|
||||
function emeraldbank.bank_receive_fields(player, form, pressed)
|
||||
|
||||
-- ATMs
|
||||
if form == "atm.form" then
|
||||
local n = player:get_player_name()
|
||||
local transaction = { amount = 0, denomination = 0, count = 0 }
|
||||
local pinv=player:get_inventory()
|
||||
|
||||
-- single note transactions
|
||||
for _,i in pairs({1, 5, 10, 50, 100, -1, -5, -10, -50, -100}) do
|
||||
if pressed["i"..i] then
|
||||
transaction.amount = i
|
||||
transaction.denomination = '_' .. math.abs(i)
|
||||
if transaction.denomination == '_1' then
|
||||
transaction.denomination = ''
|
||||
end
|
||||
transaction.count = ' ' .. 1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- 10x banknote transactions
|
||||
for _,t in pairs({10, 50, 100, 500, 1000, -10, -50, -100, -500, -1000}) do
|
||||
if pressed["t"..t] then
|
||||
transaction.amount = t
|
||||
transaction.denomination = '_' .. math.abs(t/10)
|
||||
if transaction.denomination == '_1' then
|
||||
transaction.denomination = ''
|
||||
end
|
||||
transaction.count = ' ' .. 10
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- 100x banknote transactions
|
||||
for _,c in pairs({100, 500, 1000, 5000, 10000, -100, -500, -1000, -5000, -10000}) do
|
||||
if pressed["c"..c] then
|
||||
transaction.amount = c
|
||||
transaction.denomination = '_' .. math.abs(c/100)
|
||||
if transaction.denomination == '_1' then
|
||||
transaction.denomination = ''
|
||||
end
|
||||
transaction.count = ' ' .. 100
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- someone hit exchange button
|
||||
if pressed.wt then
|
||||
atm.showform_wt(player)
|
||||
end
|
||||
|
||||
if (atm.balance[n] + transaction.amount) < 0 then
|
||||
minetest.chat_send_player(n, S("Not enough money in your account"))
|
||||
transaction.amount = 0
|
||||
end
|
||||
|
||||
local item = "mcl_core:emerald" .. transaction.denomination .. transaction.count
|
||||
|
||||
if transaction.amount < 0 then
|
||||
if pinv:room_for_item("main", item) then
|
||||
pinv:add_item("main", item)
|
||||
atm.balance[n] = atm.balance[n] + transaction.amount
|
||||
else
|
||||
minetest.chat_send_player(n, S("Not enough room in your inventory"))
|
||||
end
|
||||
|
||||
elseif transaction.amount > 0 then
|
||||
if pinv:contains_item("main", item) then
|
||||
pinv:remove_item("main", item)
|
||||
atm.balance[n] = atm.balance[n] + transaction.amount
|
||||
else
|
||||
minetest.chat_send_player(n, S("Not enough money in your inventory"))
|
||||
end
|
||||
end
|
||||
|
||||
atm.saveaccounts()
|
||||
|
||||
if not pressed.Quit and not pressed.quit then
|
||||
atm.showform(player)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
function emeraldbank.wt_receive_fields(player, form, pressed)
|
||||
|
||||
-- Wire transfer terminals
|
||||
if form == "atm.form.wt" or form == "atm.form.wtc" or form == "atm.form.wtl" then
|
||||
|
||||
local n = player:get_player_name()
|
||||
|
||||
if not pressed.Quit and not pressed.quit then
|
||||
if form == "atm.form.wt" and pressed.transactions then
|
||||
-- transaction list (can be edited in the form, but than means nothing)
|
||||
atm.read_transactions()
|
||||
atm.showform_wtlist(player, atm.completed_transactions[n])
|
||||
elseif form == "atm.form.wtl" and pressed.transfer then
|
||||
atm.showform_wt(player)
|
||||
elseif form == "atm.form.wtl" and pressed.clr then
|
||||
-- clear all transactions in the player's list
|
||||
atm.read_transactions()
|
||||
atm.completed_transactions[n] = nil
|
||||
atm.write_transactions()
|
||||
minetest.chat_send_player(n, S("Your transaction history has been cleared"))
|
||||
atm.showform_wtlist(player, atm.completed_transactions[n])
|
||||
elseif form == "atm.form.wt" and pressed.pay then
|
||||
|
||||
-- perform the checks of validity for wire transfer order
|
||||
-- if passed, store the data in a temporary table and show confirmation window
|
||||
if not atm.balance[pressed.dstn] then
|
||||
minetest.chat_send_player(n, S("The recepient <@1> is not registered in the banking system, aborting", pressed.dstn))
|
||||
atm.showform_wt(player)
|
||||
elseif not string.match(pressed.amnt, '^[0-9]+$') then
|
||||
minetest.chat_send_player(n, S("Invalid amount <@1> : must be an integer number, aborting", pressed.amnt))
|
||||
atm.showform_wt(player)
|
||||
elseif atm.balance[n] < tonumber(pressed.amnt) then
|
||||
minetest.chat_send_player(n, S("Your account does not have enough funds to complete this transfer, aborting"))
|
||||
atm.showform_wt(player)
|
||||
else
|
||||
atm.pending_transfers[n] = {to = pressed.dstn, sum = tonumber(pressed.amnt), desc = pressed.desc}
|
||||
atm.showform_wtconf(player, pressed.dstn, pressed.amnt, pressed.desc)
|
||||
end
|
||||
|
||||
elseif form == "atm.form.wtc" then
|
||||
-- transaction processing
|
||||
atm.read_transactions()
|
||||
local t = atm.pending_transfers[n]
|
||||
if not t then
|
||||
return
|
||||
end
|
||||
if not atm.completed_transactions[t.to] then
|
||||
atm.completed_transactions[t.to] = {}
|
||||
end
|
||||
|
||||
if atm.balance[n] < t.sum then
|
||||
-- you can never be too paranoid about the funds availaible
|
||||
minetest.chat_send_player(n, S("Your account does not have enough funds to complete this transfer, aborting"))
|
||||
if not t.extern then
|
||||
atm.showform_wt(player)
|
||||
else
|
||||
minetest.close_formspec(n, "atm.form.wtc")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(atm.completed_transactions[t.to], {date=os.date("%Y-%m-%d"), from=n, sum=t.sum, desc=t.desc})
|
||||
atm.balance[n] = atm.balance[n] - t.sum
|
||||
atm.balance[t.to] = atm.balance[t.to] + t.sum
|
||||
atm.write_transactions()
|
||||
atm.saveaccounts()
|
||||
minetest.chat_send_player(n, S("Payment of @1 to @2 completed", t.sum, t.to))
|
||||
minetest.chat_send_player(n, S("@1, thank you for choosing the Wire Transfer system", n))
|
||||
if t.callback then -- run callbacks from mods
|
||||
t.callback(t)
|
||||
end
|
||||
if t.extern == true then -- Transfer was initiated by mod
|
||||
atm.pending_transfers[n] = nil
|
||||
minetest.close_formspec(n, "atm.form.wtc")
|
||||
return
|
||||
end
|
||||
atm.pending_transfers[n] = nil
|
||||
atm.showform_wt(player)
|
||||
end
|
||||
else
|
||||
-- clear the pending transaction of the player, just in case
|
||||
if atm.pending_transfers[n] then
|
||||
atm.pending_transfers[n] = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
minetest.register_on_player_receive_fields(emeraldbank.bank_receive_fields)
|
||||
|
||||
minetest.register_on_player_receive_fields(emeraldbank.wt_receive_fields)
|
||||
|
10
init.lua
10
init.lua
@ -26,10 +26,6 @@ emeraldbank = {}
|
||||
local income_enabled = core.settings:get_bool("emeraldbank.income_enabled", true)
|
||||
local start_balance = tonumber(core.settings:get("emeraldbank.start_balance")) or 30
|
||||
|
||||
if income_enabled then
|
||||
dofile(modpath .. "/income.lua")
|
||||
end
|
||||
|
||||
atm = {
|
||||
balance = {},
|
||||
startbalance = start_balance,
|
||||
@ -40,9 +36,11 @@ atm = {
|
||||
}
|
||||
|
||||
dofile(modpath .. "/functions.lua")
|
||||
dofile(modpath .. "/forms.lua")
|
||||
dofile(modpath .. "/receive_fields.lua")
|
||||
dofile(modpath .. "/bank.lua")
|
||||
dofile(modpath .. "/shop.lua")
|
||||
dofile(modpath .. "/fancyshop.lua")
|
||||
dofile(modpath .. "/commands.lua")
|
||||
|
||||
if income_enabled then
|
||||
dofile(modpath .. "/income.lua")
|
||||
end
|
||||
|
@ -1,183 +1,2 @@
|
||||
|
||||
local S = core.get_translator(core.get_current_modname())
|
||||
|
||||
function emeraldbank.bank_receive_fields(player, form, pressed)
|
||||
|
||||
-- ATMs
|
||||
if form == "atm.form" then
|
||||
local n = player:get_player_name()
|
||||
local transaction = { amount = 0, denomination = 0, count = 0 }
|
||||
local pinv=player:get_inventory()
|
||||
|
||||
-- single note transactions
|
||||
for _,i in pairs({1, 5, 10, 50, 100, -1, -5, -10, -50, -100}) do
|
||||
if pressed["i"..i] then
|
||||
transaction.amount = i
|
||||
transaction.denomination = '_' .. math.abs(i)
|
||||
if transaction.denomination == '_1' then
|
||||
transaction.denomination = ''
|
||||
end
|
||||
transaction.count = ' ' .. 1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- 10x banknote transactions
|
||||
for _,t in pairs({10, 50, 100, 500, 1000, -10, -50, -100, -500, -1000}) do
|
||||
if pressed["t"..t] then
|
||||
transaction.amount = t
|
||||
transaction.denomination = '_' .. math.abs(t/10)
|
||||
if transaction.denomination == '_1' then
|
||||
transaction.denomination = ''
|
||||
end
|
||||
transaction.count = ' ' .. 10
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- 100x banknote transactions
|
||||
for _,c in pairs({100, 500, 1000, 5000, 10000, -100, -500, -1000, -5000, -10000}) do
|
||||
if pressed["c"..c] then
|
||||
transaction.amount = c
|
||||
transaction.denomination = '_' .. math.abs(c/100)
|
||||
if transaction.denomination == '_1' then
|
||||
transaction.denomination = ''
|
||||
end
|
||||
transaction.count = ' ' .. 100
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- someone hit exchange button
|
||||
if pressed.wt then
|
||||
atm.showform_wt(player)
|
||||
end
|
||||
|
||||
if (atm.balance[n] + transaction.amount) < 0 then
|
||||
minetest.chat_send_player(n, S("Not enough money in your account"))
|
||||
transaction.amount = 0
|
||||
end
|
||||
|
||||
local item = "mcl_core:emerald" .. transaction.denomination .. transaction.count
|
||||
|
||||
if transaction.amount < 0 then
|
||||
if pinv:room_for_item("main", item) then
|
||||
pinv:add_item("main", item)
|
||||
atm.balance[n] = atm.balance[n] + transaction.amount
|
||||
else
|
||||
minetest.chat_send_player(n, S("Not enough room in your inventory"))
|
||||
end
|
||||
|
||||
elseif transaction.amount > 0 then
|
||||
if pinv:contains_item("main", item) then
|
||||
pinv:remove_item("main", item)
|
||||
atm.balance[n] = atm.balance[n] + transaction.amount
|
||||
else
|
||||
minetest.chat_send_player(n, S("Not enough money in your inventory"))
|
||||
end
|
||||
end
|
||||
|
||||
atm.saveaccounts()
|
||||
|
||||
if not pressed.Quit and not pressed.quit then
|
||||
atm.showform(player)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
function emeraldbank.wt_receive_fields(player, form, pressed)
|
||||
|
||||
-- Wire transfer terminals
|
||||
if form == "atm.form.wt" or form == "atm.form.wtc" or form == "atm.form.wtl" then
|
||||
|
||||
local n = player:get_player_name()
|
||||
|
||||
if not pressed.Quit and not pressed.quit then
|
||||
if form == "atm.form.wt" and pressed.transactions then
|
||||
-- transaction list (can be edited in the form, but than means nothing)
|
||||
atm.read_transactions()
|
||||
atm.showform_wtlist(player, atm.completed_transactions[n])
|
||||
elseif form == "atm.form.wtl" and pressed.transfer then
|
||||
atm.showform_wt(player)
|
||||
elseif form == "atm.form.wtl" and pressed.clr then
|
||||
-- clear all transactions in the player's list
|
||||
atm.read_transactions()
|
||||
atm.completed_transactions[n] = nil
|
||||
atm.write_transactions()
|
||||
minetest.chat_send_player(n, S("Your transaction history has been cleared"))
|
||||
atm.showform_wtlist(player, atm.completed_transactions[n])
|
||||
elseif form == "atm.form.wt" and pressed.pay then
|
||||
|
||||
-- perform the checks of validity for wire transfer order
|
||||
-- if passed, store the data in a temporary table and show confirmation window
|
||||
if not atm.balance[pressed.dstn] then
|
||||
minetest.chat_send_player(n, S("The recepient <@1> is not registered in the banking system, aborting", pressed.dstn))
|
||||
atm.showform_wt(player)
|
||||
elseif not string.match(pressed.amnt, '^[0-9]+$') then
|
||||
minetest.chat_send_player(n, S("Invalid amount <@1> : must be an integer number, aborting", pressed.amnt))
|
||||
atm.showform_wt(player)
|
||||
elseif atm.balance[n] < tonumber(pressed.amnt) then
|
||||
minetest.chat_send_player(n, S("Your account does not have enough funds to complete this transfer, aborting"))
|
||||
atm.showform_wt(player)
|
||||
else
|
||||
atm.pending_transfers[n] = {to = pressed.dstn, sum = tonumber(pressed.amnt), desc = pressed.desc}
|
||||
atm.showform_wtconf(player, pressed.dstn, pressed.amnt, pressed.desc)
|
||||
end
|
||||
|
||||
elseif form == "atm.form.wtc" then
|
||||
-- transaction processing
|
||||
atm.read_transactions()
|
||||
local t = atm.pending_transfers[n]
|
||||
if not t then
|
||||
return
|
||||
end
|
||||
if not atm.completed_transactions[t.to] then
|
||||
atm.completed_transactions[t.to] = {}
|
||||
end
|
||||
|
||||
if atm.balance[n] < t.sum then
|
||||
-- you can never be too paranoid about the funds availaible
|
||||
minetest.chat_send_player(n, S("Your account does not have enough funds to complete this transfer, aborting"))
|
||||
if not t.extern then
|
||||
atm.showform_wt(player)
|
||||
else
|
||||
minetest.close_formspec(n, "atm.form.wtc")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(atm.completed_transactions[t.to], {date=os.date("%Y-%m-%d"), from=n, sum=t.sum, desc=t.desc})
|
||||
atm.balance[n] = atm.balance[n] - t.sum
|
||||
atm.balance[t.to] = atm.balance[t.to] + t.sum
|
||||
atm.write_transactions()
|
||||
atm.saveaccounts()
|
||||
minetest.chat_send_player(n, S("Payment of @1 to @2 completed", t.sum, t.to))
|
||||
minetest.chat_send_player(n, S("@1, thank you for choosing the Wire Transfer system", n))
|
||||
if t.callback then -- run callbacks from mods
|
||||
t.callback(t)
|
||||
end
|
||||
if t.extern == true then -- Transfer was initiated by mod
|
||||
atm.pending_transfers[n] = nil
|
||||
minetest.close_formspec(n, "atm.form.wtc")
|
||||
return
|
||||
end
|
||||
atm.pending_transfers[n] = nil
|
||||
atm.showform_wt(player)
|
||||
end
|
||||
else
|
||||
-- clear the pending transaction of the player, just in case
|
||||
if atm.pending_transfers[n] then
|
||||
atm.pending_transfers[n] = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
minetest.register_on_player_receive_fields(emeraldbank.bank_receive_fields)
|
||||
|
||||
minetest.register_on_player_receive_fields(emeraldbank.wt_receive_fields)
|
||||
|
Loading…
Reference in New Issue
Block a user