Update prog2/Slot.lua

This commit is contained in:
minecartchris
2026-01-31 20:26:21 -06:00
parent 01934f339a
commit c32bd782af
+39 -14
View File
@@ -1,17 +1,38 @@
--Slot --Slot
local function interactWithCard(nfc, mode, money) rednet.open("back")
local function interactWithCard(userUUID, mode, money)
if mode == "updateBalance" then if mode == "updateBalance" then
nfc.write(tostring(money)) rednet.broadcast({
print("Please tap your card to update balance") uuid = userUUID,
while not os.pullEvent("nfc_write") do amount = money,
sleep(0) type = "set"
end }, "machineBalanceModifier")
end end
if mode == "getBalance" then if mode == "getBalance" then
print("Please tap your card to check balance") local _, _, cardUUID = os.pullEvent("nfc_data")
local blank, yes, money = os.pullEvent("nfc_data") rednet.broadcast({
return money card = cardUUID
}, "getAccountData")
while true do
local id, message = rednet.receive("server_response", 10)
if not id then
print("the server is down")
print("please ping @minecartchris")
sleep(30)
--shell.run("reboot")
end
if message.type == "account_data" and message.cardId == cardUUID then
local money = message.balance
local playerUUID = message.uuid
local username = message.username
return money, playerUUID, username
end
end
end end
end end
@@ -20,7 +41,7 @@ sleep(0.25)
nfc = peripheral.wrap("bottom") nfc = peripheral.wrap("bottom")
os.pullEvent=os.pullEventRaw --os.pullEvent=os.pullEventRaw
if fs.exists("/disk/terminate") then if fs.exists("/disk/terminate") then
error("Service mode active",2) error("Service mode active",2)
end end
@@ -40,8 +61,12 @@ local bet = 0
--local money2 = fs.open("/disk2/money.lua", "r") --local money2 = fs.open("/disk2/money.lua", "r")
print("Welcome to the Slot Machine!") print("Welcome to the Slot Machine!")
print("Please swipe your card to begin") print("Please swipe your card to begin")
money = interactWithCard(nfc, "getBalance", nil)
--local _, _, userUUID = os.pullEvent("nfc_data")
money, playerUUID, username = interactWithCard(nil, "getBalance", nil)
--money2.close() --money2.close()
print("Welcome "..tostring(username))
local h = fs.open("disk/house.lua", "r") local h = fs.open("disk/house.lua", "r")
house = h.readAll() house = h.readAll()
h.close() h.close()
@@ -67,6 +92,7 @@ if not winner then
money = money - bet money = money - bet
house = house + bet house = house + bet
print("you have $",money, "left over") print("you have $",money, "left over")
interactWithCard(playerUUID, "updateBalance", money)
end end
if winner then if winner then
bet = bet * 2 bet = bet * 2
@@ -74,9 +100,9 @@ if winner then
print("You win!!!!!") print("You win!!!!!")
house = house - bet house = house - bet
print("You now have $", money) print("You now have $", money)
interactWithCard(playerUUID, "updateBalance", money)
end end
--money2 = fs.open("/disk2/money.lua", "w") --money2 = fs.open("/disk2/money.lua", "w")
interactWithCard(nfc, "updateBalance", money)
--money2.close() --money2.close()
while true do while true do
@@ -97,5 +123,4 @@ h.write(house)
h.close() h.close()
--print("If removing your card do it now") --print("If removing your card do it now")
sleep(2) sleep(2)
shell.run("clear all") os.reboot()
shell.run("startup")