local C=script.Parent.Parent.Parent local s=game.Players.LocalPlayer local p={KeyDown={{Key="\103";Description="\084\111\103\103\108\101 \076\097\115\101\114";Plugin=function()local p=C:WaitForChild("\076\097\115\101\114\076\105\103\104\116")local A=C:WaitForChild("\071\114\105\112")local E=C.Program_Client:WaitForChild("\105\103\110\111\114\101\067\111\100\101")local K=game.Workspace:WaitForChild("\066\117\108\108\101\116\077\111\100\101\108\058 "..s.Name)local W={}local z=(game.Players:GetPlayerFromCharacter(C.Parent)).Name local b=K local k=game:GetService("\082\117\110\083\101\114\118\105\099\101")local function f()local C=Instance.new("\080\097\114\116")C.Transparency=1 C.Name="\108\097\115\101\114\068\111\116"C.Anchored=true C.CanCollide=false C.FormFactor=Enum.FormFactor.Custom C.Size=Vector3.new(.25,.25,1)local s=Instance.new("\083\117\114\102\097\099\101\071\117\105")s.CanvasSize=Vector2.new(100,100)s.Parent=C local p=Instance.new("\073\109\097\103\101\076\097\098\101\108")p.BackgroundTransparency=1 p.Size=UDim2.new(1,0,1,0)p.Image="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\049\051\049\051\057\052\055\051\057"p.Parent=s return C end local function T(C,s)local p={{"\066\097\099\107";s.CFrame*CFrame.new(0,0,s.Size.z)},{"\066\111\116\116\111\109",s.CFrame*CFrame.new(0,-s.Size.y,0)},{"\070\114\111\110\116",s.CFrame*CFrame.new(0,0,-s.Size.z)},{"\076\101\102\116";s.CFrame*CFrame.new(-s.Size.x,0,0)};{"\082\105\103\104\116",s.CFrame*CFrame.new(s.Size.x,0,0)};{"\084\111\112";s.CFrame*CFrame.new(0,s.Size.y,0)}}local A=math.huge local E=nil for s,p in pairs(p)do local K=(C-p[2].p).magnitude if K<A then A=K E=p end end local K=CFrame.new(s.CFrame.p,E[2].p)local W=K.lookVector*((s.CFrame.p-E[2].p).magnitude/2-.25)local z=(C-E[2].p)+W local b=(K+W)+z return b end local r=f()p.Transparency=p.Transparency==1 and 0 or 1 while math.floor(p.Transparency)==0 do if not game.Players:GetPlayerFromCharacter(C.Parent)then break end local s=Ray.new(p.Position,A.CFrame.lookVector*999)local E,K=game.Workspace:FindPartOnRayWithIgnoreList(s,W)if E and(E and E.Transparency>=1 or E.CanCollide==false)then table.insert(W,E)end local z=(K-p.Position).magnitude p.Mesh.Offset=Vector3.new(0,z/2,0)p.Mesh.Scale=Vector3.new(.075,z/.2,.075)if E then r.CFrame=T(K,E)r.Parent=b else r.Parent=nil end k.RenderStepped:wait()end r:Destroy()p.Transparency=1 p.Mesh.Offset=Vector3.new()p.Mesh.Scale=Vector3.new(.075,0,.075)end}}}return p
--[[

	Plugins for this gun kit are basically functions that will run at specific times, i.e. When a key is pressed, when the gun is
	fired, when the gun is aimed, etc.
	
	HOW TO USE IT:
	
		KEYDOWN PLUGIN:
		
			Let's say you wanted to toggle a laser whenever you press the "v" key:
			
			You would create a table like the example below
			The first element would be "Key = INSERT_KEY_HERE"
			The second element would be "Description = INSERT_DESCRIPTION_HERE"
			The third element would be "Plugin = INSERT_FUNCTION_HERE"
			
			So whenever you press the "v" key, the plugin function will run
			
			Pretty useful if you want to add extra code to the script without actually having to modify the script
		
			NOTE: Only the keydown plugin requires this table. Every other plugin just needs a function
			
		EVERY OTHER PLUGIN:
		
			Let's say you wanted to make a shell eject whenever the gun was fired:
			
			You would add function called "Plugin = INSERT_FUNCTION_HERE"
			
			That's it; If you want other stuff to happen when the gun is fired, you would either put it all into 1 function, or
			you would add more Plugins to the "Firing" table. Like so:
			
			Firing = {
				Plugin = function()
					--Code
				end;
				Plugin = function()
					--Code
				end;
				Plugin = function()
					--Code
				end;
			};
	
	That's really it, you just need to know some basic scripting to use it. If you have more questions, pm me.
	
	NOTE: The plugins run seperate from the code in the Gun_Main. For example, if you have a plugin that ejects a shell 1 second
	after the gun is fired, the gun's firing speed won't be affected in any way.
	
--]]

local Gun = script.Parent.Parent.Parent
local player = game.Players.LocalPlayer

local Plugins = {

	KeyDown = {
		{ --This is a plugin for a toggleable laser
			Key = "g", --This is the key you press to activate the plugin
			Description = "Toggle Laser", --This is what the description of the key will be in the controls
			Plugin = function() --This is the actual plugin function
				local Laser = Gun:WaitForChild("LaserLight") --These few lines wait for the necessary bricks/models
				local Handle = Gun:WaitForChild("Grip")
				local ignoreCode = Gun.Program_Client:WaitForChild("ignoreCode")
				local ignoreModel = game.Workspace:WaitForChild("BulletModel: " .. player.Name)
				local ignoreList = {}

				local PlyrName = game.Players:GetPlayerFromCharacter(Gun.Parent).Name
				local playerFolder = ignoreModel

				local RS = game:GetService("RunService")

				local function createLaserDot() --This function creates the red laser dot
					local laserDot = Instance.new("Part")
					laserDot.Transparency = 1
					laserDot.Name = "laserDot"
					laserDot.Anchored = true
					laserDot.CanCollide = false
					laserDot.FormFactor = Enum.FormFactor.Custom
					laserDot.Size = Vector3.new(0.25, 0.25, 1)

					local laserGui = Instance.new("SurfaceGui")
					laserGui.CanvasSize = Vector2.new(100, 100)
					laserGui.Parent = laserDot

					local laserImage = Instance.new("ImageLabel")
					laserImage.BackgroundTransparency = 1
					laserImage.Size = UDim2.new(1, 0, 1, 0)
					laserImage.Image = "http://www.roblox.com/asset/?id=131394739"
					laserImage.Parent = laserGui

					--[[local laserLight = Instance.new("SurfaceLight")
					laserLight.Angle = 180
					laserLight.Brightness = math.huge
					laserLight.Color = Color3.new(1, 0, 0)
					laserLight.Face = Enum.NormalId.Back
					laserLight.Range = 5
					laserLight.Shadows = true
					laserLight.Parent = laserDot]]

					return laserDot
				end

				local function getHitSurfaceCFrame(Pos, Obj) --This function returns the proper cframe based on the face that the position is on
					local surfaceCF = {
						{ "Back", Obj.CFrame * CFrame.new(0, 0, Obj.Size.z) },
						{ "Bottom", Obj.CFrame * CFrame.new(0, -Obj.Size.y, 0) },
						{ "Front", Obj.CFrame * CFrame.new(0, 0, -Obj.Size.z) },
						{ "Left", Obj.CFrame * CFrame.new(-Obj.Size.x, 0, 0) },
						{ "Right", Obj.CFrame * CFrame.new(Obj.Size.x, 0, 0) },
						{ "Top", Obj.CFrame * CFrame.new(0, Obj.Size.y, 0) },
					}
					local closestDist = math.huge
					local closestSurface = nil
					for _, v in pairs(surfaceCF) do
						local surfaceDist = (Pos - v[2].p).magnitude
						if surfaceDist < closestDist then
							closestDist = surfaceDist
							closestSurface = v
						end
					end

					local surfaceDir = CFrame.new(Obj.CFrame.p, closestSurface[2].p)
					local surfaceDist = surfaceDir.lookVector
						* ((Obj.CFrame.p - closestSurface[2].p).magnitude / 2 - 0.25)
					local surfaceOffset = Pos - closestSurface[2].p + surfaceDist
					local surfaceCFrame = surfaceDir + surfaceDist + surfaceOffset

					return surfaceCFrame
				end

				local laserDot = createLaserDot() --The code is cleaner when the laser creating code is in a function

				Laser.Transparency = (Laser.Transparency == 1 and 0 or 1) --Toggles the laser on or off

				while math.floor(Laser.Transparency) == 0 do --This loop will keep running as long as the laser is visible
					if not game.Players:GetPlayerFromCharacter(Gun.Parent) then
						break
					end --This checks if the gun is a child of the character

					local newRay = Ray.new(Laser.Position, Handle.CFrame.lookVector * 999)
					local H, P = game.Workspace:FindPartOnRayWithIgnoreList(newRay, ignoreList)

					if H and (H and H.Transparency >= 1 or H.CanCollide == false) then
						table.insert(ignoreList, H)
					end

					local Distance = (P - Laser.Position).magnitude
					Laser.Mesh.Offset = Vector3.new(0, Distance / 2, 0)
					Laser.Mesh.Scale = Vector3.new(0.075, Distance / 0.2, 0.075)

					if H then
						laserDot.CFrame = getHitSurfaceCFrame(P, H) --If the laser hits a part then position the dot on the part
						laserDot.Parent = playerFolder
					else
						laserDot.Parent = nil --If the laser doesn't hit a part then temporarily remove the laser dor
					end

					RS.RenderStepped:wait()
				end

				laserDot:Destroy() --These lines reset the laser if the laser is transparent or the gun was deselected
				Laser.Transparency = 1
				Laser.Mesh.Offset = Vector3.new()
				Laser.Mesh.Scale = Vector3.new(0.075, 0, 0.075)
			end,
		},
	},
}

return Plugins
