Guest User

Untitled

a guest
Mar 13th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. --Libraries
  2. local player = game.Players.LocalPlayer
  3. local char = player.Character or player.CharacterAdded:wait()
  4. local mouse = player:GetMouse()
  5. local cam = workspace.CurrentCamera
  6. local rs = game:GetService('RunService').RenderStepped
  7. local uis = game:GetService('UserInputService')
  8.  
  9. --Fundmental Modules
  10. local gs = require(game.ReplicatedStorage.Modules.Fundementals.GameSettings)
  11. local eai = require(game.ServerScriptService.Modules.Classes.Enemy.EmemyAi)
  12.  
  13. --Events
  14. local events = game.ReplicatedStorage.Events
  15. local signal = events:WaitForChild("Signal")
  16.  
  17. --Main
  18. signal.OnClientEvent:connect(function(ver,p1,p2,p3)
  19.     local bdfl = {
  20.         SetupTurrent = function()
  21.             local clp = true
  22.             local lastrot = {
  23.                 x=0,
  24.                 y=0,
  25.                 z=0,
  26.             }
  27.             --Cloning
  28.             local t = game.ReplicatedStorage.Assets.Turrets.RTurret:Clone()
  29.             t.Parent = cam
  30.            
  31.             --Input
  32.             uis.InputBegan:connect(function(io,gpe)
  33.                 if io.KeyCode == Enum.KeyCode.R and clp == true then
  34.                     if t:isA("Model") then
  35.                         if t.PrimaryPart ~= nil then
  36.                             t:SetPrimaryPartCFrame(t:GetPrimaryPartFrame()*CFrame.Angles(0,math.rad(5),0))
  37.                             lastrot.y = t.PrimaryPart.Rotation.Y
  38.                         else
  39.                             warn("Set Primary Part to base...")
  40.                         end
  41.                     elseif t:isA("BasePart") then
  42.                     t.CFrame = t.CFrame*CFrame.Angles(0,math.rad(5),0)
  43.                     lastrot.y = t.Rotation.Y
  44.                     end
  45.                 end
  46.             end)
  47.            
  48.             local function castRay(o,o2)
  49.                 local mag = (o.PrimaryPart.Position-o2.Positon).magnitude
  50.                 local beam = Instance.new("Part")
  51.                 beam.BrickColor = BrickColor.new('Black')
  52.                 beam.Material = 'Neon'
  53.                 beam.Transparency = 0
  54.                 beam.Anchored = true
  55.                 beam.CanCollide = true
  56.                 beam.Size=Vector3.new(0.3,0.3,mag)
  57.                 beam.CFrame=CFrame.new(o.PrimaryPart.Position,o2.Position)*CFrame.new(0,0,mag/2)
  58.                 beam.Parent = cam
  59.                 game:GetService("Debris"):AddItem(beam,4)
  60.             end
  61.            
  62.             local function trackEnemies()
  63.                 local cooldown = 0
  64.                 local closestpart
  65.                 spawn(function()
  66.                     while wait() do
  67.                         wait(cooldown)
  68.                         if #gs.CurrentCourse.Enemies:GetChildren()~= 0 then
  69.                             cooldown = 0
  70.                             for n,e in pairs(gs.CurrentCourse.Enemies:GetChildren()) do
  71.                                 if e~= nil then
  72.                                     local mag = (o.PrimaryPart.Position-e.Position).magnitude
  73.                                     if mag <= 4.5 then
  74.                                         closestpart = e
  75.                                     end
  76.                                 end
  77.                             end
  78.                                 if closestpart then
  79.                                     castRay(o, closestpart)
  80.                                     signal:FireServer('Backdoor','DestroyEnemy',closestpart)
  81.                                     closestpart = nil
  82.                                     cooldown = 3
  83.                                 end
  84.                             end
  85.                         end
  86.                     end)
  87.                 end        
  88.            
  89.             mouse.Button1Down:connect(function()
  90.                 clp = false
  91.                 trackEnemies(t)
  92.             end)
  93.            
  94.             mouse.TargetFilter = t
  95.            
  96.             rs:connect(function()
  97.                 if clp == true then
  98.                         if mouse.Target ~= nil then
  99.                             if mouse.Target.Parent.Parent == gs.CurrentCourse then
  100.                             signal:FireServer("Backdoor","UpdateTurretPosition",t,
  101.                             CFrame.new(mouse.Target.Position.X((t.PrimaryPart.Size.Y/2)+mouse.Target.Position.Y)+0.5,mouse.Target.Position.Z)*CFrame.Angles(0,lastrot.y,0))
  102.                         end
  103.                     end
  104.                 end
  105.             end)
  106.         end
  107.     }
  108.     if ver == 'Backdoor' then
  109.         bdfl[p1](p2,p3)
  110.     elseif ver == "Frontdoor"then
  111.         signal:FireServer("Backdoor", p1,p2,p3)
  112.     end
  113. end)
Advertisement
Add Comment
Please, Sign In to add comment