Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --alright minesweeper time
- --kill me
- --[[ This is grabbing the play and waiting for controls and stuff.
- mostly just mobile stuff but whatever]]--
- local plr = game:GetService"Players".LocalPlayer -- Grabs player
- local chr = plr.Character -- Grabs the player's Model
- 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
- local storage = game:GetService"ReplicatedStorage" -- Grab the ReplicatedStorage which contains the RemoteEvent
- local remote = storage.MineRemote -- Grab the RemoteEVent
- script.Name = plr.Name.."MinesweeperClient"
- local idForPlr = 0 -- This will be grabbed later. It will help in placing the boards
- local ignoreMessages = false
- local widthChatRequest, heightChatRequest, mineChatRequest = 2, 2, 1 -- This will come in the "Chatted" Event
- local beginner, intermediate, expert = { -- The width, height, and mine count for each difficulty
- ["width"] = 8,
- ["height"] = 8,
- ["mines"] = 10
- },{
- ["width"] = 16,
- ["height"] = 16,
- ["mines"] = 40
- },{
- ["width"] = 16,
- ["height"] = 30,
- ["mines"] = 99
- }
- function roundNum(num)
- local baseNum, newNum
- if num > 0 then
- baseNum = math.floor(num)
- newNum = num - baseNum
- if newNum >= 0.5 then
- return math.ceil(num)
- elseif newNum < 0.5 then
- return math.floor(num)
- end
- else
- baseNum = math.ceil(num)
- newNum = num - baseNum
- if newNum > -0.5 then
- return math.ceil(num)
- elseif newNum <= -0.5 then
- return math.floor(num)
- end
- end
- end
- function returnID()
- remote:FireServer("ID",0,0,0,idForPlr) -- Send the ID
- idForPlr = 0
- end
- plr.Chatted:Connect(function(msg)
- if msg:sub(1,3):lower() == "/m " then
- local cmd = msg:sub(4)
- if not ignoreMessages then
- ignoreMessages = true
- if cmd:sub(1,1) == "b" then
- widthChatRequest, heightChatRequest, mineChatRequest = beginner.width, beginner.height, beginner.mines -- Sets beginner difficulty
- remote:FireServer("Grab", nil, nil, nil, nil) -- Requests an ID
- elseif cmd:sub(1,1) == "i" then
- widthChatRequest, heightChatRequest, mineChatRequest = intermediate.width, intermediate.height, intermediate.mines -- Sets intermediate difficulty
- remote:FireServer("Grab", nil, nil, nil, nil) -- Requests an ID
- elseif cmd:sub(1,1) == "e" then
- widthChatRequest, heightChatRequest, mineChatRequest = expert.width, expert.height, expert.mines -- Sets expert difficulty
- remote:FireServer("Grab", nil, nil, nil, nil) -- Requests an ID
- elseif cmd:sub(1,1) == "c" then -- Custom Board
- local customVariables = cmd:sub(2) -- grab ONLY the custom variables
- local count = 0 -- This will help in sorting the request
- for i in customVariables:gmatch("%S+") do -- Splits the variables into their own seperate parts
- count = count + 1 -- Adds one to the count, which changes which part to change about the board
- local a = tonumber(i) -- Changes the string to a number
- if count == 1 then -- 1 is requesting width
- if a <= 32 and a > 7 then
- widthChatRequest = a
- elseif a < 7 then
- warn("There were less than 7 width in the field. Setting to 7...")
- widthChatRequest = 7
- else
- warn("The width of the board is too big! Setting to 32...")
- widthChatRequest = 32
- end
- elseif count == 2 then -- 2 is requesting height
- if a <= 32 and a > 7 then
- heightChatRequest = a
- elseif a < 7 then
- warn("There were less than 7 height in the field. Setting to 7...")
- heightChatRequest = 7
- else
- warn("The height of the board is too big! Setting to 32...")
- heightChatRequest = 32
- end
- elseif count == 3 then -- 3 is requesting mine count
- local maxMines = roundNum((widthChatRequest * heightChatRequest) / 1.25) -- This is to make it so there isn't more mines than the board itself
- if a <= maxMines then
- mineChatRequest = a
- elseif a < 0 then
- warn("There were less than 1 mine in the field. Setting to 1...")
- mineChatRequest = 1
- else
- warn("The mine count is too much! Setting to "..maxMines.."...")
- mineChatRequest = maxMines
- end
- end
- end
- remote:FireServer("Grab", nil, nil, nil, nil) -- Requests the ID
- end
- else
- if cmd:sub(1,1) == "r" then -- Restart Minesweeper
- returnID()
- ignoreMessages = false
- end
- end
- end
- end)
- remote.OnClientEvent:Connect(function(action, newID) -- Server to Client stuff
- if action == "Sending" then -- When the server gives an ID
- idForPlr = newID -- Store the ID
- remote:FireServer("Board", widthChatRequest,heightChatRequest,mineChatRequest,idForPlr) -- Then request a board
- warn("Jump to start. Do not walk off the invisible platform you are on.")
- print("0-Transparent") -- Gives the player instructions on to what each color represents
- print("1-Blue")
- print("2-Green")
- print("3-Red")
- print("4-Purple")
- print("5-Crimson")
- print("6-Turquoise")
- print("7-Black")
- print("8-Gray")
- elseif action == "Recieving" then -- When the server requests for the ID
- returnID()
- ignoreMessages = false
- end
- end)
- chr:FindFirstChildOfClass("Humanoid").Died:Connect(function() -- If the humanoid dies, return the ID. Failsafe.
- returnID()
- script:Destroy()
- end)
- 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.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement