Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sp = script.Parent
- r = game:GetService('RunService')
- Objs = {
- base = sp:WaitForChild('Base'),
- turret = sp.Base:WaitForChild('Turret'),
- }
- Set = {
- ExplosionRadius = 3,
- Damage = 5,
- Cooldown = 0.25,
- MaximumRange = 200,
- MinimumRange = 2,
- LockOnTime = 1.5,
- TeamColor = BrickColor.new ('Cyan'),
- Groups = {},
- UserIds = {},
- Spread = 1,
- }
- Var = {
- Target = nil,
- FirstLock = 0,
- RequiredLock = nil,
- }
- Sounds = {
- launch = Objs.base.PrimaryPart:WaitForChild('Launch'),
- locking = Objs.base.PrimaryPart:WaitForChild('Locking'),
- locked = Objs.base.PrimaryPart:WaitForChild('Locked'),
- }
- function castray(cframeFirst, cframeSecond, ignoreObject, distanceToCast)
- local newRay = Ray.new(cframeFirst.p, (cframeSecond.p - cframeFirst.p).unit * distanceToCast)
- local hitObject, positionHit = workspace:FindPartOnRay(newRay, ignoreObject)
- return positionHit, hitObject
- end
- function Find(t,item,mode)
- if mode == 'userid' then
- for i,name in pairs (t) do
- if name == item then
- return true
- end
- end
- elseif mode == 'group' then
- for i,id in pairs (t) do
- if item:GetRankInGroup(id) > 0 then
- return true
- end
- end
- end
- return false
- end
- function Fire(CFrame1,CFrame2)
- Sounds.launch:Play()
- local ray = Instance.new('Part',workspace)
- game:GetService('Debris'):AddItem(ray,0.1)
- ray.FormFactor = Enum.FormFactor.Custom
- ray.TopSurface = 0
- ray.BottomSurface = 0
- ray.Anchored = true
- ray.CanCollide = false
- ray.Material = Enum.Material.Neon
- ray.BrickColor = BrickColor.new('Gold')
- ray.Size = Vector3.new(0.2,(CFrame1.p - CFrame2.p).magnitude,0.2)
- ray.CFrame = CFrame.new((CFrame1.p + CFrame2.p)/2,CFrame1.p) * CFrame.fromEulerAnglesXYZ(math.rad(90),0,0)
- local mesh = Instance.new('CylinderMesh',ray)
- mesh.Scale = Vector3.new(0.25,1,0.25)
- end
- function Explode(pos)
- for i,v in pairs (game.Players:GetPlayers()) do
- if v.TeamColor ~= Set.TeamColor then
- if v:DistanceFromCharacter (pos) <= Set.ExplosionRadius then
- v.Character.Humanoid:TakeDamage(Set.Damage)
- end
- end
- end
- end
- function CheckTarget(player)
- if player.TeamColor ~= Set.TeamColor or Find(Set.UserIds,player.Name,'userid') == true or Find(Set.Groups,player,'group') == true then
- if player:DistanceFromCharacter(Objs.turret.PrimaryPart.Position) <= Set.MaximumRange then
- if player:DistanceFromCharacter(Objs.turret.PrimaryPart.Position) >= Set.MinimumRange then
- if player.Character.Humanoid.Health > 0 then
- local pos, hit = castray(Objs.turret.Gun.CFrame, player.Character.Torso.CFrame, Objs.turret, Set.MaximumRange)
- if (pos - player.Character.Torso.Position).magnitude <= Set.ExplosionRadius then
- return true
- end
- end
- end
- end
- end
- return false
- end
- function AquireTarget()
- local targets = {}
- for i,player in pairs (game.Players:GetPlayers()) do
- if CheckTarget(player) == true then
- table.insert(targets,player.Character)
- end
- end
- if #targets > 0 then
- Var.Target = targets[math.random(1,#targets)]
- else
- Var.Target = nil
- end
- end
- r.Stepped:connect(function()
- if Var.Target ~= nil then
- local direction = Objs.base.PrimaryPart.CFrame:pointToObjectSpace(Var.Target.Torso.Position)
- local direction2 = Objs.turret.PrimaryPart.CFrame:pointToObjectSpace(Var.Target.Torso.Position)
- local spiny = math.atan2(direction.x, direction.z) + math.pi
- local spinx = math.atan2(direction2.y,direction.y)
- Objs.base:SetPrimaryPartCFrame(Objs.base.PrimaryPart.CFrame * CFrame.Angles(math.rad(spiny), 0, 0))
- Objs.turret:SetPrimaryPartCFrame(Objs.turret.PrimaryPart.CFrame * CFrame.Angles(math.rad(-spinx), 0, 0))
- end
- end)
- spawn(function()
- while r.Stepped:wait() do
- if Var.Target == nil then
- for i,sound in pairs (Sounds) do
- if i ~= 'turn' and i ~= 'launch' then
- if sound.IsPlaying == true then sound:Stop() end
- wait()
- end
- end
- AquireTarget()
- else
- if Var.RequiredLock == nil then
- Var.RequiredLock = tick() + Set.LockOnTime
- end
- Var.FirstLock = tick()
- if Sounds.locking.IsPlaying == false then Sounds.locking:Play() end
- if Var.FirstLock > Var.RequiredLock then
- Sounds.locking:Stop()
- if Sounds.locked.IsPlaying == false then Sounds.locked:Play() end
- Var.RequiredLock = nil
- Var.FirstLock = 0
- while sp and wait(Set.Cooldown) and Var.Target ~= nil and CheckTarget(game.Players:GetPlayerFromCharacter(Var.Target)) == true do
- for i,gun in pairs (Objs.turret:GetChildren()) do
- if gun.Name == 'Gun' then
- local pos, hit = castray(gun.CFrame, Var.Target.Torso.CFrame, Objs.turret, Set.MaximumRange)
- gun.Muzzle.Enabled = true
- local spread = CFrame.new(math.random(-Set.Spread,Set.Spread),math.random(-Set.Spread,Set.Spread),math.random(-Set.Spread,Set.Spread))
- local tpos = CFrame.new(pos) * spread
- Fire(gun.CFrame,tpos)
- Explode(tpos.p)
- gun.Muzzle.Enabled = false
- wait()
- end
- end
- end
- Sounds.locked:Stop()
- Var.Target = nil
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement