Browse Source

Merge branch 'nalc' into upgrade

tags/nalc-1.0
sys4 1 year ago
parent
commit
81517a5b3d
2 changed files with 72 additions and 4 deletions
  1. +70
    -4
      atm.lua
  2. +2
    -0
      init.lua

+ 70
- 4
atm.lua View File

@@ -2,7 +2,7 @@
local exchange, formlib = ...

local atm_form = "global_exchange:atm_form"
local atm_pos = {}

local unique = (function(unique_num)
return function()
@@ -11,6 +11,35 @@ local unique = (function(unique_num)
end
end)(0)

local coins_convert = {
["minercantile:copper_coin"]=1, ["minercantile:silver_coin"]=9, ["minercantile:gold_coin"]=81,
["maptools:copper_coin"]=1, ["maptools:silver_coin"]=9, ["maptools:gold_coin"]=81,
["bitchange:mineninth"]=729, ["bitchange:minecoin"]=6561, ["bitchange:minecoinblock"]=59049
}

local function deposit_fs(fs, p_name)
local balance = exchange:get_balance(p_name)
local spos = atm_pos[p_name].x..","..atm_pos[p_name].y..","..atm_pos[p_name].z

fs:size(8,9)
if not balance then
fs:label(0.5,0.5, "You don't have an account.")
else
fs:label(0.5,0.5, "Balance: " .. balance)
fs:label(1,1,"Put your coins to credit your account")
fs:list(3.5,2.5, 1,1, "nodemeta:"..spos, "main")
fs:list(0,4, 8,4, "current_player", "main")
--fs("list[nodemeta:"..spos..";main;3.5,2.5;1,1;]"..
-- "list[current_player;main;0,4.85;8,1;]"..
-- "list[current_player;main;0,6.08;8,3;8]" ..
fs("listring[nodemeta:"..spos..";main]"..
"listring[current_player;main]"
)
end

fs:button(1,2, 2,1, "logout", "Log Out")
end

local function info_fs(fs, p_name)
local balance = exchange:get_balance(p_name)
@@ -93,8 +122,9 @@ end

local function main_menu_fs(fs, p_name)
fs:size(6,2)
fs:button(0.50,0.125, 2.5,1, "info", "Account Info")
fs:button(3.00,0.125, 2.5,1, "wire", "Wire Monies")
fs:button(0,0.125, 2,1, "deposit", "Cash Deposit")
fs:button(2,0.125, 2,1, "info", "Account Info")
fs:button(4,0.125, 2,1, "wire", "Wire Monies")
fs:button(0.50,1.125, 5.0,1, "transaction_log", "Transaction Log")
end

@@ -133,6 +163,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
show_atm_form(send_fs, p_name, fields.recipient, fields.amount)
elseif fields.transaction_log then
show_atm_form(log_fs, p_name)
elseif fields.deposit then
show_atm_form(deposit_fs, p_name)
end

return true
@@ -178,6 +210,7 @@ minetest.register_node("global_exchange:atm_bottom", {
{ 0.375, 1.375, -0.3125, 0.500, 1.500, -0.25},
},
},
groups = {cracky=2, atm = 1},
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local pos
@@ -216,8 +249,41 @@ minetest.register_node("global_exchange:atm_bottom", {
minetest.remove_node(pos2)
end
end,
groups = {cracky=2, atm = 1},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "ATM")
local inv = meta:get_inventory()
inv:set_size("main", 1)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local itname = stack:get_name()
if coins_convert[itname] ~= nil then
return stack:get_count()
end
return 0
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local itname = stack:get_name()
if coins_convert[itname] ~= nil then
local p_name = player:get_player_name()
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local nb = stack:get_count()
local amount = coins_convert[itname] * nb
local succ, msg = exchange:give_credits(p_name, amount, "Cash deposit (+"..amount..")")
if succ then
inv:set_stack(listname, index, nil)
minetest.log("action", p_name.." put "..nb.." "..stack:get_name() .. " to ATM at " .. minetest.pos_to_string(pos))
show_atm_form(deposit_fs, p_name)
--minetest.show_formspec(p_name, atm_form, deposit_fs(p_name))
else
minetest.log("error", p_name.." want to put "..nb.." "..stack:get_name().." to ATM at ".. minetest.pos_to_string(pos).." but: "..msg)
end
end
end,
on_rightclick = function(pos, _, clicker)
local p_name = clicker:get_player_name()
atm_pos[p_name] = pos
minetest.sound_play("atm_beep", {pos = pos, gain = 0.3, max_hear_distance = 5})
show_atm_form(main_menu_fs, clicker:get_player_name())
end,


+ 2
- 0
init.lua View File

@@ -41,3 +41,5 @@ minetest.register_chatcommand("setbalance", {
assert(loadfile(modpath .. "atm.lua"))(exchange, formlib)
assert(loadfile(modpath .. "exchange_machine.lua"))(exchange, formlib)
assert(loadfile(modpath .. "digital_mailbox.lua"))(exchange, formlib)

minetest.log("action", "[global_exchange] loaded.")

Loading…
Cancel
Save