Advertisement
toastonrye

mm-main.lua

Aug 1st, 2022 (edited)
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. --MM Idea
  2. local rInterface = peripheral.find("redstoneIntegrator")
  3. local chatBox = peripheral.find("chatBox")
  4.  
  5. if not rInterface then error("redstoneIntegrator not found! [Advanced Peripherals]") end
  6. if not chatBox then error("chatBox not found! [Advanced Peripherals]") end
  7.  
  8. newGame = false
  9. user = "toastonrye"
  10. secretCode = nil
  11. checkedGuess = {}
  12. count = 1
  13.  
  14. local function parseGuess(message)
  15.  local msgArray = {}
  16.  for w in string.gmatch(message, "%S+") do
  17.   table.insert(msgArray, w)
  18.  end
  19.  return msgArray
  20. end
  21.  
  22. local function checkGuess(guess, answer)
  23.  print("GUESS")
  24.  printLoop(guess)
  25.  checkedGuess[count] = {}
  26.  for i, code in pairs(guess) do
  27.   if tonumber(code) == answer[i] then
  28.    table.insert(checkedGuess[count], i, 2)
  29.   else
  30.    table.insert(checkedGuess[count], i, 0)
  31.   end
  32.  end
  33.  print("STATS")
  34.  printLoop(checkedGuess[count])
  35. end
  36.  
  37. local function chatListener()
  38.  while true do
  39.   local event = {os.pullEvent("chat")} -- 1.event 2.player 3.message 4/5?
  40.   local command = parseGuess(event[3])
  41.   --printLoop(command)
  42.   if command[1] == "gon" then
  43.    print("New Game")
  44.    newGame = true
  45.   elseif command[1] == "goff" then
  46.    print("Game Quit")
  47.    newGame = false
  48.   elseif command[1] == "g" then
  49.    table.remove(command, 1)
  50.    checkGuess(command, secretCode)
  51.    count = count + 1
  52.   end
  53.  end
  54. end
  55.  
  56. local function getCode()
  57.  local r = {}
  58.  for i=1,4 do
  59.   table.insert(r, math.random(1,16))
  60.  end
  61.  return r
  62. end
  63.  
  64. function printLoop(table)
  65.  for k, v in pairs(table) do
  66.   print(k, v)
  67.   chatBox.sendMessageToPlayer(k .. ":" .. v, user)
  68.   sleep(3)
  69.  end
  70. end
  71.  
  72. local function myMain()
  73.  while true do
  74.   if newGame then
  75.    chatBox.sendMessageToPlayer("NEW GAME", user)
  76.    secretCode = getCode()
  77.    print("CODE")
  78.    printLoop(secretCode)
  79.    newGame = false  
  80.   end
  81.  sleep()
  82.  end
  83. end
  84.  
  85. parallel.waitForAny(chatListener, myMain)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement