Advertisement
InTesting

E Laser test again

Sep 9th, 2019
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.28 KB | None | 0 0
  1. print'https://pastebin.com/s8AgGwH8'
  2. --// Why is this better? it recycles the laser and sound.
  3. local function Get_Components_Of_Mouse(player)
  4.     local pchar = player.Character
  5.     if pchar then
  6.         local Remote = pchar:FindFirstChild('RE_Mouse')or
  7.             Instance.new("RemoteEvent",pchar)
  8.         Remote.Name = 'RE_Mouse'
  9.        
  10.         Remote.Parent = NLS(
  11.             [[
  12. local lp,runs,re,del =
  13.     game:GetService'Players'.LocalPlayer,game:GetService'RunService',
  14.     script:WaitForChild('RE_Mouse'),true
  15. local mouse = lp:GetMouse()
  16.  
  17. while wait(1/15)do
  18.     if mouse.Target and del then
  19.         del = false
  20.         re:FireServer('KeyDown','e',mouse.Hit)
  21.         wait(.1)
  22.         del = true
  23.     end
  24. end
  25.             ]]
  26.             ,pchar)
  27.         return Remote
  28.     else
  29.         error('Best to actually put your character In the game.')
  30.     end
  31. end
  32. local re = Get_Components_Of_Mouse(owner)
  33. local person = owner.Character
  34. local deb = game:GetService("Debris")
  35. local head = person:WaitForChild'Head'
  36. local _ = person:WaitForChild'HumanoidRootPart'
  37. local _ = person:WaitForChild'Humanoid'
  38.  
  39. -- // Weapons Closet \\ --
  40.  
  41. local function Damage(part)
  42.     --[[
  43.         // Description \\
  44.         This Function can damage a model with a given part. The default damage is 10,
  45.         and can not be adjusted If its replacing an unnamed Function in an event.
  46.         So it's best advised to change the
  47.         local varables within the Function. If a humanoid is not found, the model will
  48.         be killed.
  49.        
  50.         Local varables:
  51.             (Number) Kill_At_LargeHealth
  52.                 Automatically kills player if the humanoid's health is atleast of
  53.                 this number. If the number is 0, Then it does nothing.
  54.             (Number) Damage_humanoid
  55.                 Amount of damage towards the humanoid.
  56.     --]]
  57.     local Kill_At_LargeHealth = 100
  58.     local Damage_humanoid = 10
  59.     pcall(function()
  60.         local mod = part:FindFirstAncestorWhichIsA'Model'
  61.         if mod then
  62.             if mod~=workspace then
  63.                 local hum = mod:FindFirstChildWhichIsA'Humanoid'
  64.                 local target = mod:FindFirstChild'Head'or mod:FindFirstChild'Torso'or mod:FindFirstChild'UpperTorso'or mod:FindFirstChild'HumanoidRootPart'
  65.                 if hum then
  66.                     if hum.Health>Kill_At_LargeHealth and Kill_At_LargeHealth~=0 then
  67.                         hum.Health = 0
  68.                     else
  69.                         if hum.Health>0 then
  70.                             hum:TakeDamage(Damage_humanoid)
  71.                         end
  72.                     end
  73.                 elseif target then
  74.                     target:Destroy()
  75.                 else
  76.                     mod:BreakJoints()
  77.                 end
  78.             end
  79.         end
  80.     end)
  81. end
  82. local function CustomDamage(part,damage,Kill_At_Large_Health,noharm)
  83.     --[[
  84.         // Description \\
  85.         Similar to Damage() except you can not use it to replace an unamed Function
  86.         in an event, but this version has parameters.
  87.        
  88.         --> Manatory
  89.             (Instance) Part the Function will be checking.
  90.             (Number) Amount of damage.
  91.         --> Optional
  92.             (Number) Amount of health that a player needs in order to be automatically
  93.             killed.
  94.                 Default =
  95.                     0
  96.             (Instance) The Instance that the Function will be ignoring.
  97.                 Default =
  98.                     nil
  99.     --]]
  100.     if not Kill_At_Large_Health then
  101.         Kill_At_Large_Health = 0
  102.     end
  103.     pcall(function()
  104.         local mod = part:FindFirstAncestorWhichIsA'Model'
  105.         if mod then
  106.             if mod~=workspace then
  107.                 local bool = true
  108.                 if noharm then
  109.                     if noharm==mod then
  110.                         bool = false
  111.                     end
  112.                 end
  113.                 if bool then
  114.                     local hum = mod:FindFirstChildWhichIsA'Humanoid'
  115.                     local target = mod:FindFirstChild'Head'or mod:FindFirstChild'Torso'or mod:FindFirstChild'UpperTorso'or mod:FindFirstChild'HumanoidRootPart'
  116.                     if hum then
  117.                         if hum.Health>100 then
  118.                             hum.Health = 0
  119.                         else
  120.                             if hum.Health>0 then
  121.                                 hum:TakeDamage(damage)
  122.                             end
  123.                         end
  124.                     elseif target then
  125.                         target:Destroy()
  126.                     else
  127.                         mod:BreakJoints()
  128.                     end
  129.                 end
  130.             end
  131.         end
  132.     end)
  133. end
  134. local function Explosion_Effect(hit,bullet,noharm,damage,part_properties,end_size,tw_info,
  135. end_properties)
  136.     --[[
  137.         // Description \\
  138.         Explosion on hit.
  139.        
  140.         M hit (Instance) Part that's the target part.
  141.         O
  142.     --]]
  143.     local function Check_Parameter(para,def)
  144.         if para then
  145.             if typeof(para)==typeof(def)then
  146.                 return para
  147.             end
  148.         end
  149.         return def
  150.     end
  151.    
  152. end
  153.  
  154. local function Laser_Beam(Start_Pos,End_Cframe,part_properties,beam_width,damage,
  155. delay_damage,noharm,duration)
  156.     --[[
  157.         // Description \\
  158.         Returns part that will mimic a laser beam. Often Varies from the style.
  159.         Best to keep the laser beam as a block and not a cylinder.
  160.        
  161.         Note theres alot of parameters so bare with me.
  162.        
  163.         M = Manatory
  164.         O = Optional
  165.        
  166.         M Start_Pos (Vector3) Position where the laser is starting.
  167.         M End_Cframe (CFrame) Needed to find the size of laser's length and the
  168.             End point.
  169.         O part_properties (Table) Properties of the laser. Use the format:
  170.                
  171.                 Property = value
  172.                
  173.             Default =
  174.                 (A typical brick except:)
  175.                
  176.                     Anchored = true,
  177.                     Parent = nil
  178.                
  179.         O beam_width (Number) The width and height of the laser.
  180.             Default =
  181.                 .1
  182.         O damage (Number) The amount of damage it will deal.
  183.             Default =
  184.                 10
  185.         O delay_damage (Number) Delay in seconds for the laser to rest.
  186.             Default =
  187.                 .1
  188.         O noharm (Instance) Instance for the noharm argument in CustomDamage(). Basically
  189.             ignores the model if the part it hits is a descendant of it.
  190.             Default =
  191.                 nil
  192.         O duration (Number) Amount in seconds before it disappears.
  193.             Default =
  194.                 1
  195.     --]]
  196.  
  197.     local part = Instance.new("Part")
  198.    
  199.     local function Check_Parameter(parameter,default)
  200.         if parameter then
  201.             if typeof(parameter)==typeof(default)then
  202.                 return parameter
  203.             else
  204.                 return default
  205.             end
  206.         else
  207.             return default
  208.         end
  209.     end
  210.     beam_width = Check_Parameter(beam_width,.1)
  211.     damage = Check_Parameter(damage,10)
  212.     delay_damage = Check_Parameter(delay_damage,.1)
  213.     duration = Check_Parameter(duration,1)
  214.    
  215.     local diff = (Start_Pos - End_Cframe.Position).Magnitude
  216.     for i,v in pairs(part_properties)do
  217.         pcall(function()
  218.             part[i] = v
  219.         end)
  220.     end
  221.     part.Anchored = true
  222.     part.CFrame = CFrame.new(Start_Pos,End_Cframe.Position) * CFrame.new(0,0,-diff/2)
  223.     part.Size = Vector3.new(beam_width,beam_width,diff)
  224.     local bool = true
  225.     part.Touched:Connect(function(h)
  226.         if bool then
  227.             bool = false
  228.             CustomDamage(h,damage,nil,noharm)
  229.             wait(delay_damage)
  230.             bool = true
  231.         end
  232.     end)
  233.    
  234.    
  235.     if duration then
  236.         local debris = game:GetService("Debris")
  237.         debris:AddItem(part,duration)
  238.     end
  239.    
  240.     return part
  241. end
  242. local function Bullet_Beam(Start_Pos,End_Cframe,part_properties,beam_width,damage,
  243.     delay_damage,bullet_length,type_of_travel,noharm,is_spawned,for_loop_steps,
  244.     for_loop_stud_step_forward,for_loop_stud_step_delay,tw_info,effect_function)
  245.  
  246.     --[[
  247.         // Description \\
  248.         Fuck these parameters. I'm gonna make a simpler version some day.
  249.        
  250.         Returns a bullet. Note this can auto launch if you want to.
  251.        
  252.         M = Manatory
  253.         O = Optional
  254.    
  255.         M Start_Pos (Vector3) Position where the bullet starts.
  256.         M End_Cframe (CFrame) Necessary for the End Point of the bullet and the
  257.             direction.
  258.         O part_properties (Table) Table of properties for the bullet.
  259.             Default =
  260.                 Most of the properties of a typical part.
  261.         O beam_width (Number) The width and height of the bullet.
  262.             Default =
  263.                 .1
  264.         O damage (Number) The Damage it will deal.
  265.             Default =
  266.                 10
  267.         O delay_damage (Number) The delay of the bullet's damage
  268.             Default =
  269.                 1
  270.         O bullet_length (Number) The length of the bullet.
  271.             Default =
  272.                 .25
  273.         O type_of_travel (String) The Mode of travel:
  274.              - 'for_loop'; This mode will look laggy and will use a for loop.
  275.              - 'tween'; This mode will look smoother if in small servers and uses
  276.                 Tweenservice.
  277.              - (Default) nil
  278.             Note this will affect other parameters.
  279.         O noharm (Instance) Parameter for CustomDamage()
  280.             Default =
  281.                 nil
  282.         O (type_of_travel~=nil) is_spawned (Boolean) Makes a new thread for the
  283.             travel Function, If [type_of_travel] is not nil. In skid
  284.             language, it will prevent the script from yielding/pause the script.
  285.             Default =
  286.                 nil/false
  287.         O (type_of_travel~=nil) for_loop_steps (Number)
  288.             in type_of_travel=='for_loop', this number will be of how many times the
  289.                 bullet will phase through [for_loop_stud_step_forward] of studs.
  290.            
  291.             in type_of_travel=='tween', this number will be multiplied with
  292.                 [for_loop_stud_step_forward] to create the End point of the bullet.
  293.                
  294.             Default =
  295.                 10
  296.            
  297.         O (type_of_travel~=nil) for_loop_stud_step_forward (Number)
  298.             in type_of_travel=='for_loop', this number will be the amount of studs that
  299.                 it will go through per phase.
  300.                
  301.             in type_of_travel=='tween', this number will be multiplied with
  302.                 [for_loop_steps] to create the End point of the bullet.
  303.            
  304.             Default =
  305.                 1
  306.         O (type_of_travel=='for_loop') for_loop_stud_step_delay (Number)
  307.             This number will be the amout in seconds the bullet will pause before it
  308.             goes through another phase.
  309.            
  310.             Note this does not apply to (type_of_travel=='tween') because tween is
  311.             based so that the bullet will travel to its End Position.
  312.             (type_of_travel=='for_loop') is based so that it phases after a certiain
  313.             amount of numbers.
  314.            
  315.             Default =
  316.                 .1
  317.         O (type_of_travel=='tween') tw_info (TweenInfo)
  318.             This will determine the time, and Enum.EasingStyle it will use.
  319.             Default =
  320.                 TweenInfo.new(1,Enum.EasingStyle.Linear,
  321.                 Enum.EasingDirection.InOut,0,false,0)
  322.         O effect_function (Function)
  323.             Function when bullet hits a part.
  324.             Default =
  325.                 CustomDamage()
  326.        
  327.     --]]
  328.  
  329.     local part = Instance.new("Part")
  330.     local travel
  331.     local diff = (Start_Pos - End_Cframe.Position).Magnitude
  332.    
  333.     local function Check_Parameter(parameter,default)
  334.         if parameter then
  335.             if typeof(parameter)==typeof(default)then
  336.                 return parameter
  337.             else
  338.                 return default
  339.             end
  340.         else
  341.             return default
  342.         end
  343.     end
  344.     beam_width = Check_Parameter(beam_width,.1)
  345.     damage = Check_Parameter(damage,10)
  346.     delay_damage = Check_Parameter(delay_damage,.1)
  347.     bullet_length = Check_Parameter(bullet_length,.25)
  348.     for_loop_steps = Check_Parameter(for_loop_steps,10)
  349.     for_loop_stud_step_forward = Check_Parameter(for_loop_stud_step_forward,1)
  350.     for_loop_stud_step_delay = Check_Parameter(for_loop_stud_step_delay,.1)
  351.     tw_info = Check_Parameter(tw_info,TweenInfo.new(1,Enum.EasingStyle.Linear,
  352.                     Enum.EasingDirection.InOut,0,false,0))
  353.    
  354.     for i,v in pairs(part_properties)do
  355.         pcall(function()
  356.             part[i] = v
  357.         end)
  358.     end
  359.     part.Anchored = true
  360.     part.CFrame = CFrame.new(Start_Pos,End_Cframe.Position)
  361.     part.Size = Vector3.new(beam_width,beam_width,bullet_length)
  362.     local bool = true
  363.     part.Touched:Connect(function(h)
  364.         if bool then
  365.             bool = false
  366.             if not effect_function then
  367.                 CustomDamage(h,damage,nil,noharm)
  368.             else
  369.                 effect_function(h,part,noharm)
  370.             end
  371.             wait(delay_damage)
  372.             bool = true
  373.         end
  374.     end)
  375.    
  376.     if type_of_travel=='for_loop'then
  377.         travel = function()
  378.             for i=1,for_loop_steps do
  379.                 part.CFrame = part.CFrame *
  380.                     CFrame.new(0,0,-for_loop_stud_step_forward)
  381.                 wait(for_loop_stud_step_delay)
  382.             end
  383.             part.Anchored = false
  384.             part.CanCollide = false
  385.         end
  386.     elseif type_of_travel=='tween'then
  387.         travel = function()
  388.             local tws = game:GetService("TweenService")
  389.             local prop = {
  390.                 CFrame = part.CFrame * CFrame.new(0,0,-(for_loop_steps * for_loop_stud_step_forward))
  391.                 }
  392.             local an = tws:Create(part,tw_info,prop)
  393.             an:Play()
  394.             wait(an.TweenInfo.Time)
  395.             part.Anchored = false
  396.             part.CanCollide = false
  397.         end
  398.     end
  399.     if travel then
  400.         if is_spawned then
  401.             spawn(travel)
  402.         else
  403.             travel()
  404.         end
  405.     end
  406.    
  407.     return part
  408. end
  409. local function Laser_Beam_Cylinder(Start_Pos,End_Cframe,part_properties,beam_width,damage,
  410. delay_damage,noharm,duration)
  411.     --[[
  412.         // Description \\
  413.         Returns part that will mimic a laser beam. Often Varies from the style.
  414.         Best to keep the laser beam as a block and not a cylinder.
  415.        
  416.         Note theres alot of parameters so bare with me.
  417.        
  418.         M = Manatory
  419.         O = Optional
  420.        
  421.         M Start_Pos (Vector3) Position where the laser is starting.
  422.         M End_Cframe (CFrame) Needed to find the size of laser's length and the
  423.             End point.
  424.         O part_properties (Table) Properties of the laser. Use the format:
  425.                
  426.                 Property = value
  427.                
  428.             Default =
  429.                 (A typical brick except:)
  430.                
  431.                     Anchored = true,
  432.                     Parent = nil
  433.                
  434.         O beam_width (Number) The width and height of the laser.
  435.             Default =
  436.                 .1
  437.         O damage (Number) The amount of damage it will deal.
  438.             Default =
  439.                 10
  440.         O delay_damage (Number) Delay in seconds for the laser to rest.
  441.             Default =
  442.                 .1
  443.         O noharm (Instance) Instance for the noharm argument in CustomDamage(). Basically
  444.             ignores the model if the part it hits is a descendant of it.
  445.             Default =
  446.                 nil
  447.         O duration (Number) Amount in seconds before it disappears.
  448.             Default =
  449.                 1
  450.     --]]
  451.  
  452.     local part = Instance.new("Part")
  453.    
  454.     local function Check_Parameter(parameter,default)
  455.         if parameter then
  456.             if typeof(parameter)==typeof(default)then
  457.                 return parameter
  458.             else
  459.                 return default
  460.             end
  461.         else
  462.             return default
  463.         end
  464.     end
  465.     beam_width = Check_Parameter(beam_width,.1)
  466.     damage = Check_Parameter(damage,10)
  467.     delay_damage = Check_Parameter(delay_damage,.1)
  468.  
  469.    
  470.     local diff = (Start_Pos - End_Cframe.Position).Magnitude
  471.     for i,v in pairs(part_properties)do
  472.         pcall(function()
  473.             part[i] = v
  474.         end)
  475.     end
  476.     part.Shape = 'Cylinder'
  477.     part.Anchored = true
  478.     part.CFrame = CFrame.new(Start_Pos,End_Cframe.Position) * CFrame.new(0,0,-diff/2)
  479.     * CFrame.Angles(math.rad(90),0,math.rad(90))
  480.     part.Size = Vector3.new(diff,beam_width,beam_width)
  481.     local bool = true
  482.     part.Touched:Connect(function(h)
  483.         if bool then
  484.             bool = false
  485.             CustomDamage(h,damage,nil,noharm)
  486.             wait(delay_damage)
  487.             bool = true
  488.         end
  489.     end)
  490.    
  491.    
  492.     if duration then
  493.         local debris = game:GetService("Debris")
  494.         debris:AddItem(part,duration)
  495.     end
  496.    
  497.     return part
  498. end
  499.  
  500.  
  501. local function On_OnServerEvent(player,...)
  502.     local parameters = {...}
  503.     if parameters[1]=='KeyDown'and true then -- player==owner
  504.         if parameters[2]=='e'and parameters[3]then
  505.             local pchar = player.Character
  506.             local folder = pchar:FindFirstChild'Lasers'or (function()
  507.                     local a = Instance.new("Folder");a.Name='Lasers';
  508.                     a.Parent=pchar;return a
  509.             end)()
  510.             local Start_Pos,End_Cframe,beam_width =
  511.                 head.Position + Vector3.new(0,5,0),parameters[3],1
  512.             local beam = folder:FindFirstChild'Beam'or
  513.                 Laser_Beam_Cylinder(Start_Pos,End_Cframe,{Parent=folder,
  514.                 Name='Beam',Material='ForceField',CanCollide=false,
  515.                 BrickColor = BrickColor.new("Really red")},
  516.                 beam_width,100,.25,person)
  517.            
  518.             local diff = (Start_Pos - End_Cframe.Position).Magnitude
  519.             beam.CFrame = CFrame.new(Start_Pos,End_Cframe.Position)*
  520.                 CFrame.new(0,0,-diff/2)*
  521.                 CFrame.Angles(math.rad(90),0,math.rad(90))
  522.                 beam.Size = Vector3.new(diff,beam_width,beam_width)
  523.             local block = folder:FindFirstChild'Block'or(function()
  524.                 local b=Instance.new("Part");b.Size=Vector3.new(5,5,5);
  525.                 b.BrickColor=BrickColor.new("Really red");b.Anchored=true;
  526.                 b.Name = 'Block';b.CanCollide=false;b.Material='ForceField';
  527.                 b.Parent=folder;return b
  528.             end)()
  529.             block.CFrame = CFrame.new(Start_Pos,End_Cframe.Position)
  530.             local _ = block:FindFirstChildWhichIsA'Sound'or(function()
  531.                 local s=Instance.new("Sound");s.SoundId='rbxassetid://132594796';
  532.                 s.Parent=block;s.Volume=2.5;s.Looped=true;s:Play();return s
  533.             end)()
  534.            
  535.         end
  536.     end
  537. end
  538.  
  539.  
  540.  
  541. re.OnServerEvent:Connect(On_OnServerEvent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement