Guest User

Untitled

a guest
Jul 9th, 2019
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. local Path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(workspace.Start.Position,workspace.Wall.Position+ Vector3.new(3,0,0),500) -- PathFinding
  2. local Positions = Path:GetPointCoordinates()
  3. --[[ = Vector3.new(0, 0, 0)
  4.  
  5. x = 200 -- range from origin
  6.  
  7. y = 15 -- whatever height you want
  8.  
  9. p = part
  10. ]]--
  11. math.randomseed(os.time())-- No Clue
  12. -- Variables
  13.  
  14. RSP = math.random(1,360)
  15. local EnemyGroup = game:GetService("PhysicsService"):CreateCollisionGroup("Enemies")
  16. local PlayerGroup = game:GetService("PhysicsService"):CreateCollisionGroup("Players")
  17. game:GetService("PhysicsService"):CollisionGroupSetCollidable("Enemies","Players",false)
  18. game:GetService("PhysicsService"):CollisionGroupSetCollidable("Players","Players",false)
  19. game:GetService("PhysicsService"):CollisionGroupSetCollidable("Enemies","Enemies",false)
  20.  
  21.  
  22.  
  23. local function Bounty(Enemy) -- Controls the Leaderboard and buying fuction for towers. E.g., "50 Cash" Remember to add UNITS LATER!
  24. local Total = Enemy.Bounty.Value
  25.  
  26. for i,Tag in pairs(Enemy.Credit:GetChildren()) do
  27. local Player = game.Players:FindFirstChild(Tag.Name)
  28. if Player then
  29. local Percent = Tag.Value / Enemy.MaxHealth.Value
  30. local Reward = math.ceil(Total * Percent)
  31. Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + Reward
  32. end
  33. end
  34. end
  35. -- CODE SEPERATOR --
  36. local function SpawnEnemy(Type) -- whenever SpawnEnemy is used, play everything below.
  37. local Enemy = game.ServerStorage.Enemies:FindFirstChild(Type):Clone() -- Variable for Enemy, find the Enemy folder get the Firsh Child, then clone.
  38. local Alive = true -- Variable for true.
  39. Enemy.Parent = workspace.Enemies -- Variable for Enemy.Parent as the enimes in reality.
  40.  
  41. for i,Child in pairs(Enemy:GetChildren()) do -- for the Enemy's children
  42. if Child:IsA("BasePart") then -- if Enemy's Children are BaseParts then
  43. Child.CanCollide = false -- set colliable to false
  44. end
  45. end
  46. local Objective -- Variable for Objective
  47.  
  48. local RSP = math.random(1,3)
  49. if RSP == 1 then
  50. ABC = workspace.ABC1
  51. else ABC = workspace.ABC2
  52. if RSP == 3 then
  53. ABC = workspace.ABC3
  54. end
  55. end
  56. Enemy.HumanoidRootPart.CFrame = ABC.CFrame + Vector3.new(math.random(-4,4),0,math.random(-4,4))
  57.  
  58. local Index = 0
  59.  
  60. local function NextObjective(Success)
  61. if Success then
  62. Index = Index + 1
  63. end
  64. if Positions[Index] then -- [B]
  65. Enemy.Humanoid:MoveTo(Positions[Index])
  66. Objective = Positions[Index]
  67. else
  68. local Explode = Instance.new("Explosion",workspace)
  69. Explode.Position = Enemy.HumanoidRootPart.Position
  70. Explode.BlastPressure = 0
  71. workspace.Wall.Health.Value = workspace.Wall.Health.Value - Enemy.Damage.Value
  72. Alive = false
  73. Enemy:Destroy() -- [B]
  74. end
  75. end
  76.  
  77. NextObjective(true)
  78. Enemy.Humanoid.MoveToFinished:connect(function(Reached)
  79. -- if they are *close enough* consider it as good as the real deal?
  80. if not Reached then
  81. if (Enemy.HumanoidRootPart.Position - Objective).magnitude < 4 then
  82. print("Reached override")
  83. Reached = true
  84. end
  85. end
  86. NextObjective(Reached)
  87. end)
  88.  
  89. Enemy.Health.Changed:connect(function() -- When the enimies health is changed, and the connection is etablished:
  90. if Enemy.Health.Value < 0 then -- if Enemy's health lower than 0 then
  91. if Alive then -- if its health is lower than 0, and it's alive then
  92. Enemy:BreakJoints() -- break joints of enemy or delete joints to be more specific.
  93. Alive = false -- then change alive to false.
  94. if Enemy.Head:FindFirstChild("Death") then -- then find the first child of the Head of the enemy, if it's the Death sound then
  95. Enemy.Head.Death:Play() -- play the death noise
  96. end
  97. Bounty(Enemy) -- Set the bounty of the enemy when killed by a tower.
  98. end
  99. game.Debris:AddItem(Enemy,1) -- ?????
  100. end
  101. Enemy.Humanoid.Health = (Enemy.Health.Value/Enemy.MaxHealth.Value) * 100 -- The enimies health is = to max health divided by MaxHealth value, times 100.
  102. end)
  103.  
  104. for i,Part in pairs(Enemy:GetChildren()) do -- for the Part, find the enimies children
  105. if Part:IsA("BasePart") then -- If the part is a base part, then,
  106. game:GetService("PhysicsService"):SetPartCollisionGroup(Part,"Enemies") -- then, set the base part/part to be collideable with enimies.
  107. end -- Ends
  108. end -- Ends
  109.  
  110. if Enemy:FindFirstChild("WalkAnim") then -- If the Enimies first child is the WalkAnim animation then
  111. local Track = Enemy.Humanoid:LoadAnimation(Enemy.WalkAnim) -- then, track the Enemy, and load the Animation
  112. Track:Play() -- play the animation while tracking ^^^^^^
  113. -- Enemy.WalkAnim:Play()
  114. end
  115. end
  116.  
  117.  
  118.  
  119. wait(1)
  120.  
  121. for i,Wall in pairs(workspace.Path.Walls:GetChildren()) do
  122. if Wall.Name == "Wall" and Wall:IsA("BasePart") then
  123. Wall.Transparency = 1
  124. Wall.CanCollide = false
  125. end
  126. end
  127.  
  128. while true do
  129. wait(1)
  130.  
  131. local Chance = math.random(1,10)
  132.  
  133. if Chance == 7 then
  134. SpawnEnemy("Rich Dummy")
  135. else
  136. SpawnEnemy("Dummy")
  137.  
  138. if Chance == 4 then
  139. SpawnEnemy("TestEnemy01")
  140.  
  141. else
  142. SpawnEnemy("Dummy02")
  143. end
  144.  
  145. end
  146.  
  147. end
  148.  
  149. --[[while true do
  150. wait(2)
  151. local value = math.random(-200, 200), 15, math.random(-200, 200)
  152. local model = game.ServerStorage.Enemies:FindFirstChild(Type) :Clone()
  153. Enemy:MoveTo(Vector3.new(value))
  154. model:MoveTo(Vector3.new (value))
  155. end
  156. --]]
Advertisement
Add Comment
Please, Sign In to add comment