Advertisement
alexop1000

Best script

Dec 13th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.15 KB | None | 0 0
  1. local badgeModule   = require(game.ReplicatedStorage.Modules.BadgeModule)
  2. local gameSettings  = game.ReplicatedStorage.GameSettings
  3. local gamePoints    = game.ReplicatedStorage.GamePoints
  4. local maps          = game.ServerStorage.Maps
  5.  
  6. local lastMap = ""
  7.  
  8. local function LoadMap()
  9.     -- Map voting goes here
  10.     gameSettings.RoundType.Value = "LOADING MAP"
  11.     local m = ""
  12.     repeat
  13.         m = maps:GetChildren()[math.random(#maps:GetChildren())].Name
  14.         wait(0.1)
  15.     until m ~= lastMap
  16.     lastMap = m
  17.     local map = maps[m]:Clone()
  18.     map.Name = "Map"
  19.     map.Parent = game.Workspace
  20.     local function change(obj)
  21.         for _, v in pairs(obj:GetChildren()) do
  22.             if v:IsA("BasePart") then
  23.                 v.CustomPhysicalProperties = PhysicalProperties.new(1, 4, 0)
  24.             else
  25.                 change(v)
  26.             end
  27.         end
  28.     end
  29.    
  30.     change(map)
  31.     -- Replace this with a way to wait for all the clients to load the map
  32.     wait(5)
  33.    
  34.     return map
  35. end
  36.  
  37. local rounds = {
  38.     -- FFA
  39.     FFA = function()
  40.         gameSettings.RoundType.Value = "FFA"
  41.         local winner
  42.         for _, p in pairs(game.Players:GetPlayers()) do
  43.             p.TeamColor = BrickColor.new("White")
  44.             p.Neutral = true
  45.             local pts = Instance.new("NumberValue")
  46.                 pts.Name = p.Name
  47.                 pts.Parent = gamePoints
  48.         end
  49.        
  50.         local pa = game.Players.PlayerAdded:connect(function(player)
  51.             player.TeamColor = BrickColor.new("White")
  52.             player.Neutral = true
  53.             local pts = Instance.new("NumberValue")
  54.                 pts.Name = player.Name
  55.                 pts.Parent = gamePoints
  56.         end)
  57.        
  58.         local pl = game.Players.PlayerRemoving:connect(function(player)
  59.             gamePoints[player.Name]:Destroy()
  60.         end)
  61.        
  62.         local pkp
  63.         pkp = game.ReplicatedStorage.Events.PlayerKilledPlayer.Event:connect(function(a, b)
  64.             gamePoints[a.Name].Value = gamePoints[a.Name].Value + 1
  65.             if gamePoints[a.Name].Value >= 30 then
  66.                 badgeModule.AwardBadge(a, "Win")
  67.                 winner = a
  68.                 pkp:disconnect()
  69.             end
  70.         end)
  71.        
  72.         gameSettings.SpawnEnabled.Value = true
  73.         gameSettings.Timer.Value = 360
  74.         repeat
  75.             gameSettings.Timer.Value = gameSettings.Timer.Value - 1
  76.             wait(1)
  77.         until gameSettings.Timer.Value == 0 or winner
  78.         pa:disconnect()
  79.         pl:disconnect()
  80.         pkp:disconnect()
  81.         if winner then
  82.             gameSettings.RoundType.Value = string.upper(winner.Name) .. " WINS"
  83.             wait(5)
  84.         else
  85.             local winner = gamePoints:GetChildren()[1]
  86.             for _, v in pairs(gamePoints:GetChildren()) do
  87.                 if v.Value > winner.Value then
  88.                     winner = v
  89.                 end
  90.             end
  91.             winner = winner.Name
  92.             if game.Players:FindFirstChild(winner) then
  93.                 badgeModule.AwardBadge(game.Players[winner], "Win")
  94.             end
  95.             gameSettings.RoundType.Value = string.upper(winner) .. " WINS"
  96.             wait(5)
  97.         end
  98.         --wait(2)
  99.     end;
  100.     -- TDM
  101.     TDM = function()
  102.         gameSettings.RoundType.Value = "TDM"
  103.         local players = game.Players:GetPlayers()
  104.         local scrambled = {}
  105.         repeat
  106.             local i = math.random(#players)
  107.             table.insert(scrambled, players[i])
  108.             table.remove(players, i)
  109.         until #players == 0
  110.         for i, player in pairs(scrambled) do
  111.             player.Neutral = false
  112.             if i % 2 == 0 then
  113.                 player.TeamColor = BrickColor.new("Bright blue")
  114.             else
  115.                 player.TeamColor = BrickColor.new("Bright red")
  116.             end
  117.         end
  118.         local pa = game.Players.PlayerAdded:connect(function(player)
  119.             player.Neutral = false
  120.             local a, b = 0, 0
  121.             for _, p in pairs(game.Players:GetPlayers()) do
  122.                 if p ~= player then
  123.                     if p.TeamColor == BrickColor.new("Bright blue") then
  124.                         a = a + 1
  125.                     else
  126.                         b = b + 1
  127.                     end
  128.                 end
  129.             end
  130.             if a > b then
  131.                 player.TeamColor = BrickColor.new("Bright red")
  132.             else
  133.                 player.TeamColor = BrickColor.new("Bright blue")
  134.             end
  135.         end)
  136.        
  137.         local aPts = Instance.new("NumberValue")
  138.             aPts.Name = "Bright blue"
  139.             aPts.Parent = gamePoints
  140.         local bPts = Instance.new("NumberValue")
  141.             bPts.Name = "Bright red"
  142.             bPts.Parent = gamePoints
  143.        
  144.         local pkp = game.ReplicatedStorage.Events.PlayerKilledPlayer.Event:connect(function(a, b)
  145.             if a.TeamColor == BrickColor.new("Bright blue") then
  146.                 aPts.Value = aPts.Value + 1
  147.             else
  148.                 bPts.Value = bPts.Value + 1
  149.             end
  150.         end)
  151.        
  152.         gameSettings.SpawnEnabled.Value = true
  153.         gameSettings.Timer.Value = 360
  154.         repeat
  155.             gameSettings.Timer.Value = gameSettings.Timer.Value - 1
  156.             wait(1)
  157.         until gameSettings.Timer.Value == 0 or aPts.Value >= 50 or bPts.Value >= 50
  158.         pa:disconnect()
  159.         pkp:disconnect()
  160.         if aPts.Value > bPts.Value then
  161.             for _, p in pairs(game.Players:GetPlayers()) do
  162.                 if p.TeamColor == BrickColor.new(aPts.Name) then
  163.                     badgeModule.AwardBadge(p, "Win")
  164.                 end
  165.             end
  166.             gameSettings.RoundType.Value = "BLUE TEAM WINS"
  167.             wait(5)
  168.         elseif bPts.Value > aPts.Value then
  169.             for _, p in pairs(game.Players:GetPlayers()) do
  170.                 if p.TeamColor == BrickColor.new(bPts.Name) then
  171.                     badgeModule.AwardBadge(p, "Win")
  172.                 end
  173.             end
  174.             gameSettings.RoundType.Value = "RED TEAM WINS"
  175.             wait(5)
  176.         else
  177.             gameSettings.RoundType.Value = "TIE"
  178.             wait(5)
  179.         end
  180.        
  181.     end;
  182.     -- KOTH
  183.     KOTH = function()
  184.         gameSettings.RoundType.Value = "KOTH"
  185.         local players = game.Players:GetPlayers()
  186.         local scrambled = {}
  187.         repeat
  188.             local i = math.random(#players)
  189.             table.insert(scrambled, players[i])
  190.             table.remove(players, i)
  191.         until #players == 0
  192.         for i, player in pairs(scrambled) do
  193.             player.Neutral = false
  194.             if i % 2 == 0 then
  195.                 player.TeamColor = BrickColor.new("Bright blue")
  196.             else
  197.                 player.TeamColor = BrickColor.new("Bright red")
  198.             end
  199.         end
  200.         local pa = game.Players.PlayerAdded:connect(function(player)
  201.             player.Neutral = false
  202.             local a, b = 0, 0
  203.             for _, p in pairs(game.Players:GetPlayers()) do
  204.                 if p ~= player then
  205.                     if p.TeamColor == BrickColor.new("Bright blue") then
  206.                         a = a + 1
  207.                     else
  208.                         b = b + 1
  209.                     end
  210.                 end
  211.             end
  212.             if a > b then
  213.                 player.TeamColor = BrickColor.new("Bright red")
  214.             else
  215.                 player.TeamColor = BrickColor.new("Bright blue")
  216.             end
  217.         end)
  218.        
  219.         local aPts = Instance.new("NumberValue")
  220.             aPts.Name = "Bright blue"
  221.             aPts.Parent = gamePoints
  222.         local bPts = Instance.new("NumberValue")
  223.             bPts.Name = "Bright red"
  224.             bPts.Parent = gamePoints
  225.        
  226.         local function GetPlayersInRadius(point, radius)
  227.             local players = {}
  228.            
  229.             for _, player in pairs(game.Players:GetPlayers()) do
  230.                 if player.Character and player.Character.Parent and player.Character:FindFirstChild("HumanoidRootPart") and player.Character.Humanoid.Health > 0 then
  231.                     local distance = (point - player.Character.HumanoidRootPart.Position).magnitude
  232.                     if distance <= radius then
  233.                         table.insert(players, player)
  234.                     end
  235.                 end
  236.             end
  237.            
  238.             return players
  239.         end
  240.        
  241.         -- ADD SOME GAMEMODE STUFF HERE
  242.        
  243.         local requiredPoints = 500
  244.        
  245.         local hill = game.Workspace:FindFirstChild("KOTHHILL", true)
  246.         local point = game.ReplicatedStorage.Objects.KOTHPoint:Clone()
  247.         point.Parent = hill.Parent
  248.         point:SetPrimaryPartCFrame(hill.CFrame * CFrame.new(0, 1.6, 0))
  249.        
  250.         gameSettings.SpawnEnabled.Value = true
  251.         gameSettings.Timer.Value = 360
  252.         repeat
  253.             gameSettings.Timer.Value = gameSettings.Timer.Value - 1
  254.            
  255.             local players = GetPlayersInRadius(point.PrimaryPart.Position, 40)
  256.             local blue, red = 0, 0
  257.             local color = BrickColor.new("White")
  258.            
  259.             for _, player in pairs(players) do
  260.                 if player.TeamColor == BrickColor.new("Bright blue") then
  261.                     blue = blue + 1
  262.                 elseif player.TeamColor == BrickColor.new("Bright red") then
  263.                     red = red + 1
  264.                 end
  265.                 if gameSettings.Timer.Value % 6 == 0 then
  266.                     badgeModule.AwardBadge(player, "Holding Hill")
  267.                 end
  268.             end
  269.            
  270.             if blue > 0 or red > 0 then
  271.                 if blue == red then
  272.                     color = BrickColor.new("Magenta")
  273.                 elseif blue > red then
  274.                     color = BrickColor.new("Bright blue")
  275.                     aPts.Value = aPts.Value + blue - red
  276.                 elseif red > blue then
  277.                     color = BrickColor.new("Bright red")
  278.                     bPts.Value = bPts.Value + red - blue
  279.                 end
  280.             end
  281.            
  282.             for _, v in pairs(point:GetChildren()) do
  283.                 if v:IsA("BasePart") then
  284.                     v.BrickColor = color
  285.                 end
  286.             end
  287.            
  288.             point.Crystal.BillboardGui.ImageLabel.ImageColor3 = color.Color
  289.            
  290.             wait(1)
  291.         until gameSettings.Timer.Value == 0 or aPts.Value >= requiredPoints or bPts.Value >= requiredPoints
  292.         pa:disconnect()
  293.         --pkp:disconnect()
  294.         if aPts.Value > bPts.Value then
  295.             for _, p in pairs(game.Players:GetPlayers()) do
  296.                 if p.TeamColor == BrickColor.new(aPts.Name) then
  297.                     badgeModule.AwardBadge(p, "Win")
  298.                 end
  299.             end
  300.             gameSettings.RoundType.Value = "BLUE TEAM WINS"
  301.             wait(5)
  302.         elseif bPts.Value > aPts.Value then
  303.             for _, p in pairs(game.Players:GetPlayers()) do
  304.                 if p.TeamColor == BrickColor.new(bPts.Name) then
  305.                     badgeModule.AwardBadge(p, "Win")
  306.                 end
  307.             end
  308.             gameSettings.RoundType.Value = "RED TEAM WINS"
  309.             wait(5)
  310.         else
  311.             gameSettings.RoundType.Value = "TIE"
  312.             wait(5)
  313.         end
  314.        
  315.     end;
  316. }
  317.  
  318. local rewards = {
  319.     ["Weapon Crate"] = 4;
  320.     ["Armor Crate"] = 6;
  321.     ["Equipment Crate"] = 1;
  322. }
  323.  
  324. local weightedRewards = {}
  325.  
  326. for r, n in pairs(rewards) do
  327.     for i = 1, n do
  328.         table.insert(weightedRewards, r)
  329.     end
  330. end
  331.  
  332. local function NewRound()
  333.     local oldMap = game.Workspace:FindFirstChild("Map")
  334.     if oldMap then
  335.         oldMap:Destroy()
  336.     end
  337.    
  338.     local map = LoadMap()
  339.    
  340.     local gamemodes = {}
  341.     for _, v in pairs(map.Gamemodes:GetChildren()) do
  342.         table.insert(gamemodes, v.Name)
  343.     end
  344.    
  345.     rounds[gamemodes[math.random(#gamemodes)]]()
  346.     gameSettings.SpawnEnabled.Value = false
  347.     for _, player in pairs(game.Players:GetPlayers()) do
  348.         local playerData = game.ReplicatedStorage.Data:FindFirstChild(player.Name)
  349.             if playerData then
  350.             if playerData.Playing.Value then
  351.                 playerData.Playing.Value = false
  352.                
  353.                 game.ServerScriptService.SpawnScript.LoadCharacter:Fire(player)
  354.             end
  355.             local reward = weightedRewards[math.random(#weightedRewards)]
  356.             playerData.GameStats.Reward.Value = reward
  357.            
  358.             if playerData.Crates:FindFirstChild(reward) then
  359.                 playerData.Crates[reward].Value = playerData.Crates[reward].Value + 1
  360.             else
  361.                 local c = Instance.new("NumberValue")
  362.                     c.Name = reward
  363.                     c.Value = 1
  364.                     c.Parent = playerData.Crates
  365.             end
  366.         end
  367.     end
  368.     wait(1)
  369.     game.ReplicatedStorage.Remotes.RoundEnd:FireAllClients()
  370. end
  371.  
  372. while true do
  373.     if game.Players.NumPlayers > 0 then
  374.         NewRound()
  375.     end
  376.     for _, player in pairs(game.Players:GetPlayers()) do
  377.         local playerData = game.ReplicatedStorage.Data:FindFirstChild(player.Name)
  378.         if playerData then
  379.             local score = badgeModule.CalculatePoints(player)
  380.             playerData.Credits.Value = playerData.Credits.Value + score
  381.            
  382.            
  383.         end
  384.     end
  385.    
  386.     for _, v in pairs(game.Workspace:GetChildren()) do
  387.         if v.Name == "Turret" then
  388.             v:Destroy()
  389.         end
  390.     end
  391.     game.ServerScriptService.CrateScript.Disabled = true
  392.     game.Workspace.Crates:ClearAllChildren()
  393.    
  394.     gameSettings.RoundType.Value = "INTERMISSION"
  395.     gameSettings.Timer.Value = 20
  396.     repeat
  397.         gameSettings.Timer.Value = gameSettings.Timer.Value - 1
  398.         wait(1)
  399.     until gameSettings.Timer.Value == 0
  400.     game.ServerScriptService.CrateScript.Disabled = false
  401.    
  402.     gamePoints:ClearAllChildren()
  403.     for _, d in pairs(game.ReplicatedStorage.Data:GetChildren()) do
  404.         d.GameStats.Streak.Value = 0
  405.         d.GameStats.Kills.Value = 0
  406.         d.GameStats.Deaths.Value = 0
  407.         d.GameStats.LastKiller.Value = nil
  408.         d.GameStats.Badges:ClearAllChildren()
  409.     end
  410. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement