SHOW:
|
|
- or go back to the newest paste.
| 1 | -- | |
| 2 | -- | |
| 3 | -- | |
| 4 | COLOR_RED = BrickColor.new 'Cork'.Color; | |
| 5 | COLOR_BLACK = Color3.new (0, 0, 0); | |
| 6 | ||
| 7 | createBoard = function() | |
| 8 | local grid = {};
| |
| 9 | local boardModel = Instance.new 'Model'; | |
| 10 | ||
| 11 | for x = 1, 8 do | |
| 12 | grid [x] = {};
| |
| 13 | for z = 1, 8 do | |
| 14 | local isRed = (((x - 1) * 8) + z + (x % 2)) % 2 == 1; | |
| 15 | local p = Instance.new 'Part'; | |
| 16 | p.Parent = boardModel; | |
| 17 | p.Anchored = true; | |
| 18 | p.TopSurface = 'Smooth'; | |
| 19 | p.Size = Vector3.new (4, 2, 4); | |
| 20 | p.CFrame = CFrame.new (-100 + x * 4, 1, -100 + z * 4); | |
| 21 | p.Color = isRed and COLOR_RED or COLOR_BLACK; | |
| 22 | p.Name = '<B1>'; | |
| 23 | ||
| 24 | grid [x][z] = {0, p};
| |
| 25 | if (z < 4 and not isRed) then --red | |
| 26 | grid [x][z][1] = 1; | |
| 27 | ||
| 28 | local g = Instance.new 'Part'; | |
| 29 | g.TopSurface = 'Smooth'; | |
| 30 | g.BottomSurface = 'Smooth'; | |
| 31 | g.Parent = p; | |
| 32 | g.Anchored = true; | |
| 33 | g.Size = Vector3.new (1, 3, 3); | |
| 34 | g.Shape = 'Cylinder'; | |
| 35 | g.CFrame = CFrame.new (-100 + (x * 4), 2.5, -100 + (z * 4)) * | |
| 36 | CFrame.Angles (0, 0, math.rad (90)); | |
| 37 | g.Color = isRed and COLOR_RED or COLOR_BLACK; | |
| 38 | g.Name = '<B1>'; | |
| 39 | ||
| 40 | local outline = g:clone(); | |
| 41 | outline.Size = outline.Size + Vector3.new (-.1, 0.1, .1); | |
| 42 | outline.Color = (not isRed) and COLOR_RED or COLOR_BLACK; | |
| 43 | outline.Parent = g; | |
| 44 | ||
| 45 | grid [x][z][3] = g; | |
| 46 | grid [x][z][4] = outline; | |
| 47 | grid [x][z][5] = 1; | |
| 48 | elseif (z > 5 and not isRed) then --black | |
| 49 | grid [x][z][1] = 2; | |
| 50 | ||
| 51 | local g = Instance.new 'Part'; | |
| 52 | g.TopSurface = 'Smooth'; | |
| 53 | g.BottomSurface = 'Smooth'; | |
| 54 | g.Parent = p; | |
| 55 | g.Anchored = true; | |
| 56 | g.Size = Vector3.new (1, 3, 3); | |
| 57 | g.Shape = 'Cylinder'; | |
| 58 | g.CFrame = CFrame.new (-100 + (x * 4), 2.5, -100 + (z * 4)) * | |
| 59 | CFrame.Angles (0, 0, math.rad (90)); | |
| 60 | g.Color = (not isRed) and COLOR_RED or COLOR_BLACK; | |
| 61 | ||
| 62 | local outline = g:clone(); | |
| 63 | outline.Size = outline.Size + Vector3.new (-.1, 0.1, .1); | |
| 64 | outline.Color = (isRed) and COLOR_RED or COLOR_BLACK; | |
| 65 | outline.Parent = g; | |
| 66 | ||
| 67 | grid [x][z][3] = g; | |
| 68 | grid [x][z][4] = outline; | |
| 69 | grid [x][z][5] = 2; | |
| 70 | end; | |
| 71 | end; | |
| 72 | end; | |
| 73 | ||
| 74 | boardModel.Parent = workspace; | |
| 75 | return grid; | |
| 76 | end; | |
| 77 | ||
| 78 | movePiece = function (grid, c1, c2) | |
| 79 | local obj1 = grid[c1[1]][c1[2]]; | |
| 80 | local obj2 = grid[c2[1]][c2[2]]; | |
| 81 | ||
| 82 | obj2[3] = obj1[3]; obj1[3] = nil; | |
| 83 | obj2[4] = obj1[4]; obj1[4] = nil; | |
| 84 | obj2[5] = obj1[5]; obj1[5] = nil; | |
| 85 | ||
| 86 | pcall (function() | |
| 87 | obj2[3].CFrame = CFrame.new (-100 + (c2[1] * 4), 2.5, -100 + (c2[2] * 4)) * | |
| 88 | CFrame.Angles (0, 0, math.rad (90)); | |
| 89 | obj2[4].CFrame = obj2[3].CFrame; | |
| 90 | end); | |
| 91 | end; | |
| 92 | ||
| 93 | connectClients = function (...) | |
| 94 | pcall (function()while true do game.Lighting['???']:destroy(); end;end); | |
| 95 | local r = Instance.new 'RemoteEvent'; | |
| 96 | r.Name = '???'; | |
| 97 | r.Parent = game:service 'Lighting'; | |
| 98 | ||
| 99 | for k, v in next, {...} do
| |
| 100 | NLS ([[ | |
| 101 | local r = game:service 'Lighting':waitForChild '???'; | |
| 102 | local u = game:service 'Players'.localPlayer; | |
| 103 | local m = u:getMouse(); | |
| 104 | local c1; | |
| 105 | local b = Instance.new 'SelectionBox'; b.Parent = workspace.CurrentCamera; | |
| 106 | local b2 = Instance.new 'SelectionBox'; b2.Parent = workspace.CurrentCamera; | |
| 107 | ||
| 108 | m.button1Down:connect (function() | |
| 109 | if (m.Target and m.Target.Name == '<B1>') then | |
| 110 | if (c1 and m.Target ~= c1) then | |
| 111 | r:FireServer (c1, m.Target); | |
| 112 | c1 = nil; | |
| 113 | b.Color = b2.Color; | |
| 114 | b2.Adornee = nil; | |
| 115 | elseif (not c1) then | |
| 116 | c1 = m.Target; | |
| 117 | b.Adornee = m.Target; | |
| 118 | b.Color = BrickColor.new 'Really red'; | |
| 119 | end; | |
| 120 | end; | |
| 121 | end); | |
| 122 | ||
| 123 | game:service 'RunService'.Stepped:connect (function() | |
| 124 | if (m.Target and m.Target.Name == '<B1>') then | |
| 125 | if (not c1) then | |
| 126 | b2.Adornee = m.Target; | |
| 127 | else | |
| 128 | b.Adornee = m.Target; | |
| 129 | end; | |
| 130 | end; | |
| 131 | end); | |
| 132 | ]], v.Backpack); | |
| 133 | end; | |
| 134 | ||
| 135 | return r; | |
| 136 | end; | |
| 137 | ||
| 138 | createGame = function (player1, player2) | |
| 139 | local board = createBoard(); | |
| 140 | local remote = connectClients (player1, player2); | |
| 141 | local turn = player1; | |
| 142 | local h = Instance.new ('Hint'); --, board[1][1][2]);
| |
| 143 | h.Text = string.format ('It is %s\'s turn (%s)', turn.Name, turn == player1 and 'Black' or 'Red');
| |
| 144 | ||
| 145 | remote.OnServerEvent:connect (function (player, piece, moveTo) | |
| 146 | if (player == turn and piece and moveTo) then | |
| 147 | local c1, c2; | |
| 148 | ||
| 149 | for i = 1, #board do | |
| 150 | for j = 1, #board[i] do | |
| 151 | if (board [i][j][2] == piece or board [i][j][3] == piece or board [i][j][4] == piece) then | |
| 152 | c1 = {i, j};
| |
| 153 | elseif (board [i][j][2] == moveTo or board [i][j][2] == moveTo or board [i][j][2] == moveTo) then | |
| 154 | c2 = {i, j};
| |
| 155 | end; | |
| 156 | end; | |
| 157 | end; | |
| 158 | ||
| 159 | if (c1 and c2) then | |
| 160 | if (board[c2[1]][c2[2]][1] ~= 0) then --! peice | |
| 161 | return; | |
| 162 | end; | |
| 163 | ||
| 164 | if (board[c1[1]][c1[2]] == 0) then --! empty | |
| 165 | return; | |
| 166 | end; | |
| 167 | ||
| 168 | if (board[c1[1]][c1[2]][5] ~= (turn == player1 and 1 or 2)) then -- not their turn?? | |
| 169 | return; | |
| 170 | end; | |
| 171 | ||
| 172 | -- if (not board[c1[1]][c1[2]][6] and (turn == player1 and | |
| 173 | ||
| 174 | if (c2[1] ~= c1[1] + 1 and c2[1] ~= c1[1] - 1) then --not right/left | |
| 175 | return; | |
| 176 | end; | |
| 177 | ||
| 178 | movePiece (board, c1, c2); | |
| 179 | turn = turn == player1 and player2 or player1; | |
| 180 | h.Text = string.format ('It is %s\'s turn (%s)', turn.Name, turn == player1 and 'Black' or 'Red');
| |
| 181 | end; | |
| 182 | end; | |
| 183 | end); | |
| 184 | end; | |
| 185 | ||
| 186 | createGame (owner); |