added new machines
This commit is contained in:
parent
ceb168de55
commit
8603834f56
35 changed files with 2223 additions and 1204 deletions
|
|
@ -1,13 +1,7 @@
|
|||
--[[
|
||||
Card Swipe Node
|
||||
---------------
|
||||
This file defines the Card Swipe node, which allows players
|
||||
to set up shops and sell items via card payments.
|
||||
--]]
|
||||
-- card_swipe.lua (Besitzer kann jetzt Items wieder entnehmen)
|
||||
|
||||
-- Uses the global 'pos_info' variable for consistency.
|
||||
pos_info = {}
|
||||
|
||||
-- Node definition for the Card Swipe.
|
||||
minetest.register_node("bank_accounts:card_swipe", {
|
||||
description = S("Card Swipe"),
|
||||
drawtype = "mesh",
|
||||
|
|
@ -19,12 +13,10 @@ minetest.register_node("bank_accounts:card_swipe", {
|
|||
selection_box = { type = "fixed", fixed = {{-.3,-.5,-.3,.4,-.2,.3}} },
|
||||
collision_box = { type = "fixed", fixed = {{-.3,-.5,-.3,.4,-.2,.3}} },
|
||||
|
||||
-- Creates the item inventory when the node is placed.
|
||||
on_construct = function(pos)
|
||||
minetest.get_meta(pos):get_inventory():set_size("items", 8)
|
||||
end,
|
||||
|
||||
-- Sets the owner of the node after it has been placed.
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = placer:get_player_name()
|
||||
|
|
@ -32,7 +24,6 @@ minetest.register_node("bank_accounts:card_swipe", {
|
|||
meta:set_string("owner", owner)
|
||||
end,
|
||||
|
||||
-- Ensures only the owner can dig the node, and only if it's empty.
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() == meta:get_string("owner") then
|
||||
|
|
@ -41,15 +32,13 @@ minetest.register_node("bank_accounts:card_swipe", {
|
|||
return false
|
||||
end,
|
||||
|
||||
-- Called when a player right-clicks the node.
|
||||
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
||||
pos_info = pos -- Set global position.
|
||||
pos_info = pos
|
||||
local meta = minetest.get_meta(pos)
|
||||
local player_name = player:get_player_name()
|
||||
local owner = meta:get_string("owner")
|
||||
local list_name = "nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z
|
||||
|
||||
-- Show seller interface if the player is the owner.
|
||||
if player_name == owner then
|
||||
minetest.show_formspec(player_name, "bank_accounts:card_swipe_seller",
|
||||
"size[8,9]" ..
|
||||
|
|
@ -60,7 +49,6 @@ minetest.register_node("bank_accounts:card_swipe", {
|
|||
"list[current_player;main;0,5;8,3]" ..
|
||||
"button_exit[1,8.25;3,1;reset;"..S("Reset Price").."]" ..
|
||||
"button_exit[4.5,8.25;3,1;set_price;"..S("Set Price").."]")
|
||||
-- Show buyer interface for everyone else.
|
||||
else
|
||||
if meta:get_inventory():is_empty("items") then
|
||||
minetest.chat_send_player(player_name, S("[Card Swipe] This machine is empty."))
|
||||
|
|
@ -83,7 +71,7 @@ minetest.register_node("bank_accounts:card_swipe", {
|
|||
return
|
||||
end
|
||||
|
||||
local price = tonumber(price_str)
|
||||
local price = normalize_and_tonumber(price_str)
|
||||
if wielded_item == "bank_accounts:debit_card" and bank_accounts.get_balance(player_name) < price then
|
||||
minetest.chat_send_player(player_name, S("[Card Swipe] Card declined. Insufficient funds."))
|
||||
return
|
||||
|
|
@ -91,8 +79,8 @@ minetest.register_node("bank_accounts:card_swipe", {
|
|||
|
||||
minetest.show_formspec(player_name, "bank_accounts:card_swipe_buyer",
|
||||
"size[8,8]" ..
|
||||
"label[1,1;"..S("Price: @1", string.format("%.2f", price).." MG").."]" ..
|
||||
"label[1,1.5;"..S("Owner: @1", owner).."]"..
|
||||
"label[1,1;"..S("Price: @1",string.format("%.2f",price).." MG").."]" ..
|
||||
"label[1,1.5;"..S("Owner: @1",owner).."]"..
|
||||
"label[1,2;"..S("Items for Sale (Click 'Buy' to receive):").."]"..
|
||||
"list["..list_name..";items;0,2.5;8,2]" ..
|
||||
"list[current_player;main;0,5;8,2;]" ..
|
||||
|
|
@ -101,7 +89,6 @@ minetest.register_node("bank_accounts:card_swipe", {
|
|||
end
|
||||
end,
|
||||
|
||||
-- Only the owner can put items into the swipe machine.
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if player:get_player_name() == minetest.get_meta(pos):get_string("owner") then
|
||||
return stack:get_count()
|
||||
|
|
@ -109,14 +96,21 @@ minetest.register_node("bank_accounts:card_swipe", {
|
|||
return 0
|
||||
end,
|
||||
|
||||
-- THEFT-PREVENTION: Players cannot take items manually.
|
||||
-- The script transfers them automatically upon successful purchase.
|
||||
-- KORREKTUR: Nur der Besitzer darf Items wieder aus dem Automaten nehmen.
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
if player_name == owner or minetest.check_player_privs(player_name, {protection_bypass=true}) then
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
-- Alle anderen (Käufer) werden blockiert.
|
||||
return 0
|
||||
end,
|
||||
})
|
||||
|
||||
-- Crafting recipe for the Card Swipe machine.
|
||||
minetest.register_craft({
|
||||
output = "bank_accounts:card_swipe",
|
||||
recipe = {
|
||||
|
|
@ -126,24 +120,16 @@ minetest.register_craft({
|
|||
},
|
||||
})
|
||||
|
||||
-- Handles formspec submissions for the Card Swipe.
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if not formname:find("bank_accounts:card_swipe") then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
local pos = pos_info
|
||||
if not pos then
|
||||
return
|
||||
end
|
||||
|
||||
if not formname:find("bank_accounts:card_swipe") then return end
|
||||
local player_name = player:get_player_name(); local pos = pos_info; if not pos then return end
|
||||
local meta = minetest.get_meta(pos)
|
||||
if not meta then
|
||||
return
|
||||
if not meta then return end
|
||||
|
||||
local function on_fail()
|
||||
minetest.chat_send_player(player_name, S("[Bank] System is busy, please try again in a moment."))
|
||||
end
|
||||
|
||||
-- Logic for the seller's interface.
|
||||
if formname == "bank_accounts:card_swipe_seller" then
|
||||
if fields.set_price then
|
||||
local price = normalize_and_tonumber(fields.price)
|
||||
|
|
@ -159,9 +145,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
end
|
||||
end
|
||||
|
||||
-- Logic for the buyer's interface.
|
||||
if formname == "bank_accounts:card_swipe_buyer" then
|
||||
if fields.buy then
|
||||
if bank_accounts.is_calculating_interest then on_fail(); return end
|
||||
|
||||
local owner = meta:get_string("owner")
|
||||
local price = tonumber(meta:get_string("price") or "0")
|
||||
local shop_inv = meta:get_inventory()
|
||||
|
|
@ -176,21 +163,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local description_for_buyer = S("Items from @1", owner)
|
||||
local description_for_seller = S("Items to @1", player_name)
|
||||
|
||||
-- Debit Card Transaction
|
||||
if wielded_item == "bank_accounts:debit_card" then
|
||||
if bank_accounts.get_balance(player_name) >= price then
|
||||
bank_accounts.add_balance(player_name, -price, "Purchase", "", description_for_buyer, owner)
|
||||
bank_accounts.add_balance(owner, price, "Sale", "", description_for_seller, player_name)
|
||||
payment_successful = true
|
||||
local s1 = bank_accounts.add_balance(player_name, -price, "Purchase", "", description_for_buyer, owner)
|
||||
local s2 = bank_accounts.add_balance(owner, price, "Sale", "", description_for_seller, player_name)
|
||||
if s1 and s2 then payment_successful = true else on_fail() end
|
||||
end
|
||||
-- Credit Card Transaction
|
||||
elseif wielded_item == "bank_accounts:credit_card" then
|
||||
bank_accounts.add_credit(player_name, price, "Credit Purchase", "", description_for_buyer, owner)
|
||||
bank_accounts.add_balance(owner, price, "Sale", "", description_for_seller, player_name)
|
||||
payment_successful = true
|
||||
local s1 = bank_accounts.add_credit(player_name, price, "Credit Purchase", "", description_for_buyer, owner)
|
||||
local s2 = bank_accounts.add_balance(owner, price, "Sale", "", description_for_seller, player_name)
|
||||
if s1 and s2 then payment_successful = true else on_fail() end
|
||||
end
|
||||
|
||||
-- If payment was successful, transfer items.
|
||||
if payment_successful then
|
||||
local player_inv = player:get_inventory()
|
||||
for i=1, shop_inv:get_size("items") do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue