Advertisement
Nullify1

FE SMG's script

Aug 6th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.40 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local backpack, playergui = player:WaitForChild("Backpack"), player:WaitForChild("PlayerGui")
  3. repeat wait(0.1) until player.Character
  4. local char, camera = player.Character, workspace.CurrentCamera
  5. local tool = script.Parent
  6. local handle = tool:WaitForChild("Handle")
  7. local barrel = tool:WaitForChild("Barrel")
  8. local GunGUI = tool:WaitForChild("GunGUI")
  9. local event = game.ReplicatedStorage:WaitForChild("ClientConnection")
  10.  
  11. local create = assert(LoadLibrary("RbxUtility")).Create
  12. local storage = game:GetService("ReplicatedStorage")
  13. local debris = game:GetService("Debris")
  14.  
  15. local cframe, cframeXYZ, vector = CFrame.new, CFrame.fromEulerAnglesXYZ, Vector3.new
  16.  
  17. local arms = {
  18. Left = cframe(0.9,0.8,0.5) * cframeXYZ(math.rad(280),math.rad(40),math.rad(-2)),
  19. Right = cframe(-1,0.1,0.35) * cframeXYZ(math.rad(-90),math.rad(-15),math.rad(0)),
  20. }
  21.  
  22. local creator = create("ObjectValue"){Name = "creator", Value = player}
  23. local laser = create("Part"){Name = "Ray", Anchored = true, CanCollide = false, formFactor = 0, Material = "Neon", Size = vector(1, 1, 1), Reflectance = 0, Transparency = 0.5}
  24. local mesh = create("BlockMesh"){Parent = laser, Name = "Mesh"}
  25.  
  26. local armToggle = char:FindFirstChild("armToggle") and char.armToggle or create("BoolValue"){Parent = char, Name = "armToggle"}
  27.  
  28. local settings = require(tool.Settings)
  29. mag = settings.clip
  30.  
  31. local equipped = false
  32. local mouseDown = false
  33. local reloading = false
  34. local canFire = true
  35. local firing = false
  36.  
  37. local crouch = false
  38.  
  39. if tool:FindFirstChild("used") then
  40. mag = 0
  41. else
  42. create("ObjectValue"){Name = "used", Parent = tool}
  43. end
  44.  
  45. local welding = {}
  46. welding.Weld = create("Weld"){}
  47.  
  48. function welding.SetArms(bool)
  49. if settings.animationtype == "Weld" then
  50. event:FireServer({["Function"] = "Weld", ["Bool"] = bool})
  51. elseif settings.animationtype == "Animations" and settings.animationsfolder ~= nil then
  52. local default = settings.animationsfolder:FindFirstChild("Default")
  53. local reload = settings.animationsfolder:FindFirstChild("Reload")
  54. local crouch = settings.animationsfolder:FindFirstChild("Crouch")
  55. local sprint = settings.animationsfolder:FindFirstChild("Sprint")
  56. if default and reload and crouch and sprint and bool then
  57. defaultanimation = char.Humanoid:LoadAnimation(default)
  58. reloadanimation = char.Humanoid:LoadAnimation(reload)
  59. crouchanimation = char.Humanoid:LoadAnimation(crouch)
  60. sprintanimation = char.Humanoid:LoadAnimation(sprint)
  61. defaultanimation:Play()
  62. local con
  63. con = defaultanimation.KeyframeReached:connect(function(keyframeName)
  64. con:disconnect()
  65. if keyframeName == "Finish" then
  66. defaultanimation:AdjustSpeed(0)
  67. end
  68. end)
  69. end
  70. else
  71. defaultanimation:Stop()
  72. reloadanimation:Stop()
  73. crouchanimation:Stop()
  74. sprintanimation:Stop()
  75. end
  76. end
  77.  
  78. function welding.Default(...)
  79. char.Humanoid.WalkSpeed = 16
  80. if settings.animationtype == "Weld" then
  81. event:FireServer({["Function"] = "Stance", ["Type"] = "Default"})
  82. if char and char:FindFirstChild("Torso") and char.Torso:FindFirstChild("Weld1") and char.Torso:FindFirstChild("Weld2") then
  83. local Left = char.Torso:FindFirstChild("Weld1")
  84. local Right = char.Torso:FindFirstChild("Weld2")
  85. Left.C1 = arms.Left
  86. Right.C1 = arms.Right
  87. end
  88. elseif settings.animationtype == "Animations" then
  89. sprintanimation:Stop()
  90. end
  91. end
  92.  
  93. function welding.Holster(...)
  94. if settings.animationtype == "Weld" then
  95. event:FireServer({["Function"] = "Stance", ["Type"] = "Sprint"})
  96. local left = char.Torso:FindFirstChild("Weld1")
  97. local right = char.Torso:FindFirstChild("Weld2")
  98. if left and right then
  99. right.C1 = arms.Right * CFrame.Angles(math.pi/6, -math.pi/6, 0) * CFrame.new(-0.5, 0.1, 0)
  100. left.C1 = arms.Left * CFrame.Angles(math.pi/6, 0, 0) * CFrame.new(0.5, -0.5, -0.5)
  101. end
  102. elseif settings.animationtype == "Animations" then
  103. local con
  104. sprintanimation:Play()
  105. con = sprintanimation.KeyframeReached:connect(function(keyframeName)
  106. con:disconnect()
  107. if keyframeName == "Finish" then
  108. sprintanimation:AdjustSpeed(0)
  109. end
  110. end)
  111. end
  112. end
  113.  
  114. function welding.Crouch(bool)
  115. if settings.animationtype == "Weld" then
  116. event:FireServer({["Function"] = "Stance", ["Type"] = "Crouch", ["Bool"] = bool})
  117. elseif settings.animationtype == "Animations" then
  118. if bool then
  119. local con
  120. crouchanimation:Play()
  121. con = crouchanimation.KeyframeReached:connect(function(keyframeName)
  122. con:disconnect()
  123. if keyframeName == "Finish" then
  124. crouchanimation:AdjustSpeed(0)
  125. end
  126. end)
  127. else
  128. crouchanimation:Stop()
  129. end
  130. end
  131. end
  132.  
  133. local remote = game.ReplicatedStorage:WaitForChild("ReloadConnection")
  134. function welding.Animations()
  135. welding.Default()
  136. if settings.animationtype == "Weld" and settings.reloadanimation == true then
  137. local s, m = pcall(function() return remote:InvokeServer()end)
  138. if s then
  139. print("Reloaded")
  140. welding.Default()
  141. else
  142. print("Did not reload properly")
  143. welding.Default()
  144. end
  145. elseif settings.animationtype == "Animations" then
  146. reloadanimation:Play()
  147. reloadanimation:AdjustSpeed(settings.reloadanimationtempo)
  148. wait(settings.animationonlyreload)
  149. else
  150. wait(2.36)
  151. end
  152. end
  153.  
  154. local call = {}
  155.  
  156. function call.UpdateGui(...)
  157. if playergui:FindFirstChild("GunGUI") then
  158. playergui.GunGUI.Main.Ammo.Text = mag
  159. playergui.GunGUI.Main.GunMain.AmmoBar2.Size = UDim2.new(mag/settings.clip, 0, 1, 0)
  160. end
  161. end
  162.  
  163. function call.GetPlayer(hit)
  164. if hit and hit.Parent then
  165. if hit.Parent:FindFirstChild("Humanoid") then
  166. return hit.Parent.Humanoid
  167. elseif hit.Parent.Parent:FindFirstChild("Humanoid") then
  168. return hit.Parent.Parent.Humanoid
  169. end
  170. end
  171. end
  172.  
  173. local gun = {}
  174.  
  175. function gun.Raycast(init, last, ign)
  176. local dir = (last-init).unit
  177. local ray = Ray.new(init, dir*999)
  178. local hit, at = workspace:FindPartOnRayWithIgnoreList(ray, ign)
  179. if hit and at and hit.Name == "Ray" then
  180. hit, at = gun.Raycast(at, dir*999, ign)
  181. end
  182. return hit, at
  183. end
  184.  
  185. function gun.Fire(focus, mouse)
  186. local interval = (barrel.Position-focus).magnitude
  187. local min, max = -(settings.spread/100)*interval, (settings.spread/100)*interval
  188. local aim = vector((focus.x)+(math.random(min, max)), (focus.y)+(math.random(min, max)), (focus.z)+(math.random(min, max)))
  189. local hitPart, hitPos = gun.Raycast(char.Head.Position, aim, {char})
  190. local length, orientation = (barrel.Position-hitPos).magnitude, cframe(barrel.Position, hitPos)
  191. event:FireServer({["Function"] = "Ray", ["Client"] = player, ["Color"] = settings.raycolor, ["Orientation"] = orientation, ["Length"] = length, ["Thickness"] = settings.raythickness, ["Barrel"] = barrel, ["Decay"] = settings.raydecaytime})
  192. local laser1 = laser:clone()
  193. laser1.BrickColor = settings.raycolor
  194. barrel.Light.Color = settings.raycolor.Color
  195. laser1.CFrame = orientation * cframe(0, 0, -length/2)
  196. laser1.Mesh.Scale = vector(settings.raythickness, settings.raythickness, length)
  197. laser1.Parent = workspace
  198. game.Debris:AddItem(laser1, settings.raydecaytime)
  199. if hitPart then
  200. local hum = call.GetPlayer(hitPart)
  201. if hum then
  202. local target = game.Players:playerFromCharacter(hum.Parent)
  203. if not settings.teamkill and (target and target.TeamColor ~= player.TeamColor) or settings.teamkill then
  204. if hum.Health > 0 and playergui:FindFirstChild("GunGUI") then
  205. playergui:FindFirstChild("GunGUI").Hit.Rotation = math.random(1, 360)
  206. playergui:FindFirstChild("GunGUI").Hit.Visible = true
  207. delay(0.1, function()
  208. playergui:FindFirstChild("GunGUI").Hit.Visible = false
  209. end)
  210. end
  211. event:FireServer({["Function"] = "Hurt", ["Victim"] = hum, ["Damage"] = settings.damage})
  212. end
  213. end
  214. end
  215. end
  216.  
  217.  
  218. function gun.Reload(mouse)
  219. barrel.Light.Enabled = false
  220. call.UpdateGui()
  221. if not reloading then
  222. if mag < settings.clip and equipped then
  223. reloading = true
  224. char.Humanoid.WalkSpeed = 16
  225. spawn(function()
  226. for i = 1, 3 do
  227. if playergui:FindFirstChild("GunGUI") and reloading and equipped then
  228. playergui:FindFirstChild("GunGUI").Main.Ammo.Text = "REL" .. string.rep(".", i)
  229. wait(0.4)
  230. else
  231. break
  232. end
  233. end
  234. end)
  235. handle.Reload:Play()
  236. welding.Animations()
  237. if not reloading or not equipped then return end
  238. mag = settings.clip
  239. reloading = false
  240. call.UpdateGui()
  241. end
  242. end
  243. end
  244.  
  245. local bindings = {}
  246.  
  247. function bindings.KeyPressed(key, mouse)
  248. local key = key:lower()
  249. if key == "r" and not reloading and not mouseDown then
  250. gun.Reload(mouse)
  251. elseif key == "f" and not reloading and not mouseDown then
  252. if armToggle.Value then
  253. armToggle.Value = false
  254. char.Humanoid.WalkSpeed = 16
  255. welding.Default()
  256. else
  257. armToggle.Value = true
  258. char.Humanoid.WalkSpeed = settings.sprintspeed
  259. welding.Crouch(false)
  260. welding.Holster()
  261. end
  262. elseif key == "c" and not armToggle.Value then
  263. if crouch then
  264. crouch = false
  265. char.Humanoid.WalkSpeed = 16
  266. welding.Crouch(false)
  267. welding.Default()
  268. else
  269. crouch = true
  270. armToggle.Value = false
  271. char.Humanoid.WalkSpeed = settings.crouchspeed
  272. --welding.Default()
  273. welding.Crouch(true)
  274. end
  275. end
  276. end
  277.  
  278. function bindings.MouseClick(mouse)
  279. if equipped and not mouseDown and not reloading and canFire and char.Humanoid.Health > 0 then
  280. mouseDown = true
  281. call.UpdateGui()
  282. welding.Default()
  283. armToggle.Value = false
  284. barrel.Light.Enabled = true
  285. if settings.fireMode == "Auto" then
  286. while mouseDown and char.Humanoid.Health > 0 and canFire and mag > 0 and equipped do
  287. call.UpdateGui()
  288. barrel.Light.Angle = math.random(90, 180)
  289. mag = mag - 1
  290. gun.Fire(mouse.hit.p, mouse)
  291. handle.Fire:Play()
  292. handle.Parent.Barrel.Flash.Light.Rotation = math.random(0, 90)
  293. handle.Parent.Barrel.Flash.Enabled = true
  294. canFire = false
  295. wait(settings.firerate)
  296. canFire = true
  297. end
  298. elseif settings.fireMode == "Semi" then
  299. barrel.Light.Angle = math.random(90, 180)
  300. mag = mag - 1
  301. gun.Fire(mouse.hit.p, mouse)
  302. handle.Fire:Play()
  303. handle.Parent.Barrel.Flash.Enabled = true
  304. canFire = false
  305. wait(settings.firerate)
  306. canFire = true
  307. end
  308. if mag <= 0 then
  309. gun.Reload(mouse)
  310. end
  311. call.UpdateGui()
  312. barrel.Light.Enabled = false
  313. handle.Parent.Barrel.Flash.Enabled = false
  314. end
  315. end
  316.  
  317. function bindings.MouseRelease(mouse)
  318. mouseDown = false
  319. barrel.Light.Enabled = false
  320. handle.Parent.Barrel.Flash.Enabled = false
  321. end
  322.  
  323. char.Humanoid.Changed:connect(function(p)
  324. if p == "Health" and char.Humanoid.Health <= 0 then
  325. tool:Destroy()
  326. end
  327. end)
  328.  
  329. tool.Equipped:connect(function(mouse)
  330. wait()
  331. welding.SetArms(true)
  332. equipped = true
  333. local newGui = GunGUI:Clone()
  334. newGui.Parent = playergui
  335. call.UpdateGui()
  336. mouse.Button1Down:connect(function() bindings.MouseClick(mouse) end)
  337. mouse.Button1Up:connect(function() bindings.MouseRelease(mouse) end)
  338. mouse.KeyDown:connect(function(key) bindings.KeyPressed(key, mouse) end)
  339. mouse.Move:connect(function()
  340. if equipped and playergui:FindFirstChild("GunGUI") then
  341. playergui:FindFirstChild("GunGUI").Hit.Position = UDim2.new(0, mouse.X-22.5, 0, mouse.Y-22.5)
  342. end
  343. end)
  344. end)
  345. tool.Unequipped:connect(function(mouse)
  346. if playergui:FindFirstChild("GunGUI") then
  347. playergui:FindFirstChild("GunGUI"):Destroy()
  348. end
  349. welding.SetArms(false)
  350. equipped = false
  351. mouseDown = false
  352. crouch = false
  353. welding.Crouch(false)
  354. reloading = false
  355. barrel.Light.Enabled = false
  356. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement