mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-08-19 04:44:05 +02:00
atm system
This commit is contained in:
parent
5478d4364e
commit
ef1644d65f
62
bank.lua
62
bank.lua
@ -24,58 +24,8 @@ local S = core.get_translator(core.get_current_modname())
|
|||||||
local bankcraft = core.settings:get_bool("emeraldbank.bank_craft") or true
|
local bankcraft = core.settings:get_bool("emeraldbank.bank_craft") or true
|
||||||
|
|
||||||
|
|
||||||
function emeraldbank.add_emeralds(player, num)
|
|
||||||
if not player then return false end
|
|
||||||
local meta = player:get_meta()
|
|
||||||
local bankemeralds = meta:get_int("emeraldbank:emerald") -- if nil "get_int()" return 0 Magic!
|
|
||||||
local name = player:get_player_name()
|
|
||||||
if num then
|
|
||||||
meta:set_int("emeraldbank:emerald", bankemeralds+num)
|
|
||||||
mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", bankemeralds+num), color="yellow"})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function emeraldbank.keep(player, itemstack)
|
|
||||||
local itemname = itemstack:get_name()
|
|
||||||
local itemcount = itemstack:get_count()
|
|
||||||
local name = player:get_player_name()
|
|
||||||
if itemname == "mcl_core:emerald" then
|
|
||||||
itemstack:take_item(itemcount)
|
|
||||||
emeraldbank.add_emeralds(player, itemcount)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if itemname == "mcl_core:emeraldblock" then
|
|
||||||
itemstack:take_item(itemcount)
|
|
||||||
emeraldbank.add_emeralds(player, itemcount*9)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
mcl_title.set(player, "actionbar", {text=S("You need keep emeralds or emeraldblocks in your hand!"), color="dark_red"})
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function emeraldbank.take(player)
|
|
||||||
local meta = player:get_meta()
|
|
||||||
local bankemeralds = meta:get_int("emeraldbank:emerald")
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local pos = player:get_pos()
|
|
||||||
local num = 1
|
|
||||||
if bankemeralds >= 1 then
|
|
||||||
if bankemeralds >= 10 then
|
|
||||||
num = 10
|
|
||||||
end
|
|
||||||
emeraldbank.add_emeralds(player, -num)
|
|
||||||
core.add_item(pos, "mcl_core:emerald "..num)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
mcl_title.set(player, "actionbar", {text=S("Not enough Emeralds in your account"), color="dark_red"})
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- register bank node
|
-- register bank node
|
||||||
core.register_node("emeraldbank:bank", {
|
core.register_node(":atm:atm", {
|
||||||
description = S("Emerald Bank"),
|
description = S("Emerald Bank"),
|
||||||
_doc_items_longdesc = S("This block can keep your emeralds."),
|
_doc_items_longdesc = S("This block can keep your emeralds."),
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
@ -91,14 +41,16 @@ core.register_node("emeraldbank:bank", {
|
|||||||
_mcl_hardness = 1,
|
_mcl_hardness = 1,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
emeraldbank.keep(clicker, itemstack)
|
--emeraldbank.keep(clicker, itemstack)
|
||||||
|
atm.showform(clicker)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_punch = function(pos, node, puncher, pointed_thing)
|
-- on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
emeraldbank.take(puncher)
|
-- emeraldbank.take(puncher)
|
||||||
end,
|
-- end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_alias("emeraldbank:bank", "atm:atm")
|
||||||
|
|
||||||
|
|
||||||
if bankcraft then
|
if bankcraft then
|
||||||
|
50
commands.lua
50
commands.lua
@ -28,40 +28,14 @@ core.register_chatcommand("pay", {
|
|||||||
description = S("Pay money to other player. Transfer your emeralds to another bank account."),
|
description = S("Pay money to other player. Transfer your emeralds to another bank account."),
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local player1 = core.get_player_by_name(name)
|
local player1 = core.get_player_by_name(name)
|
||||||
local meta1 = player1:get_meta()
|
local name2, stringnum = param:match("([^ ]+) (.+)")
|
||||||
local bankemeralds1 = meta1:get_int("emeraldbank:emerald")
|
|
||||||
local playername2, stringnum = param:match("([^ ]+) (.+)")
|
|
||||||
local player2
|
local player2
|
||||||
local num = tonumber(stringnum)
|
local num = tonumber(stringnum)
|
||||||
if playername2 and num then
|
if name2 and num then
|
||||||
player2 = core.get_player_by_name(playername2)
|
player2 = core.get_player_by_name(name2)
|
||||||
end
|
end
|
||||||
if player2 and num then
|
if player2 and num then
|
||||||
if num > 0 then
|
return emeraldbank.transfer_emeralds(player1, player2, num)
|
||||||
if bankemeralds1 >= num then
|
|
||||||
core.chat_send_player(name, S("Pay Successfully! You have transferred @1 Emeralds." , num) )
|
|
||||||
core.chat_send_player(playername2, S("Pay Successfully! You've gotten @1 Emeralds.", num) )
|
|
||||||
if core.get_modpath("irc") and irc.saysec then
|
|
||||||
irc.saysec(name.." has transferred "..num.." emeralds to "..playername2)
|
|
||||||
end
|
|
||||||
if core.get_modpath("yl_matterbridge") and yl_matterbridge.send_to_sec then
|
|
||||||
yl_matterbridge.send_to_sec("", name.." has transferred "..num.." emeralds to "..playername2)
|
|
||||||
end
|
|
||||||
emeraldbank.add_emeralds(player1, -num)
|
|
||||||
emeraldbank.add_emeralds(player2, num)
|
|
||||||
core.sound_play("cash", {
|
|
||||||
to_player = playername2,
|
|
||||||
gain = 1.0,
|
|
||||||
fade = 0.0,
|
|
||||||
pitch = 1.0,
|
|
||||||
})
|
|
||||||
else
|
|
||||||
core.chat_send_player(name, S("Not enough Emeralds in your account"))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
core.chat_send_player(name, S("Invalid pay"))
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -86,3 +60,19 @@ core.register_chatcommand("emeralds", {
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- experimental upgrade command
|
||||||
|
core.register_chatcommand("upgrade", {
|
||||||
|
description = S("Admin Command! Upgrade a shop"),
|
||||||
|
privs = {server=true},
|
||||||
|
func = function(name, param)
|
||||||
|
local player = core.get_player_by_name(name)
|
||||||
|
local pos = player:get_pos()
|
||||||
|
local nodename = core.get_node(pos).name
|
||||||
|
if nodename == "emeraldbank:shop" or nodename == "emeraldbank:shop_empty" then
|
||||||
|
emeraldbank.upgrade_shop(pos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
})
|
||||||
|
@ -281,6 +281,8 @@ local function reset_vendor_settings(pos)
|
|||||||
return settings_default
|
return settings_default
|
||||||
end
|
end
|
||||||
|
|
||||||
|
emeraldbank.reset_vendor_settings = reset_vendor_settings
|
||||||
|
|
||||||
local function get_vendor_settings(pos)
|
local function get_vendor_settings(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local settings = minetest.deserialize(meta:get_string("settings"))
|
local settings = minetest.deserialize(meta:get_string("settings"))
|
||||||
@ -299,6 +301,8 @@ local function get_vendor_settings(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
emeraldbank.get_vendor_settings = get_vendor_settings
|
||||||
|
|
||||||
local function can_buy_from_vendor(pos, player)
|
local function can_buy_from_vendor(pos, player)
|
||||||
local settings = get_vendor_settings(pos)
|
local settings = get_vendor_settings(pos)
|
||||||
local banned_buyers = string.split((settings.banned_buyers or ""),",")
|
local banned_buyers = string.split((settings.banned_buyers or ""),",")
|
||||||
@ -1080,6 +1084,8 @@ local function refresh_vendor(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
emeraldbank.refresh_vendor = refresh_vendor
|
||||||
|
|
||||||
local function move_inv(frominv, toinv, filter)
|
local function move_inv(frominv, toinv, filter)
|
||||||
for i, v in ipairs(frominv:get_list("main") or {}) do
|
for i, v in ipairs(frominv:get_list("main") or {}) do
|
||||||
if v:get_name() == filter or not filter then
|
if v:get_name() == filter or not filter then
|
||||||
|
129
forms.lua
Normal file
129
forms.lua
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
|
||||||
|
-- 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
|
260
functions.lua
Normal file
260
functions.lua
Normal file
@ -0,0 +1,260 @@
|
|||||||
|
|
||||||
|
|
||||||
|
-- Copyright (C) 2021, 2022 Ale
|
||||||
|
|
||||||
|
-- This file is part of Emeraldbank Minetest Mod.
|
||||||
|
|
||||||
|
-- Emeraldbank is free software: you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU Affero General Public License as
|
||||||
|
-- published by the Free Software Foundation, either version 3 of the
|
||||||
|
-- License, or (at your option) any later version.
|
||||||
|
|
||||||
|
-- Emeraldbank is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
-- You should have received a copy of the GNU Affero General Public License
|
||||||
|
-- along with Emeraldbank. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local S = core.get_translator(core.get_current_modname())
|
||||||
|
|
||||||
|
function atm.ensure_init(name)
|
||||||
|
-- Ensure the atm account for the placer specified by name exists
|
||||||
|
atm.readaccounts()
|
||||||
|
if not atm.balance[name] then
|
||||||
|
atm.balance[name] = atm.startbalance
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- banking accounts storage
|
||||||
|
|
||||||
|
function atm.readaccounts ()
|
||||||
|
local b = atm.balance
|
||||||
|
local file = io.open(atm.pth, "r")
|
||||||
|
if file then
|
||||||
|
repeat
|
||||||
|
local balance = file:read("*n")
|
||||||
|
if balance == nil then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
local name = file:read("*l")
|
||||||
|
b[name:sub(2)] = balance
|
||||||
|
until file:read(0) == nil
|
||||||
|
io.close(file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function atm.saveaccounts()
|
||||||
|
if not atm.balance then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local data = {}
|
||||||
|
for k, v in pairs(atm.balance) do
|
||||||
|
table.insert(data, string.format("%d %s\n", v, k))
|
||||||
|
end
|
||||||
|
|
||||||
|
local output = io.open(atm.pth, "w")
|
||||||
|
output:write(table.concat(data))
|
||||||
|
io.close(output)
|
||||||
|
end
|
||||||
|
|
||||||
|
function emeraldbank.update_account()
|
||||||
|
atm.readaccounts()
|
||||||
|
for _, player in ipairs(core.get_connected_players()) do
|
||||||
|
if not player or player.is_fake_player then return end
|
||||||
|
local meta = player:get_meta()
|
||||||
|
local bankemeralds = meta:get_int("emeraldbank:emerald")
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if atm.balance[name] then
|
||||||
|
atm.balance[name] = math.floor(atm.balance[name] + bankemeralds)
|
||||||
|
else
|
||||||
|
atm.balance[name] = bankemeralds
|
||||||
|
end
|
||||||
|
meta:set_int("emeraldbank:emerald", 0)
|
||||||
|
-- backup
|
||||||
|
meta:set_int("emeraldbank:emerald_backup", bankemeralds)
|
||||||
|
end
|
||||||
|
atm.saveaccounts()
|
||||||
|
end
|
||||||
|
|
||||||
|
function emeraldbank.old_add_emeralds(player, num)
|
||||||
|
if not player then return false end
|
||||||
|
local meta = player:get_meta()
|
||||||
|
local bankemeralds = meta:get_int("emeraldbank:emerald") -- if nil "get_int()" return 0 Magic!
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if num then
|
||||||
|
meta:set_int("emeraldbank:emerald", bankemeralds+num)
|
||||||
|
mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", bankemeralds+num), color="yellow"})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function emeraldbank.add_emeralds(player, num)
|
||||||
|
atm.readaccounts()
|
||||||
|
if not player then return false end
|
||||||
|
local meta = player:get_meta()
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if num then
|
||||||
|
if atm.balance[name] then
|
||||||
|
atm.balance[name] = math.floor(atm.balance[name] + num)
|
||||||
|
else
|
||||||
|
atm.balance[name] = num
|
||||||
|
end
|
||||||
|
mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", atm.balance[name]), color="yellow"})
|
||||||
|
atm.saveaccounts()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function emeraldbank.transfer_emeralds(player1, player2, num)
|
||||||
|
atm.readaccounts()
|
||||||
|
local name = player1:get_player_name()
|
||||||
|
local name2 = player2:get_player_name()
|
||||||
|
local bankemeralds1 = atm.balance[name]
|
||||||
|
if num > 0 then
|
||||||
|
if bankemeralds1 and bankemeralds1 >= num then
|
||||||
|
core.chat_send_player(name, S("Pay Successfully! You have transferred @1 Emeralds." , num))
|
||||||
|
core.chat_send_player(name2, S("Pay Successfully! You've gotten @1 Emeralds.", num))
|
||||||
|
if core.get_modpath("irc") then
|
||||||
|
irc.say(name.." has transferred "..num.." emeralds to "..name2)
|
||||||
|
end
|
||||||
|
if core.get_modpath("yl_matterbridge") then
|
||||||
|
yl_matterbridge.send_to_bridge("", name.." has transferred "..num.." emeralds to "..name2)
|
||||||
|
end
|
||||||
|
emeraldbank.add_emeralds(player1, -num)
|
||||||
|
emeraldbank.add_emeralds(player2, num)
|
||||||
|
core.sound_play("cash", {
|
||||||
|
to_player = name2,
|
||||||
|
gain = 1.0,
|
||||||
|
fade = 0.0,
|
||||||
|
pitch = 1.0,
|
||||||
|
})
|
||||||
|
else
|
||||||
|
core.chat_send_player(name, S("Not enough Emeralds in your account"))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
core.chat_send_player(name, S("Invalid pay"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function emeraldbank.keep(player, itemstack)
|
||||||
|
local itemname = itemstack:get_name()
|
||||||
|
local itemcount = itemstack:get_count()
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if itemname == "mcl_core:emerald" then
|
||||||
|
itemstack:take_item(itemcount)
|
||||||
|
emeraldbank.add_emeralds(player, itemcount)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if itemname == "mcl_core:emeraldblock" then
|
||||||
|
itemstack:take_item(itemcount)
|
||||||
|
emeraldbank.add_emeralds(player, itemcount*9)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
mcl_title.set(player, "actionbar", {text=S("You need keep emeralds or emeraldblocks in your hand!"), color="dark_red"})
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function emeraldbank.take(player)
|
||||||
|
local meta = player:get_meta()
|
||||||
|
local bankemeralds = meta:get_int("emeraldbank:emerald")
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local pos = player:get_pos()
|
||||||
|
local num = 1
|
||||||
|
if bankemeralds >= 1 then
|
||||||
|
if bankemeralds >= 10 then
|
||||||
|
num = 10
|
||||||
|
end
|
||||||
|
emeraldbank.add_emeralds(player, -num)
|
||||||
|
core.add_item(pos, "mcl_core:emerald "..num)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
mcl_title.set(player, "actionbar", {text=S("Not enough Emeralds in your account"), color="dark_red"})
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- wire transfer data storage
|
||||||
|
|
||||||
|
function atm.read_transactions()
|
||||||
|
local file = io.open(atm.pth_wt, "r")
|
||||||
|
if file then
|
||||||
|
local data = file:read("*all")
|
||||||
|
atm.completed_transactions = minetest.deserialize(data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function atm.write_transactions()
|
||||||
|
if not atm.completed_transactions then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local file = io.open(atm.pth_wt, "w")
|
||||||
|
local data = minetest.serialize(atm.completed_transactions)
|
||||||
|
file:write(data)
|
||||||
|
io.close(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(atm.readaccounts)
|
||||||
|
minetest.register_on_joinplayer(emeraldbank.update_account)
|
||||||
|
|
||||||
|
|
||||||
|
function emeraldbank.upgrade_shop(pos)
|
||||||
|
local oldnode = core.get_node(pos)
|
||||||
|
local old_meta = core.get_meta(pos)
|
||||||
|
local old_meta_table = core.get_meta(pos):to_table()
|
||||||
|
local nodename = core.get_node(pos).name
|
||||||
|
-- set the new shop node
|
||||||
|
core.swap_node(pos, {name = "fancy_vend:player_vendor"})
|
||||||
|
|
||||||
|
-- setup the new shop node
|
||||||
|
-- Set variables for access later (for various checks, etc.)
|
||||||
|
local owner = old_meta:get_string("owner") or ""
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
local above_node = minetest.get_node(pos).name
|
||||||
|
|
||||||
|
-- If node above is air or the display node, and it is not protected, attempt to place the vendor. If vendor sucessfully places, place display node above, otherwise alert the user
|
||||||
|
if (minetest.registered_nodes[above_node].buildable_to or above_node == "fancy_vend:display_node") and not minetest.is_protected(pos, owner) then
|
||||||
|
if above_node ~= "fancy_vend:display_node" then
|
||||||
|
minetest.set_node(pos, minetest.registered_nodes["fancy_vend:display_node"])
|
||||||
|
end
|
||||||
|
-- Set owner
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("owner", owner or "")
|
||||||
|
|
||||||
|
-- Set default meta
|
||||||
|
meta:set_string("log", minetest.serialize({"Vendor placed by "..owner,}))
|
||||||
|
emeraldbank.reset_vendor_settings(pos)
|
||||||
|
emeraldbank.refresh_vendor(pos)
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(owner, S("Vendors require 2 nodes of space."))
|
||||||
|
end
|
||||||
|
|
||||||
|
if minetest.get_modpath("pipeworks") then
|
||||||
|
pipeworks.after_place(pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- copy old metadata in new node
|
||||||
|
core.get_meta(pos):from_table(old_meta_table)
|
||||||
|
-- new node
|
||||||
|
local node = core.get_node(pos)
|
||||||
|
local meta = core.get_meta(pos)
|
||||||
|
local count = meta:get_int("count")
|
||||||
|
local price = meta:get_int("price")
|
||||||
|
local shop_item = meta:get_string("shop_item")
|
||||||
|
local minv = meta:get_inventory()
|
||||||
|
local settings = emeraldbank.get_vendor_settings(pos)
|
||||||
|
settings.input_item = "mcl_core:emerald"
|
||||||
|
settings.input_item_qty = price
|
||||||
|
settings.output_item = shop_item
|
||||||
|
settings.output_item_qty = count
|
||||||
|
|
||||||
|
emeraldbank.refresh_vendor(pos)
|
||||||
|
end
|
@ -18,6 +18,7 @@
|
|||||||
-- along with Emeraldbank. If not, see <https://www.gnu.org/licenses/>.
|
-- along with Emeraldbank. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
-- adapted from the income.lua file from the currency mod.
|
||||||
|
|
||||||
local S = core.get_translator(core.get_current_modname())
|
local S = core.get_translator(core.get_current_modname())
|
||||||
|
|
||||||
@ -27,15 +28,16 @@ local income_period = tonumber(core.settings:get("emeraldbank.income_period")) o
|
|||||||
|
|
||||||
local timer = 0
|
local timer = 0
|
||||||
|
|
||||||
core.register_globalstep(function(dtime)
|
function emeraldbank.income(dtime)
|
||||||
timer = timer + dtime;
|
timer = timer + dtime;
|
||||||
if timer >= income_period then
|
if timer >= income_period then
|
||||||
timer = 0
|
timer = 0
|
||||||
for _, player in ipairs(core.get_connected_players()) do
|
for _, player in ipairs(core.get_connected_players()) do
|
||||||
if not player or player.is_fake_player then return end
|
if not player or player.is_fake_player then return end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
core.chat_send_player(name, S("You have earned @1 emeralds in your bank account!", income_count))
|
|
||||||
emeraldbank.add_emeralds(player, income_count)
|
emeraldbank.add_emeralds(player, income_count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
minetest.register_globalstep(emeraldbank.income)
|
||||||
|
15
init.lua
15
init.lua
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
-- Copyright (C) 2021, 2022 Ale
|
-- Copyright (C) 2021, 2023 Ale
|
||||||
|
|
||||||
-- This file is part of Emeraldbank Minetest Mod.
|
-- This file is part of Emeraldbank Minetest Mod.
|
||||||
|
|
||||||
@ -24,11 +24,24 @@ local modpath = core.get_modpath(core.get_current_modname())
|
|||||||
emeraldbank = {}
|
emeraldbank = {}
|
||||||
|
|
||||||
local income_enabled = core.settings:get_bool("emeraldbank.income_enabled", true)
|
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
|
if income_enabled then
|
||||||
dofile(modpath .. "/income.lua")
|
dofile(modpath .. "/income.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
atm = {
|
||||||
|
balance = {},
|
||||||
|
startbalance = start_balance,
|
||||||
|
pending_transfers = {},
|
||||||
|
completed_transactions = {},
|
||||||
|
pth = minetest.get_worldpath().."/atm_accounts",
|
||||||
|
pth_wt = minetest.get_worldpath().."/atm_wt_transactions"
|
||||||
|
}
|
||||||
|
|
||||||
|
dofile(modpath .. "/functions.lua")
|
||||||
|
dofile(modpath .. "/forms.lua")
|
||||||
|
dofile(modpath .. "/receive_fields.lua")
|
||||||
dofile(modpath .. "/bank.lua")
|
dofile(modpath .. "/bank.lua")
|
||||||
dofile(modpath .. "/shop.lua")
|
dofile(modpath .. "/shop.lua")
|
||||||
dofile(modpath .. "/fancyshop.lua")
|
dofile(modpath .. "/fancyshop.lua")
|
||||||
|
@ -4,18 +4,13 @@
|
|||||||
### bank.lua ###
|
### bank.lua ###
|
||||||
|
|
||||||
Emerald Bank=Banco de Esmeraldas
|
Emerald Bank=Banco de Esmeraldas
|
||||||
Emeralds in Bank: @1=Esmeraldas en el Banco: @1
|
|
||||||
This block can keep your emeralds.=Este bloque puede guardar tus esmeraldas.
|
This block can keep your emeralds.=Este bloque puede guardar tus esmeraldas.
|
||||||
You need keep emeralds or emeraldblocks in your hand!=Necesitas sostener esmeraldas o bloques de esmeralda.
|
|
||||||
Not enough Emeralds in your account=No tienes suficientes esmeraldas en tu cuenta.
|
|
||||||
|
|
||||||
### commands.lua ###
|
### commands.lua ###
|
||||||
|
|
||||||
Admin Command! Add player emeralds in bank account, also can use negative numbers=Comando Admin. Añade esmeraldas a una cuenta, tambien admite numeros negativos.
|
Admin Command! Add player emeralds in bank account, also can use negative numbers=Comando Admin. Añade esmeraldas a una cuenta, tambien admite numeros negativos.
|
||||||
|
|
||||||
Invalid pay=Pago invalido, no puedes pagar un numero negativo.
|
Admin Command! Upgrade a shop=Comando de Admin para actualizar tiendas
|
||||||
Pay Successfully! You have transferred @1 Emeralds.=¡Pago completado! Has transferido @1 Esmeraldas.
|
|
||||||
Pay Successfully! You've gotten @1 Emeralds.=¡Pago completado! Te acaban de pagar @1 Esmeraldas.
|
|
||||||
|
|
||||||
Pay money to other player. Transfer your emeralds to another bank account.=Paga dinero a otro jugador. Transfiere esmeraldas a su cuenta del Banco.
|
Pay money to other player. Transfer your emeralds to another bank account.=Paga dinero a otro jugador. Transfiere esmeraldas a su cuenta del Banco.
|
||||||
|
|
||||||
@ -61,9 +56,52 @@ Vendor will not sell worn tools.=La tienda no vende herramientas gastadas
|
|||||||
for:=para:
|
for:=para:
|
||||||
lots.=cantidad
|
lots.=cantidad
|
||||||
|
|
||||||
### income.lua ###
|
### forms.lua ###
|
||||||
|
|
||||||
You have earned @1 emeralds in your bank account!=¡Has ganado @1 esmeraldas en tu cuenta del Banco!
|
from=de
|
||||||
|
< Transfer money=< Tranferencias
|
||||||
|
Amount:=Cantidad:
|
||||||
|
Clear transactions=Limpiar transacciones
|
||||||
|
Complete the payment=Completar el pago
|
||||||
|
Confirm transfer=Confirmar transferencia
|
||||||
|
Deposit:=Ingresar
|
||||||
|
Description:=Descripción:
|
||||||
|
Quit=Salir
|
||||||
|
Recepient:=Destinatario:
|
||||||
|
TRANSACTION SUMMARY:=SUMARIO DE LA TRANSACCIÓN:
|
||||||
|
Transaction list=Lista de transacciones
|
||||||
|
Transactions >=Registro >
|
||||||
|
Wire Transfer=Tranferencias
|
||||||
|
Wire Transfer System=Sistema de transferencias
|
||||||
|
Withdraw:=Retirar
|
||||||
|
Your account balance: $@1=Tu dinero en la cuenta: @1$
|
||||||
|
no transactions registered=no hay registro de transacciones
|
||||||
|
|
||||||
|
### functions.lua ###
|
||||||
|
|
||||||
|
Emeralds in Bank: @1=Esmeraldas en el Banco: @1
|
||||||
|
Invalid pay=Pago invalido, no puedes pagar un numero negativo.
|
||||||
|
Pay Successfully! You have transferred @1 Emeralds.=¡Pago completado! Has transferido @1 Esmeraldas.
|
||||||
|
Pay Successfully! You've gotten @1 Emeralds.=¡Pago completado! Te acaban de pagar @1 Esmeraldas.
|
||||||
|
Vendors require 2 nodes of space.=La tienda ocupa 2 bloques de alto
|
||||||
|
You need keep emeralds or emeraldblocks in your hand!=Necesitas sostener esmeraldas o bloques de esmeralda.
|
||||||
|
|
||||||
|
Not enough Emeralds in your account=No tienes suficientes esmeraldas en tu cuenta.
|
||||||
|
|
||||||
|
### receive_fields.lua ###
|
||||||
|
|
||||||
|
@1, thank you for choosing the Wire Transfer system=Gracias por elegir el sistema de transferencias de EmeraldBank
|
||||||
|
Invalid amount <@1> : must be an integer number, aborting=Cantidad invalida <@1> debe ser un numero entero, cancelado
|
||||||
|
Not enough money in your account=No tienes suficiente dinero en tu cuenta del banco
|
||||||
|
Not enough money in your inventory=No tienes suficiente dinero en tu inventario
|
||||||
|
Not enough room in your inventory=No tienes espacio en tu inventario
|
||||||
|
Payment of @1 to @2 completed=Pago de @1 a @2 completado con exito
|
||||||
|
|
||||||
|
The recepient <@1> is not registered in the banking system, aborting=El destinatario <@1> no está registrado en el sistema bancario, cancelado
|
||||||
|
|
||||||
|
Your account does not have enough funds to complete this transfer, aborting=Tu cuenta no tiene fondos suficientes para completar la transferencia, cancelado
|
||||||
|
|
||||||
|
Your transaction history has been cleared=El historial de transacciones ha sido limpiado
|
||||||
|
|
||||||
### shop.lua ###
|
### shop.lua ###
|
||||||
|
|
||||||
|
@ -4,23 +4,13 @@
|
|||||||
### bank.lua ###
|
### bank.lua ###
|
||||||
|
|
||||||
Emerald Bank=
|
Emerald Bank=
|
||||||
Emeralds in Bank: @1=
|
|
||||||
This block can keep your emeralds.=
|
This block can keep your emeralds.=
|
||||||
You need keep emeralds or emeraldblocks in your hand!=
|
|
||||||
|
|
||||||
### bank.lua ###
|
|
||||||
### commands.lua ###
|
|
||||||
### shop.lua ###
|
|
||||||
|
|
||||||
Not enough Emeralds in your account=
|
|
||||||
|
|
||||||
### commands.lua ###
|
### commands.lua ###
|
||||||
|
|
||||||
Admin Command! Add player emeralds in bank account, also can use negative numbers=
|
Admin Command! Add player emeralds in bank account, also can use negative numbers=
|
||||||
|
|
||||||
Invalid pay=
|
Admin Command! Upgrade a shop=
|
||||||
Pay Successfully! You have transferred @1 Emeralds.=
|
|
||||||
Pay Successfully! You've gotten @1 Emeralds.=
|
|
||||||
|
|
||||||
Pay money to other player. Transfer your emeralds to another bank account.=
|
Pay money to other player. Transfer your emeralds to another bank account.=
|
||||||
|
|
||||||
@ -66,9 +56,56 @@ Vendor will not sell worn tools.=
|
|||||||
for:=
|
for:=
|
||||||
lots.=
|
lots.=
|
||||||
|
|
||||||
### income.lua ###
|
### forms.lua ###
|
||||||
|
|
||||||
You have earned @1 emeralds in your bank account!=
|
from =
|
||||||
|
< Transfer money=
|
||||||
|
Amount:=
|
||||||
|
Clear transactions=
|
||||||
|
Complete the payment=
|
||||||
|
Confirm transfer=
|
||||||
|
Deposit:=
|
||||||
|
Description:=
|
||||||
|
Quit=
|
||||||
|
Recepient:=
|
||||||
|
TRANSACTION SUMMARY:=
|
||||||
|
Transaction list=
|
||||||
|
Transactions >=
|
||||||
|
Wire Transfer=
|
||||||
|
Wire Transfer System=
|
||||||
|
Wire Transfer Terminal=
|
||||||
|
Withdraw:=
|
||||||
|
Your account balance: $@1=
|
||||||
|
no transactions registered=
|
||||||
|
|
||||||
|
### functions.lua ###
|
||||||
|
|
||||||
|
Emeralds in Bank: @1=
|
||||||
|
Invalid pay=
|
||||||
|
Pay Successfully! You have transferred @1 Emeralds.=
|
||||||
|
Pay Successfully! You've gotten @1 Emeralds.=
|
||||||
|
Vendors require 2 nodes of space.=
|
||||||
|
You need keep emeralds or emeraldblocks in your hand!=
|
||||||
|
|
||||||
|
### functions.lua ###
|
||||||
|
### shop.lua ###
|
||||||
|
|
||||||
|
Not enough Emeralds in your account=
|
||||||
|
|
||||||
|
### receive_fields.lua ###
|
||||||
|
|
||||||
|
@1, thank you for choosing the Wire Transfer system=
|
||||||
|
Invalid amount <@1> : must be an integer number, aborting=
|
||||||
|
Not enough money in your account=
|
||||||
|
Not enough money in your inventory=
|
||||||
|
Not enough room in your inventory=
|
||||||
|
Payment of @1 to @2 completed=
|
||||||
|
|
||||||
|
The recepient <@1> is not registered in the banking system, aborting=
|
||||||
|
|
||||||
|
Your account does not have enough funds to complete this transfer, aborting=
|
||||||
|
|
||||||
|
Your transaction history has been cleared=
|
||||||
|
|
||||||
### shop.lua ###
|
### shop.lua ###
|
||||||
|
|
||||||
|
183
receive_fields.lua
Normal file
183
receive_fields.lua
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
|
||||||
|
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)
|
@ -1,14 +1,11 @@
|
|||||||
|
|
||||||
[Bank and Shops]
|
[Bank]
|
||||||
|
|
||||||
# If true bank can be crafted
|
# If true bank can be crafted
|
||||||
emeraldbank.bank_craft (bank craft) bool true
|
emeraldbank.bank_craft (bank craft) bool true
|
||||||
|
|
||||||
# If true shop can be crafted
|
# Number of emeralds on start
|
||||||
emeraldbank.shop_craft (shop craft) bool true
|
emeraldbank.start_balance (emeralds on start) int 30
|
||||||
|
|
||||||
# If true old shop can be crafted
|
|
||||||
emeraldbank.old_shop_craft (old shop craft) bool false
|
|
||||||
|
|
||||||
# If true, bank will give emeralds to players for gamed time
|
# If true, bank will give emeralds to players for gamed time
|
||||||
emeraldbank.income_enabled (Is income enabled?) bool true
|
emeraldbank.income_enabled (Is income enabled?) bool true
|
||||||
@ -20,7 +17,13 @@ emeraldbank.income_count (number of emeralds) int 1
|
|||||||
emeraldbank.income_period (time between income) int 1800
|
emeraldbank.income_period (time between income) int 1800
|
||||||
|
|
||||||
|
|
||||||
[Fancy Shops]
|
[Shops]
|
||||||
|
|
||||||
|
# If true shop can be crafted
|
||||||
|
emeraldbank.shop_craft (shop craft) bool true
|
||||||
|
|
||||||
|
# If true old shop can be crafted
|
||||||
|
emeraldbank.old_shop_craft (old shop craft) bool false
|
||||||
|
|
||||||
# The node to copy as the display node
|
# The node to copy as the display node
|
||||||
fancy_vend.display_node (Display Node) string mcl_core:glass
|
fancy_vend.display_node (Display Node) string mcl_core:glass
|
||||||
|
4
shop.lua
4
shop.lua
@ -260,6 +260,8 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
|
|||||||
local prefix_len = string.len(formspec_prefix)
|
local prefix_len = string.len(formspec_prefix)
|
||||||
if formname:sub(1,prefix_len) == formspec_prefix then
|
if formname:sub(1,prefix_len) == formspec_prefix then
|
||||||
|
|
||||||
|
atm.readaccounts()
|
||||||
|
|
||||||
local pos_string = formname:sub(prefix_len+1)
|
local pos_string = formname:sub(prefix_len+1)
|
||||||
local pos = core.string_to_pos(pos_string)
|
local pos = core.string_to_pos(pos_string)
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
@ -273,7 +275,7 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
|
|||||||
local shop_item = meta:get_string("shop_item")
|
local shop_item = meta:get_string("shop_item")
|
||||||
local minv = meta:get_inventory()
|
local minv = meta:get_inventory()
|
||||||
local pinv = sender:get_inventory()
|
local pinv = sender:get_inventory()
|
||||||
local bankemeralds = playermeta:get_int("emeraldbank:emerald")
|
local bankemeralds = atm.balance[name]
|
||||||
|
|
||||||
-- set or reset timer
|
-- set or reset timer
|
||||||
core.get_node_timer(pos):start(shop_timer)
|
core.get_node_timer(pos):start(shop_timer)
|
||||||
|
Loading…
Reference in New Issue
Block a user