Null_Cat

Minesweeper (Server) v2 (Roblox)

Jan 31st, 2019
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.81 KB | None | 0 0
  1. -- v2 has an Always Good Start. This generates the board AFTER you first uncover a mine, so you always start on a 0.
  2. -- Part of the Minesweeper Project [https://pastebin.com/Yftb7QWL]
  3.  
  4. if script.ClassName == "LocalScript" then error("Run with r/, not rl/.") return end
  5. if workspace:FindFirstChild("NullMinesweeperServerv2") then error("The script is already being ran. Use the client sided script\nIf you believe this is an error, run the following:\n\"c/workspace.NullMinesweeperServerv2:Destroy()\"") return end
  6.  
  7. script.Name = "NullMinesweeperServerv2"
  8. --Creates the Remote for Client to Server communication
  9. local mineRemote = Instance.new("RemoteEvent")
  10. mineRemote.Parent = game:GetService"ReplicatedStorage"
  11. mineRemote.Name = "MineRemote"
  12.  
  13. --Creates a function that makes every part Smooth instead of studded
  14. function noOutlines(partNoOutlines)
  15.   if partNoOutlines.ClassName == "Part" or partNoOutlines.ClassName == "WedgePart" then
  16.     partNoOutlines.TopSurface = "SmoothNoOutlines"
  17.     partNoOutlines.BottomSurface = "SmoothNoOutlines"
  18.     partNoOutlines.LeftSurface = "SmoothNoOutlines"
  19.     partNoOutlines.RightSurface = "SmoothNoOutlines"
  20.     partNoOutlines.FrontSurface = "SmoothNoOutlines"
  21.     partNoOutlines.BackSurface = "SmoothNoOutlines"
  22.   else
  23.     error('what')
  24.   end
  25. end
  26.  
  27. --Creates the ID system for placing the boards
  28. local boardID = {}
  29.  
  30. for i = 1, game:GetService"Players".MaxPlayers do --[[Generates the boardID table to be of the MaxPlayers allowed in the game.
  31.   Allows for easy customization of the Players, as well as not having unneccessary 32s and 54s]]
  32.     boardID[i] = i
  33. end
  34.  
  35. function createBoardArray(startPos, width, height, mineCount, physicalBoard)
  36.     --This will help with RNG
  37.     math.randomseed(tick())
  38.     --Generating the Array. First step towards the board generation
  39.     local board = {}
  40.     for i = 1, height do
  41.         local newRow = {} -- This is an array for each new row
  42.         for j = 1, width do
  43.             if mineCount > 0 then -- If there is still meant to be mines
  44.                 if math.random(1,10) == 1 and not ( -- Go through with RNG.
  45.                         (startPos.y == i or (startPos.y + 1 == i or startPos.y - 1 == i)) and
  46.                         (startPos.x == j or (startPos.x + 1 == j or startPos.x - 1 == j))) then
  47.                         table.insert(newRow,j,10)
  48.                         mineCount = mineCount - 1
  49.                 else -- If RNG fails, don't place a mine.
  50.                     table.insert(newRow,j,0)
  51.                 end
  52.             else -- If there shouldn't be anymore mines, just place an empty space
  53.                 table.insert(newRow,j,0)
  54.             end
  55.         end
  56.         table.insert(board,i,newRow) -- Insert the generated mode into the board. Repeat this "height" times
  57.     end
  58.   --If there still needs to be mines, it'll create them here.
  59.     while mineCount ~= 0 do
  60.         for n,i in ipairs(board) do
  61.             for m,j in ipairs(board[n]) do
  62.                 if board[n][m] ~= 10 and board[n][m] ~= 9 then -- Check if the space is not a mine already
  63.                     if math.random(1,15) == 1 and not ( -- If not, go through with RNG. Tougher this time.
  64.                         (startPos.y == n or (startPos.y + 1 == n or startPos.y - 1 == n)) and
  65.                         (startPos.x == m or (startPos.x + 1 == m or startPos.x - 1 == m))) then
  66.                             board[n][m] = 10 -- Replaces board[n][m] with a mine.
  67.                             mineCount = mineCount - 1
  68.                     end
  69.                 end
  70.                 if mineCount == 0 then
  71.                     break
  72.                 end
  73.             end
  74.             if mineCount == 0 then -- Double break because one break only stops part of it
  75.                 break
  76.             end
  77.         end    
  78.     end
  79.     -- Check for Mines and put numbers next to them
  80.     for n,i in ipairs(board) do
  81.         for m,j in ipairs(board[n]) do
  82.             if board[n][m] == 10 then -- If there is a mine, execute all of the following. Each direction shows where it goes towards below.
  83.                 --Left
  84.                 if m-1 ~= 0 then
  85.                     if board[n][m-1] ~= 10 then
  86.                         board[n][m-1] = board[n][m-1] + 1
  87.                     end
  88.                 end
  89.                 --Right
  90.                 if m+1 <= width then
  91.                     if board[n][m+1] ~= 10 then
  92.                         board[n][m+1] = board[n][m+1] + 1
  93.                     end
  94.                 end
  95.                 --Up
  96.                 if n-1 ~= 0 then
  97.                     if board[n-1][m] ~= 10 then
  98.                         board[n-1][m] = board[n-1][m] + 1
  99.                     end
  100.                 end
  101.                 --Down
  102.                 if n+1 <= height then
  103.                     if board[n+1][m] ~= 10 then
  104.                         board[n+1][m] = board[n+1][m] + 1
  105.                     end
  106.                 end
  107.                
  108.                 --Up Left
  109.                 if n-1 ~= 0 and m-1 ~= 0 then
  110.                     if board[n-1][m-1] ~= 10 then
  111.                         board[n-1][m-1] = board[n-1][m-1] + 1
  112.                     end
  113.                 end
  114.                 --Up Right
  115.                 if n-1 ~= 0 and m+1 <= width then
  116.                     if board[n-1][m+1] ~= 10 then
  117.                         board[n-1][m+1] = board[n-1][m+1] + 1
  118.                     end
  119.                 end
  120.                 --Down Left
  121.                 if n+1 <= height and m-1 ~= 0 then
  122.                     if board[n+1][m-1] ~= 10 then
  123.                         board[n+1][m-1] = board[n+1][m-1] + 1
  124.                     end
  125.                 end
  126.                 --Down Right
  127.                 if n+1 <= height and m+1 <= width then
  128.                     if board[n+1][m+1] ~= 10 then
  129.                         board[n+1][m+1] = board[n+1][m+1] + 1
  130.                     end
  131.                 end
  132.             end
  133.         end
  134.     end
  135.    
  136.     for i = 1, height do
  137.         for j = 1, width do
  138.             physicalBoard[i.." "..j].Check.Value = board[i][j]
  139.         end
  140.     end
  141. end
  142.  
  143. --Time for the big boy function
  144. function generateBoard(width, height, lmineCount, x, y, z, plr)
  145.     --Creates two variables that will keep count of the mines
  146.     local mineCount = lmineCount
  147.     local spacesRemaining = (width * height) - lmineCount
  148.     local allowTouch = false -- It's a surprise tool that will help us later. (makes it so you can't uncover the spaces if lost)
  149.  
  150.      --Creates the Model for the spaces
  151.     local minesweepTempStorage = Instance.new("Folder")
  152.    
  153.     local modelSpace = Instance.new("Model")
  154.     modelSpace.Parent = minesweepTempStorage
  155.     modelSpace.Name = "Space"
  156.    
  157.     local spaceCenter = Instance.new("Part")
  158.     spaceCenter.Name = "Center"
  159.     spaceCenter.Anchored = true
  160.     spaceCenter.Parent = modelSpace
  161.     noOutlines(spaceCenter)
  162.     spaceCenter.Color = Color3.fromRGB(163,162,165)
  163.     spaceCenter.Size = Vector3.new(4,0.5,4)
  164.     spaceCenter.CFrame = CFrame.new(-16.5,0.25,-23.5)
  165.     modelSpace.PrimaryPart = spaceCenter
  166.    
  167.     local spaceOutline = Instance.new("Part")
  168.     spaceOutline.Name = "Outline"
  169.     spaceOutline.Parent = modelSpace
  170.     noOutlines(spaceOutline)
  171.     spaceOutline.Color = Color3.fromRGB(99,95,98)
  172.     spaceOutline.Size = Vector3.new(5,0.5,5)
  173.     spaceOutline.CFrame = CFrame.new(-16.5,0.226,-23.5)
  174.     spaceOutline.Anchored = true
  175.    
  176.     local spaceCheck = Instance.new("NumberValue")
  177.     spaceCheck.Name = "Check"
  178.     spaceCheck.Value = 9
  179.     spaceCheck.Parent = modelSpace
  180.  
  181.     local spaceFlag = Instance.new("BoolValue")
  182.     spaceFlag.Parent = modelSpace
  183.     spaceFlag.Value = false
  184.     spaceFlag.Name = "IsFlagged"
  185.  
  186.     local spaceClick = Instance.new("ClickDetector")
  187.     spaceClick.Parent = spaceCenter
  188.     spaceClick.Name = "ToFlag"
  189.  
  190.     -- Now create the actual board
  191.     local physicalBoard = Instance.new("Model") -- Creates a model to hold the board
  192.     physicalBoard.Name = "Board"
  193.     physicalBoard.Parent = workspace
  194.     for i = 1, height do
  195.         for j = 1, width do
  196.             local newSpace = minesweepTempStorage.Space:Clone() -- Clone the space.
  197.             local numCheck = newSpace.Check -- Get the number container for where it's meant to be.
  198.             newSpace.Parent = physicalBoard -- The Clone is put into the Board Model (in the workspace)
  199.             newSpace:SetPrimaryPartCFrame(CFrame.new(x+(i*5),y,z+(j*5))) --Place it 5 away from the other spaces
  200.             newSpace.Name = i.." "..j
  201.            
  202.             newSpace.Center.ToFlag.MouseClick:Connect(function(playerClick) -- To Flag Stuff
  203.                 if playerClick == plr then -- Makes it so other people can mess stuff up
  204.                     if newSpace.IsFlagged.Value then -- If it is flagged, unflag it.
  205.                         newSpace.IsFlagged.Value = false
  206.                         newSpace.Center.Color = Color3.fromRGB(163,162,165)
  207.                     else -- If it isn't flagged, flag it.
  208.                         newSpace.IsFlagged.Value = true
  209.                         newSpace.Center.Color = Color3.new(1,0,0)
  210.                     end
  211.                 end
  212.             end)
  213.            
  214.             newSpace.Center.Touched:Connect(function(part) -- If they touched a space, clear it.
  215.                 if ((part.Parent.ClassName == "Model" and part.Parent.Name == plr.Character.Name) or (part.Name == "0Detect"..plr.Character.Name)) and allowTouch then -- If you are a model, are named the player playing, AND are allowed to touch stuff (disabled when lost), it will allow.
  216.                     if not newSpace.IsFlagged.Value then -- Checks if the space isn't flagged
  217.                         newSpace.Center:Destroy() -- Destroys the center. Prevents the Touched part to run indefinetly
  218.                         spacesRemaining = spacesRemaining - 1
  219.                         if numCheck.Value == 0 then -- If its 0, make it semi-transparent
  220.                             newSpace.Outline.Transparency = 0.75
  221.                             --Place a block that will clear everything around it.
  222.                                 local clearBlock = Instance.new("Part")
  223.                                 clearBlock.Parent = physicalBoard
  224.                                 clearBlock.Size = Vector3.new(10,10,10)
  225.                                 clearBlock.CFrame = newSpace.Outline.CFrame --Set the CFrame to be where the space that was touched was.
  226.                                 clearBlock.Transparency = 1
  227.                                 clearBlock.Name = "0Detect"..plr.Character.Name --Name it like the Player so it doesn't activate anything else on accident, or anything else doesn't activate it.
  228.                                 clearBlock.CanCollide = false
  229.                                 wait()
  230.                                 clearBlock:Destroy()
  231.                         --Colors each one
  232.                             --1 : RGB(0,0,255)
  233.                             --2 : RGB(0,255,0)
  234.                             --3 : RGB(255,0,0)
  235.                             --4 : RGB(107,50,124)
  236.                             --5 : RGB(117,0,0)
  237.                             --6 : RGB(64,224,208)
  238.                             --7 : RGB(0,0,0)
  239.                             --8 : RGB(99,95,98)
  240.                             --10 : RGB(255,255,255)
  241.                         elseif numCheck.Value == 1 then
  242.                             newSpace.Outline.Color = Color3.fromRGB(0,0,255)
  243.                             --newSpace.Outline.SurfaceGui.Number.Text = "1"
  244.                         elseif numCheck.Value == 2 then
  245.                             newSpace.Outline.Color = Color3.fromRGB(0,255,0)
  246.                             --newSpace.Outline.SurfaceGui.Number.Text = "2"
  247.                         elseif numCheck.Value == 3 then
  248.                             newSpace.Outline.Color = Color3.fromRGB(255,0,0)
  249.                             --newSpace.Outline.SurfaceGui.Number.Text = "3"
  250.                         elseif numCheck.Value == 4 then
  251.                             newSpace.Outline.Color = Color3.fromRGB(107,50,124)
  252.                             --newSpace.Outline.SurfaceGui.Number.Text = "4"
  253.                         elseif numCheck.Value == 5 then
  254.                             newSpace.Outline.Color = Color3.fromRGB(117,0,0)
  255.                             --newSpace.Outline.SurfaceGui.Number.Text = "5"
  256.                         elseif numCheck.Value == 6 then
  257.                             newSpace.Outline.Color = Color3.fromRGB(64,224,208)
  258.                             --newSpace.Outline.SurfaceGui.Number.Text = "6"
  259.                         elseif numCheck.Value == 7 then
  260.                             newSpace.Outline.Color = Color3.fromRGB(0,0,0)
  261.                             --newSpace.Outline.SurfaceGui.Number.Text = "7"
  262.                         elseif numCheck.Value == 8 then
  263.                             newSpace.Outline.Color = Color3.fromRGB(99,95,98)
  264.                             --newSpace.Outline.SurfaceGui.Number.Text = "8"
  265.                         elseif numCheck.Value == 10 then -- Oh hecc, you stepped on a mine!
  266.                             spacesRemaining = spacesRemaining + 1 -- Make sure it doesn't trigger the Win sequence
  267.                             newSpace.Outline.Color = Color3.fromRGB(255,255,255)
  268.                             allowTouch = false -- The player can no longer interact with the board.
  269.                             mineRemote:FireClient(plr,"Recieving",nil) -- Grab the ID from the player.
  270.                             for _,i in ipairs(physicalBoard:GetChildren()) do -- Highlight all the mines in green
  271.                                 if i.ClassName == "Model" then
  272.                                     if i.Check.Value == 10 then
  273.                                         if i ~= newSpace then -- This checks if it ISN'T the current space, as it will break everything because the Center doesn't exist.
  274.                                             i.Center.Color = Color3.new(0,1,0)
  275.                                             --i.Center.ToFlag:Destroy()
  276.                                         end
  277.                                     end
  278.                                 end
  279.                             end
  280.                             wait(5) -- Wait a little for the player to see the mines
  281.                             physicalBoard:Destroy()
  282.                         elseif numCheck.Value == 9 then -- First step, make the board
  283.                             createBoardArray({["x"]=j,["y"]=i},width,height,lmineCount,physicalBoard)
  284.                             wait()
  285.                             newSpace.Outline.Transparency = 0.75
  286.                             --Place a block that will clear everything around it.
  287.                                 local clearBlock = Instance.new("Part")
  288.                                 clearBlock.Parent = physicalBoard
  289.                                 clearBlock.Size = Vector3.new(10,10,10)
  290.                                 clearBlock.CFrame = newSpace.Outline.CFrame --Set the CFrame to be where the space that was touched was.
  291.                                 clearBlock.Transparency = 1
  292.                                 clearBlock.Name = "0Detect"..plr.Character.Name --Name it like the Player so it doesn't activate anything else on accident, or anything else doesn't activate it.
  293.                                 clearBlock.CanCollide = false
  294.                                 wait()
  295.                                 clearBlock:Destroy()
  296.                         end
  297.                         if spacesRemaining == 0 then
  298.                             for _,i in ipairs(physicalBoard:GetChildren()) do -- Mark all of the mines with green.
  299.                                 if i.ClassName == "Model" then
  300.                                     if i.Check.Value == 10 then
  301.                                         i.Center.Color = Color3.new(0,1,0)
  302.                                         i.Center.ToFlag:Destroy()
  303.                                     end
  304.                                 end
  305.                             end
  306.                             allowTouch = false
  307.                             wait(10) -- Wait 10 for the person who won to see their work.
  308.                             mineRemote:FireClient(plr,"Recieving",nil) -- Grab the ID they were given back.
  309.                             wait(1)
  310.                             physicalBoard:Destroy() -- Destroy the board
  311.                         end
  312.                     end
  313.                 end
  314.             end)
  315.         end
  316.     wait(0.1)
  317.     end
  318.    
  319.     --Create Overhead stuff to start
  320.     local platformBegin = Instance.new("Part") --Creates a platform the player can stand on to move raround to find a starting spot.
  321.     platformBegin.Parent = physicalBoard
  322.     platformBegin.Size = Vector3.new(height*5,0.5,width*5)
  323.     platformBegin.Position = Vector3.new(x+(2.5*height),y+10,z+(2.5*width))
  324.     platformBegin.Anchored = true
  325.     platformBegin.Transparency = 1
  326.    
  327.     wait(0.5)
  328.     plr.Character.HumanoidRootPart.CFrame = CFrame.new(x+(2.5*height),y+13,z+(2.5*width)) -- Teleports the player
  329.     wait(0.25)
  330.    
  331.     local touchToBegin = Instance.new("Part") -- Creates the Overhead part that is used to start the game.
  332.     touchToBegin.Parent = physicalBoard
  333.     touchToBegin.Size = Vector3.new(height*5,0.5,width*5)
  334.     touchToBegin.Position = Vector3.new(x+(2.5*height),y+18,z+(2.5*width))
  335.     touchToBegin.Anchored = true
  336.     touchToBegin.Transparency = 1
  337.    
  338.     touchToBegin.Touched:Connect(function(part) -- If the player jumped, start the game.
  339.         if part.Parent.ClassName == "Model" and part.Parent.Name == plr.Character.Name then
  340.             touchToBegin:Destroy()
  341.             platformBegin:Destroy()
  342.         end
  343.     end)
  344.     minesweepTempStorage:Destroy() -- Destroys the inital part that was cloned to create the board
  345.     allowTouch = true
  346.  
  347.     plr.Character:FindFirstChildOfClass("Humanoid").Died:Connect(function() -- Failsafe in case the player dies
  348.         physicalBoard:Destroy() -- Destroy the board
  349.     end)
  350.     plr.Chatted:Connect(function(msg)
  351.         if msg:sub(1,4):lower() == "/m r" then
  352.             physicalBoard:Destroy()
  353.         elseif msg:sub(1,4):lower() == "/m t" then
  354.         allowTouch = false
  355.         plr.Character.HumanoidRootPart.CFrame = CFrame.new(x+(2.5*height),y+13,z+(2.5*width)) -- Teleports the player
  356.         wait(5)
  357.         allowTouch = true
  358.     end
  359.     end)
  360. end
  361.  
  362. mineRemote.OnServerEvent:Connect(function(plrRec, action, w, h, m, plrID) -- OH BOY SERVER TO CLIENT COMMUNICATION
  363.     if action == "Board" then -- If the client wants to create the board
  364.        
  365.         generateBoard(w,h,m, --[[plrID*(w*5+5)]]0,plrID*20-19,h, plrRec) --Create the board
  366.     elseif action == "ID" then -- The client wants to give an ID
  367.        
  368.         boardID[plrID] = plrID --Takes the player ID and puts it back to be used
  369.     elseif action == "Grab" then -- If the Client requests an ID
  370.        
  371.         for n,i in ipairs(boardID) do --Checks every spot in the board
  372.             if boardID[n] ~= 0 then -- If the ID is available
  373.                 mineRemote:FireClient(plrRec,"Sending",boardID[i]) -- Send the ID to the player
  374.                
  375.                 boardID[n] = 0 -- Set that ID to be nothing so it isn't used again
  376.                 break -- break the loop
  377.             end
  378.         end
  379.     end
  380. end)
  381.  
  382. -- OH BOI LOCALSCRIPT TIME
  383. local localscript = NLS([=[--alright minesweeper time
  384. --kill me
  385. --[[ This is grabbing the play and waiting for controls and stuff.
  386. mostly just mobile stuff but whatever]]--
  387.  
  388. local plr = game:GetService"Players".LocalPlayer -- Grabs player
  389. local chr = plr.Character -- Grabs the player's Model
  390. if workspace:FindFirstChild(plr.Name.."MinesweeperClient") then error("The local is already being ran. If you believe this is an error, run the following:\n\"c/owner.Character:FindFirstChild(plr.Name..\"MinesweeperClient\"):Destroy()\"") return end
  391. local storage = game:GetService"ReplicatedStorage" -- Grab the ReplicatedStorage which contains the RemoteEvent
  392. local remote = storage.MineRemote -- Grab the RemoteEVent
  393. script.Name = plr.Name.."MinesweeperClient"
  394.  
  395. local idForPlr = 0 -- This will be grabbed later. It will help in placing the boards
  396. local ignoreMessages = false
  397. local widthChatRequest, heightChatRequest, mineChatRequest = 2, 2, 1 -- This will come in the "Chatted" Event
  398. local beginner, intermediate, expert = { -- The width, height, and mine count for each difficulty
  399.     ["width"] = 8,
  400.     ["height"] = 8,
  401.     ["mines"] = 10
  402. },{
  403.     ["width"] = 16,
  404.     ["height"] = 16,
  405.     ["mines"] = 40
  406. },{
  407.     ["width"] = 16,
  408.     ["height"] = 30,
  409.     ["mines"] = 99
  410. }
  411.  
  412. function roundNum(num)
  413.   local baseNum, newNum
  414.   if num > 0 then
  415.     baseNum = math.floor(num)
  416.     newNum = num - baseNum
  417.     if newNum >= 0.5 then
  418.       return math.ceil(num)
  419.     elseif newNum < 0.5 then
  420.       return math.floor(num)
  421.     end
  422.   else
  423.     baseNum = math.ceil(num)
  424.     newNum = num - baseNum
  425.     if newNum > -0.5 then
  426.       return math.ceil(num)
  427.     elseif newNum <= -0.5 then
  428.       return math.floor(num)
  429.     end
  430.   end
  431. end
  432.  
  433. function returnID()
  434.     remote:FireServer("ID",0,0,0,idForPlr) -- Send the ID
  435.     idForPlr = 0
  436. end
  437.  
  438. plr.Chatted:Connect(function(msg)
  439.     if msg:sub(1,3):lower() == "/m " then
  440.         local cmd = msg:sub(4)
  441.         if not ignoreMessages then
  442.             ignoreMessages = true
  443.             if cmd:sub(1,1) == "b" then
  444.                 widthChatRequest, heightChatRequest, mineChatRequest = beginner.width, beginner.height, beginner.mines -- Sets beginner difficulty
  445.                 remote:FireServer("Grab", nil, nil, nil, nil) -- Requests an ID
  446.             elseif cmd:sub(1,1) == "i" then
  447.                 widthChatRequest, heightChatRequest, mineChatRequest = intermediate.width, intermediate.height, intermediate.mines -- Sets intermediate difficulty
  448.                 remote:FireServer("Grab", nil, nil, nil, nil) -- Requests an ID
  449.             elseif cmd:sub(1,1) == "e" then
  450.                 widthChatRequest, heightChatRequest, mineChatRequest = expert.width, expert.height, expert.mines -- Sets expert difficulty
  451.                 remote:FireServer("Grab", nil, nil, nil, nil) -- Requests an ID
  452.             elseif cmd:sub(1,1) == "c" then -- Custom Board
  453.         local customVariables = cmd:sub(2) -- grab ONLY the custom variables
  454.         local count = 0 -- This will help in sorting the request
  455.         for i in customVariables:gmatch("%S+") do -- Splits the variables into their own seperate parts
  456.           count = count + 1 -- Adds one to the count, which changes which part to change about the board
  457.           local a = tonumber(i) -- Changes the string to a number
  458.           if count == 1 then -- 1 is requesting width
  459.             if a <= 32 and a > 7 then
  460.               widthChatRequest = a
  461.             elseif a < 7 then
  462.               warn("There were less than 7 width in the field. Setting to 7...")
  463.               widthChatRequest = 7
  464.             else
  465.               warn("The width of the board is too big! Setting to 32...")
  466.               widthChatRequest = 32
  467.             end
  468.           elseif count == 2 then -- 2 is requesting height
  469.             if a <= 32 and a > 7 then
  470.               heightChatRequest = a
  471.             elseif a < 7 then
  472.               warn("There were less than 7 height in the field. Setting to 7...")
  473.               heightChatRequest = 7
  474.             else
  475.               warn("The height of the board is too big! Setting to 32...")
  476.               heightChatRequest = 32
  477.             end
  478.           elseif count == 3 then -- 3 is requesting mine count
  479.             local maxMines = roundNum((widthChatRequest * heightChatRequest) / 1.25) -- This is to make it so there isn't more mines than the board itself
  480.             if a <= maxMines then
  481.               mineChatRequest = a
  482.             elseif a < 0 then
  483.               warn("There were less than 1 mine in the field. Setting to 1...")
  484.               mineChatRequest = 1
  485.             else
  486.               warn("The mine count is too much! Setting to "..maxMines.."...")
  487.               mineChatRequest = maxMines
  488.             end
  489.           end
  490.         end
  491.         remote:FireServer("Grab", nil, nil, nil, nil) -- Requests the ID
  492.       end
  493.         else
  494.             if cmd:sub(1,1) == "r" then -- Restart Minesweeper
  495.                 returnID()
  496.                 ignoreMessages = false
  497.             end
  498.         end
  499.     end
  500. end)
  501.  
  502.  
  503. remote.OnClientEvent:Connect(function(action, newID) -- Server to Client stuff
  504.     if action == "Sending" then -- When the server gives an ID
  505.         idForPlr = newID -- Store the ID
  506.         remote:FireServer("Board", widthChatRequest,heightChatRequest,mineChatRequest,idForPlr) -- Then request a board
  507.         warn("Jump to start. Do not walk off the invisible platform you are on.")
  508.         print("0-Transparent") -- Gives the player instructions on to what each color represents
  509.         print("1-Blue")
  510.         print("2-Green")
  511.         print("3-Red")
  512.         print("4-Purple")
  513.         print("5-Crimson")
  514.         print("6-Turquoise")
  515.         print("7-Black")
  516.         print("8-Gray")
  517.     elseif action == "Recieving" then -- When the server requests for the ID
  518.         returnID()
  519.         ignoreMessages = false
  520.     end
  521. end)
  522.  
  523. chr:FindFirstChildOfClass("Humanoid").Died:Connect(function() -- If the humanoid dies, return the ID. Failsafe.
  524.     returnID()
  525.     script:Destroy()
  526. end)
  527.  
  528. print("Prefix: /m\nb, i, e run the beginner, intermediate, and expert boards respectively.\nc [w] [h] [m] to set a custom board [w]*[h] big with [m] mines.\nr to reset your board.\nt to teleport back to your board.")]=], owner.Character):WaitForChild"MineRemote"
Advertisement
Add Comment
Please, Sign In to add comment