added new machines
This commit is contained in:
parent
ceb168de55
commit
8603834f56
35 changed files with 2223 additions and 1204 deletions
126
pin_terminal.lua
126
pin_terminal.lua
|
|
@ -1,133 +1,41 @@
|
|||
--[[
|
||||
PIN Terminal Node
|
||||
-----------------
|
||||
This file defines the PIN Terminal, which allows players to
|
||||
set their initial PIN, change it, and request a new card.
|
||||
It provides an immersive replacement for the /set_pin command.
|
||||
--]]
|
||||
-- pin_terminal.lua (Angepasst mit Fehler-Nachricht für besetztes System)
|
||||
|
||||
-- Shows the form for a new player to set their first PIN.
|
||||
local function show_pin_create_form(player, error_msg)
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = "size[8,5]" ..
|
||||
"label[1,0.5;"..S("Welcome! Please set your personal 4-digit PIN.").."]" ..
|
||||
"pwdfield[2,2;4,1;new_pin;"..S("New PIN:").."]" ..
|
||||
"button_exit[3,4;2,1;confirm_new_pin;"..S("Confirm").."]"
|
||||
|
||||
if error_msg then
|
||||
formspec = formspec .. "label[1,3;`"..minetest.formspec_escape(S(error_msg)).."`]" .. "style[label;color=red]"
|
||||
end
|
||||
|
||||
minetest.show_formspec(player_name, "bank_accounts:pin_create", formspec)
|
||||
local player_name = player:get_player_name(); local formspec = "size[8,5]" .. "label[1,0.5;"..S("Welcome! Please set your personal 4-digit PIN.").."]" .. "pwdfield[2,2;4,1;new_pin;"..S("New PIN:").."]" .. "button_exit[3,4;2,1;confirm_new_pin;"..S("Confirm").."]"; if error_msg then formspec = formspec .. "label[1,3;`"..minetest.formspec_escape(S(error_msg)).."`]" .. "style[label;color=red]" end; minetest.show_formspec(player_name, "bank_accounts:pin_create", formspec)
|
||||
end
|
||||
|
||||
-- Shows the main menu for an existing player at the PIN terminal.
|
||||
local function show_pin_options_form(player)
|
||||
local player_name = player:get_player_name()
|
||||
minetest.show_formspec(player_name, "bank_accounts:pin_options",
|
||||
"size[8,6]" ..
|
||||
"label[1,0.5;"..S("PIN & Card Service").."]" ..
|
||||
"label[1,1.5;"..S("What would you like to do?").."]" ..
|
||||
"button_exit[2,3;4,1;change_pin;"..S("Change PIN").."]" ..
|
||||
"button_exit[2,4;4,1;new_card;"..S("Request New Card").."]")
|
||||
end
|
||||
|
||||
-- Shows the form to change an existing PIN.
|
||||
-- Can display an error message if something goes wrong.
|
||||
local function show_pin_options_form(player) local player_name = player:get_player_name(); minetest.show_formspec(player_name, "bank_accounts:pin_options", "size[8,6]" .. "label[1,0.5;"..S("PIN & Card Service").."]" .. "label[1,1.5;"..S("What would you like to do?").."]" .. "button_exit[2,3;4,1;change_pin;"..S("Change PIN").."]" .. "button_exit[2,4;4,1;new_card;"..S("Request New Card").."]") end
|
||||
local function show_pin_change_form(player, error_msg)
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = "size[8,7]" ..
|
||||
"label[1,0.5;"..S("Change Your PIN").."]" ..
|
||||
"pwdfield[2,2;4,1;old_pin;"..S("Old PIN:").."]" ..
|
||||
"pwdfield[2,3;4,1;new_pin1;"..S("New PIN:").."]" ..
|
||||
"pwdfield[2,4;4,1;new_pin2;"..S("Confirm New PIN:").."]" ..
|
||||
"button_exit[3,6;2,1;confirm_change;"..S("Confirm").."]"
|
||||
|
||||
if error_msg then
|
||||
formspec = formspec .. "label[1,5;`"..minetest.formspec_escape(S(error_msg)).."`]" .. "style[label;color=red]"
|
||||
end
|
||||
|
||||
minetest.show_formspec(player_name, "bank_accounts:pin_change", formspec)
|
||||
local player_name = player:get_player_name(); local formspec = "size[8,7]" .. "label[1,0.5;"..S("Change Your PIN").."]" .. "pwdfield[2,2;4,1;old_pin;"..S("Old PIN:").."]" .. "pwdfield[2,3;4,1;new_pin1;"..S("New PIN:").."]" .. "pwdfield[2,4;4,1;new_pin2;"..S("Confirm New PIN:").."]" .. "button_exit[3,6;2,1;confirm_change;"..S("Confirm").."]"; if error_msg then formspec = formspec .. "label[1,5;`"..minetest.formspec_escape(S(error_msg)).."`]" .. "style[label;color=red]" end; minetest.show_formspec(player_name, "bank_accounts:pin_change", formspec)
|
||||
end
|
||||
|
||||
-- Node definition for the PIN Terminal.
|
||||
minetest.register_node("bank_accounts:pin_terminal", {
|
||||
description = S("PIN Terminal"),
|
||||
drawtype = "mesh",
|
||||
mesh = "card_swipe.obj",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
tiles = {"pin_terminal.png"},
|
||||
groups = {cracky=3, crumbly=3, oddly_breakable_by_hand=2},
|
||||
|
||||
-- Called when a player right-clicks the node.
|
||||
-- It does not require a card to operate.
|
||||
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
||||
local player_name = player:get_player_name()
|
||||
-- Check if the player is new (has the default PIN).
|
||||
if bank_accounts.get_pin(player_name) == "0000" then
|
||||
show_pin_create_form(player)
|
||||
else
|
||||
show_pin_options_form(player)
|
||||
end
|
||||
end,
|
||||
description = S("PIN Terminal"), drawtype = "mesh", mesh = "card_swipe.obj", paramtype = "light", paramtype2 = "facedir", tiles = {"pin_terminal.png"}, groups = {cracky=3, crumbly=3, oddly_breakable_by_hand=2},
|
||||
on_rightclick = function(pos, node, player, itemstack, pointed_thing) local player_name = player:get_player_name(); if bank_accounts.get_pin(player_name) == "0000" then show_pin_create_form(player) else show_pin_options_form(player) end end,
|
||||
})
|
||||
|
||||
-- Handles formspec submissions for all PIN Terminal forms.
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- Only process forms belonging to this node.
|
||||
if not formname:find("bank_accounts:pin_") then
|
||||
return
|
||||
end
|
||||
|
||||
if not formname:find("bank_accounts:pin_") then return end
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
-- Logic for initial PIN creation.
|
||||
if formname == "bank_accounts:pin_create" then
|
||||
if fields.confirm_new_pin then
|
||||
local new_pin = fields.new_pin
|
||||
if new_pin and new_pin:match("^[0-9][0-9][0-9][0-9]$") and new_pin ~= "0000" then
|
||||
bank_accounts.set_pin(player_name, new_pin)
|
||||
local inv = player:get_inventory()
|
||||
if not inv:contains_item("main", "bank_accounts:atm_card") then
|
||||
inv:add_item("main", "bank_accounts:atm_card")
|
||||
end
|
||||
if not bank_accounts.set_pin(player_name, new_pin) then minetest.chat_send_player(player_name, S("[Bank] System is busy, please try again in a moment.")); show_pin_create_form(player, S("[Bank] System is busy, please try again in a moment.")); return end
|
||||
local inv = player:get_inventory(); if not inv:contains_item("main", "bank_accounts:atm_card") then inv:add_item("main", "bank_accounts:atm_card") end
|
||||
minetest.chat_send_player(player_name, S("[PIN Terminal] Your PIN has been set! Your new bank card is in your inventory."))
|
||||
else
|
||||
-- Re-show form with an error message.
|
||||
show_pin_create_form(player, "[PIN Terminal] Your PIN must be 4 digits and not '0000'.")
|
||||
end
|
||||
else show_pin_create_form(player, "[PIN Terminal] Your PIN must be 4 digits and not '0000'.") end
|
||||
end
|
||||
|
||||
-- Logic for the options menu.
|
||||
elseif formname == "bank_accounts:pin_options" then
|
||||
if fields.change_pin then
|
||||
show_pin_change_form(player)
|
||||
elseif fields.new_card then
|
||||
local inv = player:get_inventory()
|
||||
if inv:contains_item("main", "bank_accounts:atm_card") then
|
||||
minetest.chat_send_player(player_name, S("[PIN Terminal] You already have a bank card."))
|
||||
else
|
||||
inv:add_item("main", "bank_accounts:atm_card")
|
||||
minetest.chat_send_player(player_name, S("[PIN Terminal] A new bank card has been added to your inventory."))
|
||||
end
|
||||
end
|
||||
|
||||
-- Logic for the PIN change form.
|
||||
if fields.change_pin then show_pin_change_form(player)
|
||||
elseif fields.new_card then local inv = player:get_inventory(); if inv:contains_item("main", "bank_accounts:atm_card") then minetest.chat_send_player(player_name, S("[PIN Terminal] You already have a bank card.")) else inv:add_item("main", "bank_accounts:atm_card"); minetest.chat_send_player(player_name, S("[PIN Terminal] A new bank card has been added to your inventory.")) end end
|
||||
elseif formname == "bank_accounts:pin_change" then
|
||||
if fields.confirm_change then
|
||||
local old_pin = fields.old_pin
|
||||
local new_pin1 = fields.new_pin1
|
||||
local new_pin2 = fields.new_pin2
|
||||
|
||||
if old_pin ~= bank_accounts.get_pin(player_name) then
|
||||
show_pin_change_form(player, "[PIN Terminal] Your old PIN is incorrect.")
|
||||
elseif not new_pin1 or not new_pin1:match("^[0-9][0-9][0-9][0-9]$") or new_pin1 == "0000" then
|
||||
show_pin_change_form(player, "[PIN Terminal] Your PIN must be 4 digits and not '0000'.")
|
||||
elseif new_pin1 ~= new_pin2 then
|
||||
show_pin_change_form(player, "[PIN Terminal] The new PINs do not match.")
|
||||
local old_pin = fields.old_pin; local new_pin1 = fields.new_pin1; local new_pin2 = fields.new_pin2
|
||||
if old_pin ~= bank_accounts.get_pin(player_name) then show_pin_change_form(player, "[PIN Terminal] Your old PIN is incorrect.")
|
||||
elseif not new_pin1 or not new_pin1:match("^[0-9][0-9][0-9][0-9]$") or new_pin1 == "0000" then show_pin_change_form(player, "[PIN Terminal] Your PIN must be 4 digits and not '0000'.")
|
||||
elseif new_pin1 ~= new_pin2 then show_pin_change_form(player, "[PIN Terminal] The new PINs do not match.")
|
||||
else
|
||||
bank_accounts.set_pin(player_name, new_pin1)
|
||||
if not bank_accounts.set_pin(player_name, new_pin1) then minetest.chat_send_player(player_name, S("[Bank] System is busy, please try again in a moment.")); show_pin_change_form(player, S("[Bank] System is busy, please try again in a moment.")); return end
|
||||
minetest.chat_send_player(player_name, S("[PIN Terminal] Your PIN has been successfully changed."))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue