MrUndead

NumberGame

Feb 11th, 2022 (edited)
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local event = require("event")
  4. local Data = component.data
  5. local m = component.modem
  6.  
  7. term.clear()
  8.  
  9. local ServerA = "158e29fe-4f83-42b5-8837-1bddad8fadc4"
  10. local PortO = 123
  11.  
  12. m.open(PortO)
  13.  
  14. local function myFunction(eventName, address, playerName, cardData,
  15.                           cardUniqueId, isCardLocked, side)
  16.  
  17.     m.send(ServerA, PortO, "ATM")
  18.     os.sleep(2)
  19.     m.send(ServerA, PortO, cardData)
  20.     os.sleep(1)
  21.     local _, _, from, port, _, ServerBalance = event.pull("modem_message")
  22.  
  23.     term.clear()
  24.     local Balance = ServerBalance
  25.     io.write("Choose how much money you are willing to bet\n")
  26.     io.write("Type E to exit!")
  27.     io.write("---------------------------------\n")
  28.     io.write("your balance is ", Balance, "$\n")
  29.     io.write("You will be assigned a random number between\n 1-15 and the casino will be assigned a number between 1-10\n Highest number win!")
  30.     print("\n")
  31.  
  32.     local BetChoice = io.read()
  33.  
  34.     local PlayerNum = math.random(1, 15)
  35.  
  36.     local CasinoNum = math.random(1, 10)
  37.  
  38.     if PlayerNum > CasinoNum then
  39.         term.clear()
  40.         io.write("YOU WIN!\n You had ", PlayerNum, " Casino had ", CasinoNum)
  41.         local BetWin = BetChoice * 3
  42.         local NewBalance = BetWin + Balance
  43.         io.write("YOU WON ", BetWin, "$")
  44.         m.send(ServerA, PortO, "NewBalance")
  45.         os.sleep(2)
  46.         m.send(ServerA, PortO, cardData)
  47.         os.sleep(2)
  48.         m.send(ServerA, PortO, NewBalance)
  49.         event.ignore("magData", myFunction)
  50.         os.execute("NumberGame")
  51.  
  52.     elseif PlayerNum < CasinoNum then
  53.         term.clear()
  54.         io.write("YOU LOOSE!\n You had ", PlayerNum, " Casino had ", CasinoNum)
  55.         local NewBalance = Balance - BetChoice
  56.         m.send(ServerA, PortO, "NewBalance")
  57.         os.sleep(2)
  58.         m.send(ServerA, PortO, cardData)
  59.         os.sleep(2)
  60.         m.send(ServerA, PortO, NewBalance)
  61.         event.ignore("magData", myFunction)
  62.         os.execute("NumberGame")
  63.  
  64.     elseif BetChoice > Balance then
  65.         term.clear()
  66.         io.write("You cant bet more money than what you own!")
  67.         os.sleep(5)
  68.         event.ignore("magData", myFunction)
  69.         os.execute("NumberGame")
  70.  
  71.     elseif Choice == "E" then
  72.         term.clear()
  73.         event.ignore("magData", myFunction)
  74.         os.execute("CasinoStart")
  75.  
  76.     else
  77.         term.clear()
  78.         io.write("Incorrect Command!")
  79.         os.sleep(4)
  80.         os.execute("NumberGame")
  81.     end
  82.  
  83. end
  84.  
  85. term.clear()
  86.  
  87. io.write("Scan Your Card")
  88.  
  89. event.listen("magData", myFunction)
  90.  
Add Comment
Please, Sign In to add comment