Advertisement
nostopgmaming17

Naval Warfare AA Script

Dec 5th, 2023 (edited)
1,715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.09 KB | None | 0 0
  1. -- NAVAL WARFARE AA SCRIPT --
  2. -- Sirmeme please unban noam01 from your server plzplz --
  3. -- Controls: get on a AA turret and watch it destroy the enemy team and make the whole server mad --
  4.  
  5. getgenv().AA_enabled = true
  6.  
  7. local plr = game.Players.LocalPlayer
  8. local r = game.ReplicatedStorage.Event
  9. local BULLETSPEED = 800
  10. local SHOOTING = false
  11. local shootThs = {}
  12. local phrase = "shoot"
  13. local MAXDIST = 2345 -- Recommended for best performance --
  14. local function aim(v3)
  15.     r:FireServer("aim",{v3})
  16. end
  17. local function shoot(b)
  18.     SHOOTING = b
  19.     for i=1,#shootThs do
  20.         coroutine.resume(shootThs[i])
  21.     end
  22. end
  23. local function radar()
  24.     if plr.Character == nil or not plr.Character:FindFirstChild("HumanoidRootPart") or not plr.Character:FindFirstChild("Humanoid") or plr.Character.Humanoid.Health <= 0 then return end
  25.     local team = plr.Team.Name
  26.     local P = plr.Character.HumanoidRootPart.Position
  27.  
  28.     local r,rv = MAXDIST,nil
  29.  
  30.     for i,v in next, workspace:GetChildren() do
  31.         if not v:FindFirstChild("HitCode") or not v:FindFirstChild("Team") or not v:FindFirstChild("HP") or not v:FindFirstChild("Seat") then continue end
  32.         if v.HP.Value <= 0 then continue end
  33.         if v.HitCode.Value ~= "Plane" then continue end
  34.         if v.Team.Value == team then continue end
  35.         local d = (P - v.Seat.Position).Magnitude
  36.         if d < r then
  37.             r = d
  38.             rv = v
  39.         end
  40.     end
  41.  
  42.     return rv
  43. end
  44. local function isOnAA()
  45.     if not plr.Character then return false end
  46.     if not plr.Character:FindFirstChild("Humanoid") then return false end
  47.     local seat = plr.Character.Humanoid.SeatPart
  48.     if not seat then return false end
  49.     local hc,gn = seat.Parent:FindFirstChild("HitCode"),seat.Parent:FindFirstChild("GunNum")
  50.     if hc ~= nil and gn ~= nil then
  51.         if hc.Value == "Ship" and gn.Value ~= 0 then phrase = "bomb" return true end
  52.     end
  53.  
  54.     if seat:FindFirstChild("GunType") ~= nil then
  55.         if seat.GunType.Value == "AA" then phrase = "shoot" return true end
  56.     end
  57.     return false
  58. end
  59. local function getShootPos(p,v)
  60.     local from = plr.Character.HumanoidRootPart.Position
  61.     local d = (from - p).Magnitude
  62.     local t = d / (BULLETSPEED - v.Magnitude)
  63.     return p + (v*t)
  64. end
  65. local function shootTh()
  66.     while task.wait() do
  67.         if not SHOOTING then
  68.             r:FireServer(phrase,{false})
  69.             coroutine.yield()
  70.             if not SHOOTING then break end
  71.         end
  72.         r:FireServer(phrase,{true})
  73.     end
  74. end
  75. for i = 1,1 do
  76.     table.insert(shootThs,coroutine.create(shootTh))
  77. end
  78.  
  79.  
  80. local tgt = Drawing.new("Circle")
  81. tgt.Visible = false
  82. tgt.Color = Color3.new(0,1,0)
  83. tgt.Radius = 3
  84. tgt.Thickness = 0
  85.  
  86. local tgt2 = Drawing.new("Circle")
  87. tgt2.Visible = false
  88. tgt2.Color = Color3.new(0,1,0)
  89. tgt2.Radius = 15
  90. tgt2.Thickness = 0
  91. tgt2.Transparency = 0.25
  92.  
  93.  
  94. local to = Drawing.new("Circle")
  95. to.Visible = false
  96. to.Color = Color3.new(1,0,0)
  97. to.Radius = 3
  98. to.Thickness = 0
  99.  
  100. local to2 = Drawing.new("Circle")
  101. to2.Visible = false
  102. to2.Color = Color3.new(1,0,0)
  103. to2.Radius = 15
  104. to2.Thickness = 0
  105. to2.Transparency = 0.25
  106.  
  107. local txt = Drawing.new("Text")
  108. txt.Visible = false
  109. txt.Font = Drawing.Fonts.Monospace
  110. txt.Color = Color3.new(1,1,0)
  111. txt.Size = 14
  112. txt.Center = true
  113. txt.Outline = false
  114.  
  115. tgt.Filled = true
  116. tgt2.Filled = true
  117. to.Filled = true
  118. to2.Filled = true
  119.  
  120. local wasOnAA,hadTarget = false,false
  121. while AA_enabled do
  122.     task.wait()
  123.     if isOnAA() then
  124.         local target = radar()
  125.         if not target then
  126.             if hadTarget then
  127.                 tgt.Visible = false
  128.                 tgt2.Visible = false
  129.                 to.Visible = false
  130.                 to2.Visible = false
  131.                 txt.Visible = false
  132.                 SHOOTING = false
  133.             end
  134.             hadTarget = false
  135.             continue
  136.         end
  137.         if not hadTarget then
  138.             hadTarget = true
  139.         end
  140.         if not SHOOTING then
  141.             shoot(true)
  142.         end
  143.         local p = target.Seat.Position
  144.         local v = target.Seat.Velocity
  145.         local pos = getShootPos(p,v)
  146.         aim(pos)
  147.         local tgtv3,tgnscreen = workspace.CurrentCamera:WorldToViewportPoint(p)
  148.         local tov3,tonscreen = workspace.CurrentCamera:WorldToViewportPoint(pos)
  149.         local tgtv2,tov2 = Vector2.new(tgtv3.X,tgtv3.Y), Vector2.new(tov3.X,tov3.Y)
  150.         tgt.Position = tgtv2
  151.         tgt2.Position = tgtv2
  152.         txt.Position = tgtv2 - Vector2.new(0,30)
  153.         to.Position = tov2
  154.         to2.Position = tov2
  155.         tgt.Visible = tgnscreen
  156.         tgt2.Visible = tgnscreen
  157.         if tgnscreen then
  158.             txt.Text = ("[%s] HP: %d/%d %dm"):format(target.Name,target.HP.Value, target.Name == "Large Bomber" and 300 or 100, (plr.Character.HumanoidRootPart.Position - target.Seat.Position).Magnitude)
  159.         end
  160.         txt.Visible = tgnscreen
  161.         to.Visible = tonscreen
  162.         to2.Visible = tonscreen
  163.     else
  164.         SHOOTING = false
  165.         tgt.Visible = false
  166.         tgt2.Visible = false
  167.         to.Visible = false
  168.         to2.Visible = false
  169.         txt.Visible = false
  170.     end
  171. end
  172. tgt:Remove()
  173. tgt2:Remove()
  174. to:Remove()
  175. to2:Remove()
  176. txt:Remove()
  177. shoot(false)
  178.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement