Advertisement
Scripting_King

Untitled

Dec 13th, 2024
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.95 KB | Source Code | 0 0
  1. --This script is from TDS game which I scripted few days ago
  2.  
  3.  
  4. local function spawnZombiesWithSpecialAbilities(roundNumber, mapName, RoundType, PlayerInRound)
  5.     local roundInfo = RoundData[RoundType][roundNumber]
  6.  
  7.     if not roundInfo then
  8.         warn("Round not found in data!")
  9.         return
  10.     end
  11.  
  12.     for zombieType, quantity in pairs(roundInfo) do
  13.         print("Spawning " .. quantity .. " " .. zombieType .. "(s) with abilities for Round " .. roundNumber)
  14.         if EndRound.ShouldEndSubrubanRounds == true then
  15.             break
  16.         end
  17.  
  18.         for i = 1, quantity do
  19.             if EndRound.ShouldEndSubrubanRounds == true then
  20.                 for _, child in pairs(workspace:FindFirstChild(mapName).SpawnedZombies:GetChildren()) do
  21.                     child:Destroy()
  22.                 end
  23.                 break
  24.             end
  25.  
  26.             local CloneZombie = ReplicatedStorage.Zombies:FindFirstChild(zombieType):Clone()
  27.             CloneZombie.Parent = workspace:FindFirstChild(mapName).SpawnedZombies
  28.             CloneZombie.HumanoidRootPart.CFrame = workspace:FindFirstChild(mapName).MovingPoints["1"].CFrame
  29.  
  30.             -- Apply random abilities to zombies for added challenge
  31.             local randomAbility = math.random(1, 3)
  32.             if randomAbility == 1 then
  33.                 CloneZombie.Humanoid.WalkSpeed = 50  -- Increased speed
  34.                 print(zombieType .. " gained speed boost!")
  35.             elseif randomAbility == 2 then
  36.                 CloneZombie.Humanoid.Health = CloneZombie.Humanoid.Health * 2  -- Increased health
  37.                 print(zombieType .. " gained extra health!")
  38.             elseif randomAbility == 3 then
  39.                 local damageBoost = Instance.new("NumberValue")
  40.                 damageBoost.Name = "DamageBoost"
  41.                 damageBoost.Value = 25  -- Increased damage output
  42.                 damageBoost.Parent = CloneZombie
  43.                 print(zombieType .. " gained damage boost!")
  44.             end
  45.  
  46.             wait(1.5)
  47.         end
  48.        
  49.         repeat
  50.             wait()
  51.         until #workspace:FindFirstChild(mapName).SpawnedZombies:GetChildren() == 0
  52.         if RoundType == "EasyRound" then
  53.             if roundNumber == EasyRoundLenght then
  54.                 for _, playerInRound in pairs(PlayerInRound) do
  55.                     playerInRound.PlayerGui.ShowRound.Enabled = false
  56.                     task.delay(3, function()
  57.                         playerInRound.Character.PrimaryPart.CFrame = workspace.Lobby.SpawnLocation.CFrame + Vector3.new(0, 2, 0)
  58.                         playerInRound.PlayerGui.RoundEndScreen.Frame.Visible = true
  59.                         playerInRound.PlayerGui.RoundEndScreen.Frame.TextLabel.Text = "You Won!"
  60.                         table.remove(PlayerInRound, table.find(PlayerInRound, playerInRound))
  61.                     end)
  62.                 end
  63.             end
  64.         end
  65.     end
  66. end
  67.  
  68. local function HandleRoundProgress(PlayerInRound, roundNumber, mapName, RoundType, RoundLenght)
  69.     local remainingTime = RoundLenght
  70.     local roundOver = false
  71.     local roundStartTime = tick()  -- Capture the time when the round starts
  72.  
  73.     -- Update the round timer on the player's UI
  74.     for _, playerInRound in pairs(PlayerInRound) do
  75.         playerInRound.PlayerGui.ShowRound.Frame.TextLabel.Text = "Round: " .. roundNumber
  76.     end
  77.  
  78.     -- Function to update the timer every second
  79.     local function updateTimer()
  80.         while remainingTime > 0 and not roundOver do
  81.             -- Calculate the elapsed time and update the remaining time
  82.             remainingTime = RoundLenght - math.floor(tick() - roundStartTime)
  83.             for _, playerInRound in pairs(PlayerInRound) do
  84.                 playerInRound.PlayerGui.ShowRound.Frame.TimerLabel.Text = "Time Left: " .. remainingTime .. "s"
  85.             end
  86.             wait(1)
  87.         end
  88.     end
  89.  
  90.     -- Function to check if round should end
  91.     local function checkEndRound()
  92.         -- If max damage reached or all zombies are defeated, end the round
  93.         if SuburbanSiege.CurrentDamage.Value >= SuburbanSiege.MaxDamage.Value then
  94.             for _, playerInRound in pairs(PlayerInRound) do
  95.                 playerInRound.PlayerGui.ShowRound.Enabled = false
  96.                 task.delay(3, function()
  97.                     playerInRound.Character.PrimaryPart.CFrame = workspace.Lobby.SpawnLocation.CFrame + Vector3.new(0, 2, 0)
  98.                     playerInRound.PlayerGui.RoundEndScreen.Frame.Visible = true
  99.                     playerInRound.PlayerGui.RoundEndScreen.Frame.TextLabel.Text = "You Defeated!"
  100.                     table.remove(PlayerInRound, table.find(PlayerInRound, playerInRound))
  101.                 end)
  102.             end
  103.             roundOver = true
  104.             EndRound.ShouldEndSubrubanRounds = true
  105.         elseif #workspace:FindFirstChild(mapName).SpawnedZombies:GetChildren() == 0 then
  106.             for _, playerInRound in pairs(PlayerInRound) do
  107.                 playerInRound.PlayerGui.ShowRound.Enabled = false
  108.                 task.delay(3, function()
  109.                     playerInRound.Character.PrimaryPart.CFrame = workspace.Lobby.SpawnLocation.CFrame + Vector3.new(0, 2, 0)
  110.                     playerInRound.PlayerGui.RoundEndScreen.Frame.Visible = true
  111.                     playerInRound.PlayerGui.RoundEndScreen.Frame.TextLabel.Text = "You Won!"
  112.                     table.remove(PlayerInRound, table.find(PlayerInRound, playerInRound))
  113.                 end)
  114.             end
  115.             roundOver = true
  116.             EndRound.ShouldEndSubrubanRounds = true
  117.         end
  118.     end
  119.  
  120.     -- Start updating the timer in a separate thread
  121.     spawn(updateTimer)
  122.  
  123.     -- Spawn zombies for the round
  124.     spawn(function()
  125.         spawnZombiesForRound(roundNumber, mapName, RoundType, PlayerInRound)
  126.     end)
  127.    
  128.     spawn(function()
  129.         HandleRoundProgress(PlayerInRound, i, "suburban_siege", RoundType, RoundLenght)
  130.     end)
  131.  
  132.     -- Continuously check for conditions that would end the round
  133.     spawn(function()
  134.         while not roundOver do
  135.             checkEndRound()
  136.             wait(1)
  137.         end
  138.     end)
  139.  
  140.     -- Wait for the round to end
  141.     repeat
  142.         wait(1)
  143.     until roundOver
  144.  
  145.     -- Perform any final actions or cleanup after the round ends
  146.     print("Round " .. roundNumber .. " has ended.")
  147. end
  148.  
  149. -- Track player progress through rounds and assign rewards
  150. local function trackPlayerProgress(roundNumber, mapName, RoundType, PlayerInRound)
  151.     local roundInfo = RoundData[RoundType][roundNumber]
  152.  
  153.     if not roundInfo then
  154.         warn("Round not found in data!")
  155.         return
  156.     end
  157.  
  158.     for zombieType, quantity in pairs(roundInfo) do
  159.         if EndRound.ShouldEndSubrubanRounds == true then
  160.             break
  161.         end
  162.  
  163.         for _, playerInRound in pairs(PlayerInRound) do
  164.             local progress = playerInRound:FindFirstChild("RoundProgress")
  165.             if not progress then
  166.                 progress = Instance.new("IntValue")
  167.                 progress.Name = "RoundProgress"
  168.                 progress.Parent = playerInRound
  169.             end
  170.  
  171.             progress.Value = progress.Value + quantity
  172.             playerInRound.PlayerGui.ShowRound.Frame.TextLabel.Text = "Progress: " .. progress.Value .. "/" .. roundInfo[zombieType]
  173.  
  174.             -- Reward players based on their progress
  175.             if progress.Value == roundInfo[zombieType] then
  176.                 playerInRound:FindFirstChild("Stats"):FindFirstChild("Currency").Value = playerInRound.Stats.Currency.Value + 10
  177.                 playerInRound.PlayerGui.ShowRound.Frame.TextLabel.Text = "Reward: 10 Coins!"
  178.                 progress.Value = 0  -- Reset progress after reward
  179.             end
  180.         end
  181.     end
  182. end
  183.  
  184. -- NPC behavior
  185. local function enhanceNpcBehavior(npc)
  186.     -- Random chance to trigger a special attack
  187.     local specialAttackChance = math.random(1, 5)
  188.     if specialAttackChance == 1 then
  189.         local specialAttack = Instance.new("Part")
  190.         specialAttack.Size = Vector3.new(5, 1, 5)
  191.         specialAttack.Position = npc.HumanoidRootPart.Position + Vector3.new(0, 10, 0)
  192.         specialAttack.Anchored = true
  193.         specialAttack.BrickColor = BrickColor.new("Bright red")
  194.         specialAttack.Parent = workspace
  195.         game:GetService("Debris"):AddItem(specialAttack, 3)
  196.         print("Special attack triggered by " .. npc.Name)
  197.        
  198.         -- Apply damage to players in range of the special attack
  199.         for _, player in pairs(workspace.Players:GetChildren()) do
  200.             if player.Character and (player.Character.HumanoidRootPart.Position - specialAttack.Position).Magnitude < 10 then
  201.                 player.Character.Humanoid:TakeDamage(50)  -- Deal 50 damage
  202.                 print(player.Name .. " took damage from special attack!")
  203.             end
  204.         end
  205.     end
  206. end
  207.  
  208. -- Handle player interaction with teleporter zones and special zones
  209. for i, container in pairs(TeleportZones.SuburanSiegeTeleporter:GetChildren()) do
  210.     local Timer = BaseTimer
  211.     local Owner
  212.     local EnteredPlayer = {}
  213.     local PlayerInRound = {}
  214.     local Connection = nil
  215.    
  216.     EndRound.ShouldEndSubrubanRounds = false
  217.    
  218.     if container:IsA("BasePart") then
  219.         local zone = ZoneModule.new(container)
  220.  
  221.         zone.playerEntered:Connect(function(player)
  222.             table.insert(EnteredPlayer, player)
  223.             container.PlayersUI.BillboardGui.TextLabel.Text = #EnteredPlayer.."/"..MinimumPlayerRequired
  224.             if not Owner then
  225.                 Owner = player
  226.                 Timer = BaseTimer
  227.                 while Timer >= 0 do
  228.                     if not Owner then break end
  229.                     print(Timer)
  230.                     wait(1)
  231.                     Timer -= 1
  232.                 end
  233.                 if not Owner then return end
  234.                 print("Timer Finished")
  235.                 for _, PlayerToTeleport : Player in pairs(EnteredPlayer) do
  236.                     table.insert(PlayerInRound, PlayerToTeleport)
  237.                     PlayerToTeleport.Character.PrimaryPart.CFrame = SuburbanSiege.SpawnPoints:GetChildren()[math.random(1, #SuburbanSiege.SpawnPoints:GetChildren())].CFrame
  238.                     PlayerToTeleport.PlayerGui.ShowRound.Enabled = true
  239.                 end
  240.                 Connection = nil
  241.             end
  242.             SuburbanSiege.CurrentDamage.Value = 0
  243.             EndRound.ShouldEndSubrubanRounds = false
  244.             if container.Name == "EasyZone" then
  245.                 spawn(function()
  246.                     HandleRounds(Connection, PlayerInRound, EasyRoundLenght, "EasyRound")
  247.                 end)
  248.             elseif container.Name == "MediumZone" then
  249.                 spawn(function()
  250.                     HandleRounds(Connection, PlayerInRound, MediumRoundLenght, "MediumRound")
  251.                 end)
  252.             elseif container.Name == "HardZone" then
  253.                 spawn(function()
  254.                     HandleRounds(Connection, PlayerInRound, EasyRoundLenght, "HardRound")
  255.                 end)
  256.             elseif container.Name == "ExtremeZone" then
  257.                 spawn(function()
  258.                     HandleRounds(Connection, PlayerInRound, EasyRoundLenght, "ExtremeRound")
  259.                 end)
  260.             end
  261.         end)
  262.  
  263.         zone.playerExited:Connect(function(player)
  264.             local find = table.find(EnteredPlayer, player)
  265.             table.remove(EnteredPlayer, find)
  266.             if player == Owner then
  267.                 Owner = nil
  268.             end
  269.             container.PlayersUI.BillboardGui.TextLabel.Text = #EnteredPlayer.."/"..MinimumPlayerRequired
  270.         end)
  271.     end
  272. end
  273.  
  274. -- Monitor and notify if any player exceeds the maximum rounds played
  275. local function monitorMaxRounds(PlayerInRound)
  276.     for _, player in pairs(PlayerInRound) do
  277.         local roundsPlayed = player:FindFirstChild("RoundsPlayed")
  278.         if not roundsPlayed then
  279.             roundsPlayed = Instance.new("IntValue")
  280.             roundsPlayed.Name = "RoundsPlayed"
  281.             roundsPlayed.Parent = player
  282.         end
  283.  
  284.         if roundsPlayed.Value >= 5 then
  285.             player:Kick("You have exceeded the maximum number of rounds allowed!")
  286.             print(player.Name .. " has been kicked for exceeding max rounds played.")
  287.         end
  288.     end
  289. end
  290.  
  291. -- Call function to track progress for each round
  292. for i, container in pairs(TeleportZones.SuburanSiegeTeleporter:GetChildren()) do
  293.     local Timer = BaseTimer
  294.     local Owner
  295.     local EnteredPlayer = {}
  296.     local PlayerInRound = {}
  297.  
  298.     monitorMaxRounds(PlayerInRound)
  299. end
  300.  
Tags: #scripting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement