Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.63 KB | None | 0 0
  1. local weaponHandler = {
  2. debugmode = true
  3. }
  4.  
  5. --Modules
  6. local spring = require(script:WaitForChild("SpringModule"))
  7. local fastcast = require(game.ReplicatedStorage:WaitForChild("Values"):WaitForChild("FastCast"))
  8. local services = require(script.Parent.RevolutionaryServices)
  9. local cs = require(script.Parent.CustomVariable)
  10. --Services
  11. local tweenService = services.tweenService
  12.  
  13.  
  14. --Functions
  15. local random = Random.new()
  16.  
  17. --Variables
  18. local inChat
  19. local hitParticlesEnabled
  20. local currentWeapon
  21. local savedWeapon
  22. local lastHealth = 100
  23.  
  24.  
  25. local movements = {
  26. default = game.ReplicatedStorage.Values.WalkingSpeed.Normal.Value;
  27. aiming = game.ReplicatedStorage.Values.WalkingSpeed.Aiming.Value;
  28. running = game.ReplicatedStorage.Values.WalkingSpeed.Running.Value;
  29. crouching = game.ReplicatedStorage.Values.WalkingSpeed.Crouching.Value
  30. }
  31.  
  32. local concreteSounds = {
  33. [1] = "rbxassetid://3689488418";
  34. [2] = "rbxassetid://3689488700";
  35. [3] = "rbxassetid://3689489022";
  36. [4] = "rbxassetid://3689489347";
  37. }
  38.  
  39. local plasticSounds = {
  40. [1] = "rbxassetid://3689396192";
  41. [2] = "rbxassetid://3689396705";
  42. [3] = "rbxassetid://3689397197";
  43. }
  44.  
  45. local metalSounds = {
  46. [1] = "rbxassetid://3689482778";
  47. [2] = "rbxassetid://3689483148";
  48. [3] = "rbxassetid://3689483453";
  49. [4] = "rbxassetid://3689483722";
  50. [5] = "rbxassetid://3689484031";
  51. [6] = "rbxassetid://3689484356";
  52. }
  53.  
  54. local woodSounds = {
  55. [1] = "rbxassetid://3689542185";
  56. [2] = "rbxassetid://3689542521";
  57. [3] = "rbxassetid://3689542840";
  58. [4] = "rbxassetid://3689543089";
  59. [5] = "rbxassetid://3689543346";
  60. }
  61.  
  62. local glassSounds = {
  63. [1] = "rbxassetid://3689485735";
  64. [2] = "rbxassetid://3689485998";
  65. [3] = "rbxassetid://3689486291";
  66. [4] = "rbxassetid://3689486556";
  67. }
  68.  
  69. local dirtSounds = {
  70. [1] = "rbxassetid://3689528116";
  71. [2] = "rbxassetid://3689528507";
  72. }
  73.  
  74. local materials = {
  75. { material = Enum.Material.Concrete, effect = "Rocks"; sounds = concreteSounds };
  76. { material = Enum.Material.Grass, effect = "Dust"; sounds = dirtSounds };
  77. { material = Enum.Material.Wood, effect = "Dust"; sounds = woodSounds };
  78. { material = Enum.Material.CorrodedMetal, effect = "Sparks"; sounds = metalSounds };
  79. { material = Enum.Material.Brick, effect = "Rocks"; sounds = concreteSounds };
  80. { material = Enum.Material.Sand, effect = "Dust"; sounds = dirtSounds };
  81. { material = Enum.Material.Metal, effect = "Sparks"; sounds = metalSounds };
  82. { material = Enum.Material.Neon, effect = "NeonSpecific"; sounds = metalSounds };
  83. { material = Enum.Material.Cobblestone, effect = "Rocks"; sounds = concreteSounds };
  84. { material = Enum.Material.Pebble, effect = "Dust"; sounds = concreteSounds };
  85. { material = Enum.Material.SmoothPlastic, effect = "Dust"; sounds = plasticSounds };
  86. { material = Enum.Material.Fabric, effect = "Dust"; sounds = plasticSounds };
  87. { material = Enum.Material.Granite, effect = "Rocks"; sounds = concreteSounds };
  88. { material = Enum.Material.Plastic, effect = "Dust"; sounds = plasticSounds };
  89. { material = Enum.Material.Slate, effect = "Dust"; sounds = concreteSounds};
  90. { material = Enum.Material.WoodPlanks, effect = "Dust"; sounds = woodSounds };
  91. { material = Enum.Material.Foil, effect = "Dust"; sounds = plasticSounds };
  92. { material = Enum.Material.DiamondPlate, effect = "Sparks"; sounds = metalSounds };
  93. { material = Enum.Material.Ice, effect = "Dust"; sounds = glassSounds };
  94. { material = Enum.Material.Glass, effect = "Dust"; sounds = glassSounds };
  95. { material = Enum.Material.Marble, effect = "Dust"; glassSounds}
  96.  
  97. }
  98.  
  99. local LeanLeftP = { Value = -0.1 }
  100. local LeanRightP = { Value = 0.1 }
  101. local NoState = { Value = 0 }
  102. local leanLeftP = { CameraOffset = Vector3.new(-1,0,0) }
  103. local leanRightP = { CameraOffset = Vector3.new(1,0,0) }
  104. local stateResetP = { CameraOffset = Vector3.new(0,0,0) }
  105. local crouchInP = { CameraOffset = Vector3.new(0,-1.5,0) }
  106. local crouchOutP = { CameraOffset = Vector3.new(0,0,0) }
  107. local aimInP = { Value = 1 }
  108. local aimOutP = { Value = 0 }
  109. local tweenProperties = TweenInfo.new(0.3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
  110.  
  111. local defaultMovement = 0.6
  112. local aimingMovement = 0.1
  113. local runningMovement = 2
  114. local crouchingMovement = 1.5
  115.  
  116. local equipping = true
  117. local canEquip = true
  118. local canRun = true
  119. local canAim = true --stops aiming
  120. local aiming = false
  121. local running = false
  122. local canShoot = false
  123. local canFire = true --different from canshoot, stops loop spam
  124. local shooting = false
  125. local reloading = false
  126. local canReload = true
  127. local vaulting = false
  128. local canVault = true
  129. local crouching = false
  130. local canCrouch = true
  131. local walled = false
  132. local walledVariable = script:WaitForChild("Walled")
  133.  
  134. local equipEvent = game.ReplicatedStorage.Equip --for requesting the weapon
  135.  
  136. function fireSpark(laser)
  137.  
  138. local lastPosition
  139. local maxDistance = 100
  140. local curDistance = 0
  141.  
  142. local stepDistance = 2.5
  143. local stepWait = 0
  144.  
  145. local currentPos = laser.Position
  146. local currentNormal = laser.CFrame.LookVector
  147. local overrideDistance = nil
  148. local timesBounced = 0.01
  149.  
  150. repeat
  151.  
  152. local ray = Ray.new(currentPos, currentNormal * (overrideDistance or stepDistance))
  153. local hit, pos, norm = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
  154.  
  155. -- Update laser position:
  156. laser.Size = Vector3.new(0.05, 0.05, (pos - currentPos).Magnitude - timesBounced / 3)
  157. laser.CFrame = CFrame.new(currentPos:Lerp(pos, 0.5), pos)
  158.  
  159. local oldPos = currentPos
  160. currentPos = pos
  161.  
  162. overrideDistance = nil
  163. if (hit) then
  164.  
  165. timesBounced = timesBounced + 1
  166. local reflect = (currentNormal - (2 * currentNormal:Dot(norm) * norm))
  167. currentNormal = reflect
  168. overrideDistance = stepDistance - (pos - oldPos).Magnitude
  169. if stepDistance ~= 0 then
  170. stepDistance = stepDistance - 0.5
  171. end
  172. -- return
  173. else
  174. laser.CFrame = laser.CFrame * CFrame.Angles(-.1,0,0)
  175. currentPos = laser.Position
  176. currentNormal = laser.CFrame.LookVector
  177. end
  178.  
  179. if lastPosition == laser.Position then break end
  180. lastPosition = laser.Position
  181. laser.Transparency = 0
  182. curDistance = (curDistance + (pos - oldPos).Magnitude)
  183.  
  184. -- Apply fade effect to laser as it approaches max distance from < 75 studs:
  185. if (curDistance > (maxDistance - 75)) then
  186. local d = (curDistance - (maxDistance - 75)) / 75
  187. laser.Transparency = d
  188. end
  189.  
  190. game:GetService("RunService").RenderStepped:Wait()
  191.  
  192. until curDistance >= maxDistance
  193.  
  194. -- Done! Destroy laser:
  195. laser:Destroy()
  196.  
  197. end
  198.  
  199. function weaponHandler.equip(self,choice)
  200.  
  201. local gun = {}
  202. local killed = false --whether the gun was removed
  203.  
  204. local Caster = fastcast.new()
  205. Caster.Gravity = 40 --Set the values accordingly.
  206. Caster.ExtraForce = Vector3.new()
  207.  
  208. if not canEquip or equipping then wait(0.3) end
  209. if not choice or typeof(choice) ~= "string" then warn("Choice is not a string, choosing primary.") choice = "Primary" end
  210.  
  211. local localPlayer = game.Players.LocalPlayer
  212. local localCharacter = localPlayer.Character
  213. local localHumanoid = localCharacter.Humanoid
  214. local localRoot = localCharacter.HumanoidRootPart
  215. local localProperties = localPlayer:WaitForChild("Values"):WaitForChild("Properties")
  216. local localHumanoidState = localCharacter:WaitForChild("State")
  217.  
  218. local viewmodel = game.ReplicatedStorage.Viewmodel:Clone()
  219. local weapon = equipEvent:InvokeServer(choice)
  220. local weaponProperties = weapon.Properties
  221. local cameraTarget = viewmodel.Camera
  222.  
  223. localPlayer:GetMouse().Icon = "rbxassetid://45312113"
  224. weapon.Parent = viewmodel
  225. viewmodel.Parent = workspace
  226. weapon.MainBody.Hold.Part0 = viewmodel:FindFirstChild("Right Arm")
  227.  
  228. for i,v in pairs(viewmodel:GetDescendants()) do
  229. if v:IsA("Part") or v:IsA("MeshPart") then
  230. v.CastShadow = false
  231. end
  232. end
  233.  
  234. local sounds = {
  235. jump = localRoot.Jump;
  236. landing = localRoot.Landing;
  237. crouchSound = localRoot.Crouch;
  238. footPlant = localRoot.FootPlant1;
  239. footPlantAlt = localRoot.FootPlant2
  240. }
  241.  
  242. local aimingTween = script.AimingTween
  243.  
  244. local crouchIn = tweenService:Create(localHumanoid,tweenProperties,crouchInP)
  245. local crouchOut = tweenService:Create(localHumanoid,tweenProperties,crouchOutP)
  246.  
  247. local leanLeft = tweenService:Create(localHumanoid,tweenProperties,leanLeftP)
  248. local leanRight = tweenService:Create(localHumanoid,tweenProperties,leanRightP)
  249. local leanOut = tweenService:Create(localHumanoid,tweenProperties,stateResetP)
  250.  
  251. local aimIn = tweenService:Create(aimingTween,tweenProperties,aimInP)
  252. local aimOut = tweenService:Create(aimingTween,tweenProperties,aimOutP)
  253.  
  254. local leanVLeft = tweenService:Create(script:WaitForChild("Lean"),tweenProperties,LeanLeftP)
  255. local leanVRight = tweenService:Create(script:WaitForChild("Lean"),tweenProperties,LeanRightP)
  256. local LeanVOut = tweenService:Create(script:WaitForChild("Lean"),tweenProperties,NoState)
  257.  
  258. local wallIn = tweenService:Create(script:WaitForChild("Walled"),tweenProperties,{ Value = 2 })
  259. local wallOut = tweenService:Create(script:WaitForChild("Walled"),tweenProperties,{ Value = 0 })
  260.  
  261. local Spring = spring:create(3.5,200,25,2)
  262. local CameraSpring = spring:create(8,100,6,4)
  263. local IdleSpring = spring:create(8,100,6,4)
  264. local CamOffsetSpring = spring:create(3.5,200,25,2)
  265.  
  266. local localVaultAnim = viewmodel.Humanoid:LoadAnimation(game.ReplicatedStorage.Values.PlayerAnims.VaultLocal)
  267. local serverVaultAnim = game.ReplicatedStorage.Values.PlayerAnims.VaultBig
  268. local equipAnim = viewmodel.Humanoid:LoadAnimation(weaponProperties.Equip.Client)
  269. local idleAnim = viewmodel.Humanoid:LoadAnimation(weaponProperties.Idle.Client)
  270. local aimAnim = viewmodel.Humanoid:LoadAnimation(weaponProperties.Aim.Client)
  271. local runAnim = viewmodel.Humanoid:LoadAnimation(weaponProperties.Running.Client)
  272. local fireAnim = viewmodel.Humanoid:LoadAnimation(weaponProperties.Fire.Client)
  273. local fireAim = viewmodel.Humanoid:LoadAnimation(weaponProperties.AimShot.Client)
  274. local magSwitchAnim = viewmodel.Humanoid:LoadAnimation(weaponProperties.MagSwitch.Client)
  275. local pullBoltAnim = viewmodel.Humanoid:LoadAnimation(weaponProperties.BoltBack.Client)
  276. local showAnim
  277. local serverAnimations = {}
  278.  
  279. local showExists = weaponProperties:FindFirstChild("Show")
  280. if showExists then
  281. showAnim = viewmodel.Humanoid:LoadAnimation(showExists.Client)
  282. else
  283. warn("No showcase animation added for "..weapon.Name..", continuing")
  284. end
  285.  
  286.  
  287. local flagged = false --for making bobble work for the first update loop
  288. local jumpHeight = 0
  289. local controlsEnabled = false --enables all module functions
  290. local broken = false --if aiming was broken
  291. local distanceToGoal = 15 --for aiming, how far from end of lerp
  292. local movementStart = 1 --for linearly increasing the movement bobbing when you start moving
  293. local relativeCamSpeed --WASD movement signifier, velocity relative to root
  294. local moving = false --controlled by velocity magnitude
  295. local runUpdateLoop = true --repurposed to not move the viewmodel if not true
  296. local ranLastFrame = true --for avoiding the tilt glitch
  297. local useCustomOffset = false --to use custom offset
  298. local customOffset --the custom offset itself
  299. local canUnAim = true
  300. local loopBroken = false
  301.  
  302. --ViewBobbing values for OnUpdate()
  303. local dt = 0 --deltatime for onupdate() viewmodel()
  304. local tiltBobble = 0 --tiltbobble, removed from bobble vector3 for visual weapon recoil
  305. local idleBobble
  306. local springDivider = 1
  307. local mouseDelta
  308. local deltaX
  309. local deltaY
  310. local bobbleX = 0
  311. local bobbleY = 0
  312. local bobble = Vector3.new(0,0,0)
  313. local camTilt = Vector3.new() --for smooth cameratilt
  314.  
  315. --Custom enums
  316. local regular = false
  317. local custom = true
  318.  
  319. local ammo = localProperties:FindFirstChild(choice.."Ammo").Value
  320. local rpm = weaponProperties.RPM.Value
  321. local recoilx = weaponProperties.RecoilX.Value
  322. local recoily = weaponProperties.RecoilY.Value
  323. local bulletVelocity = weaponProperties.BulletVelocity.Value
  324. local permag = weaponProperties.PerMag.Value
  325.  
  326. local leaningStates = {
  327. left = false,
  328. right = false
  329. }
  330. local canLean = true
  331. local leaning
  332.  
  333.  
  334. local function onRayHit(hitPart, hitPoint, normal, material, bullet)
  335.  
  336. if hitPart then
  337. spawn(function()
  338. local identity = bullet.Identity.Value
  339. while not identity do identity = bullet.Identity.Value wait() end
  340.  
  341. bullet:Destroy()
  342.  
  343. local response,warning = game.ReplicatedStorage.HitEvent:InvokeServer(hitPart,hitPoint,tonumber(identity))
  344. if response then if warning then warn(response) else print(response) end end
  345. end)
  346. end
  347.  
  348. if hitPart then
  349. local sparkDirection = CFrame.new(hitPoint, hitPoint + normal)
  350. local effectType
  351. local playerHit = (hitPart.Parent:FindFirstChild("Humanoid") or hitPart.Parent.Parent:FindFirstChild("Humanoid"))
  352. local pointer = game.ReplicatedStorage.Pointer:Clone()
  353. pointer.Parent = viewmodel
  354.  
  355. local function shredDust(originWithNormals)
  356. if not pointer or not pointer:FindFirstChild("DustParticle") then return end
  357. local particle
  358.  
  359. pointer.CFrame = originWithNormals
  360.  
  361. if not playerHit then
  362. particle = pointer.DustParticle
  363. particle.Color = ColorSequence.new(hitPart.Color)
  364. else
  365. particle = pointer.PlayerParticle
  366. end
  367.  
  368. particle.Enabled = true
  369. wait(0.16)
  370. particle.Enabled = false
  371. wait(3)
  372. pointer:Destroy()
  373. end
  374.  
  375. for i,v in pairs(materials) do
  376. if v.material == material then
  377. effectType = v.effect
  378.  
  379. local sound = Instance.new("Sound")
  380. sound.SoundId = v.sounds[random:NextInteger(1,#v.sounds)]
  381. sound.Parent = pointer
  382. sound:Play()
  383.  
  384. end
  385. end
  386.  
  387. if playerHit then
  388. shredDust(sparkDirection)
  389. elseif effectType == "Sparks" or effectType == "Rocks" then
  390. spawn(function()
  391. shredDust(sparkDirection)
  392. end)
  393. for i = 1,random:NextNumber(4,8) do
  394. spawn(function()
  395. local spark = game.ReplicatedStorage.Spark:Clone()
  396. local reflect = CFrame.Angles(math.random(-1, 1)/2, math.random(-1, 1)/2, math.random(-1,1)/2)
  397. spark.Parent = pointer
  398. pointer.CFrame = sparkDirection
  399. spark.CFrame = pointer.CFrame:ToWorldSpace(CFrame.new(0,0,-1)) * reflect
  400. fireSpark(spark)
  401. end)
  402. end
  403. wait(5)
  404. pointer:Destroy()
  405.  
  406. elseif effectType == "Dust" then
  407. shredDust(sparkDirection)
  408. elseif effectType == "NeonSpecific" then
  409. spawn(function()
  410. for i = 1,25 do
  411. for i = 1,random:NextNumber(4,8) do
  412. spawn(function()
  413. local spark = game.ReplicatedStorage.Spark:Clone()
  414. local reflect = CFrame.Angles(math.random(-1, 1)/2, math.random(-1, 1)/2, math.random(-1,1)/2)
  415. spark.Parent = pointer
  416. pointer.CFrame = sparkDirection
  417. spark.CFrame = pointer.CFrame:ToWorldSpace(CFrame.new(0,0,-1)) * reflect
  418. fireSpark(spark)
  419. end)
  420. end
  421. wait(random:NextInteger(1,5))
  422. end
  423. end)
  424. for i = 1,26 do
  425. if hitPart.Material == Enum.Material.SmoothPlastic then
  426. hitPart.Material = Enum.Material.Neon
  427. else
  428. hitPart.Material = Enum.Material.SmoothPlastic
  429. end
  430. game:GetService("RunService").RenderStepped:Wait()
  431. end
  432. hitPart.Material = Enum.Material.SmoothPlastic
  433. end
  434. end
  435.  
  436. end
  437.  
  438. local lastID = 0
  439.  
  440. local function fireTracer(origin,direction,speed)
  441.  
  442. Caster.IgnoreDescendantsInstance = viewmodel
  443. local bullet = game.ReplicatedStorage.Tracer:Clone()
  444. bullet.Parent = viewmodel
  445.  
  446. local registeredOrigin = origin.CFrame:ToWorldSpace(CFrame.new())
  447. local directionalCF = CFrame.new(Vector3.new(), direction)
  448. local direction = (directionalCF * CFrame.fromOrientation(0, 0, random:NextNumber(0, math.pi * 2)) * CFrame.fromOrientation(math.rad(random:NextNumber(0,0.01)), 0, 0)).LookVector
  449. local myMovementSpeed = (-localRoot.Velocity)
  450. local modifiedBulletSpeed = (direction * speed) + myMovementSpeed
  451.  
  452. bullet.CFrame = CFrame.new(registeredOrigin.Position, registeredOrigin.Position + direction)
  453. bullet.Trail.Attachment0 = weapon.MainBody.barrel.Attachment
  454.  
  455. local IgnoreList = {
  456. viewmodel,
  457. localPlayer.Character
  458. }
  459.  
  460. spawn(function()
  461. local id = lastID + 1
  462. lastID = lastID + 1
  463. if lastID >= 10000 then lastID = 0 end
  464. bullet.Identity.Value = id
  465. local response,warning = game.ReplicatedStorage.FiringEvent:InvokeServer(localCharacter.Head.CFrame,direction,id)
  466. if response then if warning then warn(response) else print(response) end end
  467. end)
  468. Caster:FireWithBlacklist(registeredOrigin.Position, direction * speed, modifiedBulletSpeed, IgnoreList, bullet)
  469.  
  470. end
  471.  
  472. local function onRayUpdated(CastOrigin, SegmentOrigin, SegmentDirection, Length, CosmeticBulletObject)
  473. local BulletLength = CosmeticBulletObject.Size.Z / 2 -- This is used to move the bullet to the right spot based on a CFrame offset
  474. CosmeticBulletObject.CFrame = CFrame.new(SegmentOrigin, SegmentOrigin + SegmentDirection) * CFrame.new(0, 0, -(Length - BulletLength))
  475. end
  476.  
  477. local function killEffect(i,multiplier)
  478. game.Lighting.ColorCorrection.Saturation = -(localHumanoid.Health / 100 - localHumanoid.Health / 100 * 2)
  479. game.Lighting.ColorCorrection.Saturation = game.Lighting.ColorCorrection.Saturation - 1
  480. game.Lighting.Blur.Size = -(localHumanoid.Health / 2) + 100 / i * multiplier
  481. game:GetService("RunService").RenderStepped:Wait()
  482. end
  483.  
  484. healthChanged = localHumanoid.HealthChanged:Connect(function()
  485. if localHumanoid.Health < lastHealth and game.Lighting:FindFirstChild("Blur") then
  486. lastHealth = localHumanoid.Health
  487. game.Lighting.Blur.Size = 40 / localHumanoid.Health
  488. spawn(function()
  489. CameraSpring:shove(Vector3.new(.5,0,0.3))
  490. wait(0.1)
  491. CameraSpring:shove(Vector3.new(-.3,0,-0.2))
  492. end)
  493. for i = 1,25 do
  494. killEffect(i,4)
  495. end
  496. elseif game.Lighting:FindFirstChild("Blur") then
  497. for i = 1,25 do
  498. killEffect(i,1)
  499. end
  500. end
  501. end)
  502.  
  503. local function humanoidChanged()
  504. if crouching or reloading then
  505. localHumanoid.Jump = false -- Yes, it's this simple
  506. end
  507. end
  508.  
  509. local function updateviewmodel(getoffset,typeofoffset)
  510. mouseDelta = game:GetService("UserInputService"):GetMouseDelta() --for viewmodel movement
  511. deltaX = mouseDelta.X
  512. deltaY = mouseDelta.Y
  513. relativecamspeed = localRoot.CFrame:VectorToObjectSpace(localRoot.Velocity)
  514.  
  515. CameraSpring:shove(Vector3.new(-(bobble.Y / 1500),-(bobble.X / 1500),0))
  516. Spring:shove(relativecamspeed / 2555)
  517. Spring:shove(Vector3.new(deltaX / 45,-deltaY / 45,0) / springDivider)
  518. Spring:shove(CFrame.new(bobble.X / 3,bobble.Y / 6,bobble.Z / 6))
  519. CameraSpring:shove(idleBobble / 255)
  520. if aiming then
  521. IdleSpring:shove(idleBobble / 5)
  522. else
  523. IdleSpring:shove(idleBobble / 1.1)
  524. end
  525. CamOffsetSpring:shove(Vector3.new(relativecamspeed.X / 500,relativecamspeed.Z / 500,-(relativecamspeed.X / 300)))
  526.  
  527. local pos = Spring:update(dt)
  528. local idlePos = IdleSpring:update(dt)
  529. local offsetPos = CamOffsetSpring:update(dt)
  530. pos = pos + idlePos
  531. local offset = workspace.Camera.CFrame:ToWorldSpace(CFrame.new(pos / 2) * CFrame.Angles(-walledVariable.Value / 3 + offsetPos.Y + pos.Y,walledVariable.Value / 2.5 + offsetPos.X + -pos.X,offsetPos.Z + (bobble.X / 50) + tiltBobble / 10) + Vector3.new(walledVariable.Value / 1.5,0,walledVariable.Value / 1.5))
  532.  
  533.  
  534. if not getoffset then --all of this crap is just for aiming, ugh
  535. local camPos = CameraSpring:update(dt)
  536. workspace.Camera.CFrame = workspace.Camera.CFrame:ToWorldSpace(CFrame.new(bobble / 25) * CFrame.Angles(camPos.X,camPos.Y,camPos.Z + -script.Lean.Value ) )
  537. if runUpdateLoop then
  538. if customoffset and usecustomoffset then --if the camtarget has a custom offset
  539. cameraTarget.CFrame = customoffset
  540. else
  541. cameraTarget.CFrame = offset * weaponProperties.CFrameOffset.Value
  542. end
  543. end
  544. else
  545. if typeofoffset == regular then
  546. return offset
  547. else
  548. return customoffset
  549. end
  550. end
  551. end
  552.  
  553. local function adjustAnimationSpeed(animation,speed)
  554. animation:AdjustSpeed(speed)
  555. for i,v in pairs(serverAnimations) do
  556. if v.Animation.Parent.Name == animation.Name then
  557. v:AdjustSpeed(speed)
  558. end
  559. end
  560. end
  561.  
  562. died = localHumanoid.Died:Connect(function() --when player dies, reset variables
  563. lastHealth = 100
  564. controlsEnabled = false
  565. if viewmodel then
  566. viewmodel.Parent = nil
  567. viewmodel = nil
  568. weapon.Parent = nil
  569. weapon = nil
  570. end
  571. usecustomoffset = false
  572. customoffset = CFrame.new()
  573. equipping = true
  574. canEquip = true
  575. running = false
  576. canAim = true --stops aiming
  577. aiming = false
  578. canRun = true
  579. running = false
  580. canFire = true --different from canshoot, stops fire loop spam
  581. shooting = false
  582. reloading = false
  583. canReload = true
  584. canCrouch = true
  585. crouching = false
  586. leaningState = false
  587. leaningStates.left = false
  588. leaningStates.right = false
  589. script.Lean.Value = 0
  590. springDivider = 1
  591. end)
  592.  
  593. local function viewmodelVisible(tomakeVisible) --for equipping weapons
  594. spawn(function()
  595. local transparency
  596. if tomakeVisible then
  597. transparency = 0
  598. else
  599. transparency = 1
  600. end
  601. local left = viewmodel:FindFirstChild("Left")
  602. local right = viewmodel:FindFirstChild("Right")
  603. left.Transparency = transparency
  604. right.Transparency = transparency
  605. for i,v in pairs(left:GetChildren()) do
  606. if v:IsA("Texture") or v:IsA("MeshPart") or v:IsA("Part") then
  607. v.Transparency = transparency
  608. end
  609. end
  610. for i,v in pairs(right:GetChildren()) do
  611. if v:IsA("Texture") or v:IsA("MeshPart") or v:IsA("Part") then
  612. v.Transparency = transparency
  613. end
  614. end
  615.  
  616. end)
  617. end
  618.  
  619. local function transitionMovement(desiredMovement)
  620. local Properties = { Value = desiredMovement }
  621. local TweenProperties = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
  622. local tween = tweenService:Create(script.modifier,TweenProperties,Properties)
  623. tween:Play()
  624. end
  625.  
  626. local function playAnimation(animation,playOnClient,playOnServer,fadeTime,speed) --for playing animations
  627. if not speed then speed = 1 end --variables that haven't been fed by the f unction are reset
  628. if not fadeTime then fadeTime = 0 end
  629. if playOnClient and animation then
  630. animation:Play(fadeTime,speed)
  631. end
  632. if playOnServer and animation then --i f the animation should replicate, run
  633. local loadedAnim
  634. if animation:IsA("Animation") then
  635. loadedAnim = localHumanoid:LoadAnimation(animation)
  636. else
  637. loadedAnim = localHumanoid:LoadAnimation(weaponProperties:FindFirstChild(animation.Animation.Parent.Name).Server)
  638. end
  639. loadedAnim:Play(fadeTime,speed)
  640. if animation:IsA("AnimationTrack") then
  641. animation.KeyframeReached:Connect(function(keyFrameName)
  642. local audio = weapon.MainBody:FindFirstChild(keyFrameName)
  643. audio.TimePosition = audio.TimePos.Value
  644. audio:Play()
  645. end)
  646. end
  647. spawn(function()
  648. if loadedAnim.Looped then
  649.  
  650. table.insert(serverAnimations,loadedAnim)
  651. local savedcurrentWeapon = currentWeapon
  652. repeat wait() until currentWeapon ~= savedcurrentWeapon or not loadedAnim.IsPlaying
  653. loadedAnim:Stop()
  654. for i,v in pairs(serverAnimations) do
  655. if v == loadedAnim then
  656. table.remove(serverAnimations,i)
  657. end
  658. end
  659. else
  660. table.insert(serverAnimations,loadedAnim)
  661. loadedAnim.Stopped:Wait()
  662. for i,v in pairs(serverAnimations) do
  663. if v == loadedAnim then
  664. table.remove(serverAnimations,i)
  665. end
  666. end
  667. end
  668. end)
  669. end
  670. end
  671.  
  672. local function stopServerAnimation(animname)
  673. for i,anim in pairs(serverAnimations) do
  674. if anim.Animation.Parent.Name == animname then
  675. anim:Stop()
  676. table.remove(serverAnimations,i)
  677. end
  678. end
  679. end
  680.  
  681. -- LOOPS --------------------------------------------------------------------------------------------------------------------------------------
  682.  
  683. spawn(function()
  684.  
  685. if weaponHandler.debugmode then
  686.  
  687. game.Players.LocalPlayer.PlayerGui:WaitForChild("Debug")
  688.  
  689. local fps = 0
  690. local framerate = 0
  691. local enabled = true
  692. local dir = game.Players.LocalPlayer.PlayerGui.Debug.Frame
  693.  
  694. game:GetService("RunService").RenderStepped:Connect(function()
  695. fps = fps + 1
  696. end)
  697.  
  698. spawn(function()
  699. while wait(1) do
  700. framerate = fps
  701. fps = 0
  702. end
  703. end)
  704.  
  705. game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
  706. if input.KeyCode == Enum.KeyCode.B then
  707. enabled = not enabled
  708. dir.Parent.Enabled = enabled
  709. end
  710. end)
  711.  
  712. while wait(0.2) do
  713. if killed then break end
  714. local variables = {
  715. {name = "ClientFramerate"; var = framerate};
  716. {name = "InChat"; var = InChat};
  717. {name = "ammo"; var = ammo};
  718. {name = "permag"; var = permag};
  719. {name = "bulletVelocity"; var = bulletVelocity};
  720. {name = "currentweapon"; var = currentWeapon};
  721. {name = "lastHealth"; var = lastHealth};
  722. {name = "flagged"; var = flagged};
  723. {name = "controlsEnabled"; var = controlsEnabled};
  724. {name = "aimingbroken/broken"; var = broken};
  725. {name = "distancetogoal"; var = distanceToGoal};
  726. {name = "movementstart"; var = movementStart};
  727. {name = "cameratarget"; var = cameraTarget};
  728. {name = "relativecamspeed"; var = relativecamspeed};
  729. {name = "moving"; var = moving};
  730. {name = "runupdateloop"; var = runUpdateLoop};
  731. {name = "ranlastframe"; var = ranlastframe};
  732. {name = "usecustomoffset"; var = usecustomoffset};
  733. {name = "customoffset"; var = customoffset};
  734. {name = "aimingtween"; var = aimingTween.Value};
  735. {name = "canunaim"; var = canUnAim};
  736. {name = "loopbroken"; var = loopBroken};
  737. {name = "deltatime"; var = dt};
  738. {name = "tiltbobble"; var = tiltBobble};
  739. {name = "springdivider"; var = springDivider};
  740. {name = "mousedelta"; var = mouseDelta};
  741. {name = "bobble"; var = bobble};
  742. {name = "camtilt"; var = camTilt};
  743. {name = "equipping"; var = equipping};
  744. {name = "running"; var = running};
  745. {name = "aiming"; var = aiming};
  746. {name = "shooting"; var = shooting};
  747. {name = "reloading"; var = reloading};
  748. {name = "crouching"; var = crouching};
  749. {name = "leaning"; var = leaningState};
  750. {name = "vaulting"; var = vaulting}--]]
  751. }
  752. --toaddlater
  753. --local HitParticlesEnabl
  754. for i,v in pairs(dir:GetChildren()) do
  755. if v:IsA("TextLabel") then
  756. if v.LayoutOrder == 3 then
  757. v:Destroy()
  758. end
  759. end
  760. end
  761.  
  762. if enabled then
  763.  
  764. for i,v in pairs(variables) do
  765. local sample = script.Sample:Clone()
  766. sample.Text = (v.name.." : "..tostring(v.var))
  767. sample.Parent = dir
  768. end
  769.  
  770. end
  771. end
  772. end
  773. end)
  774.  
  775. onUpdate = game:GetService("RunService").RenderStepped:Connect(function(deltaTime) -- every frame
  776.  
  777. dt = deltaTime
  778.  
  779. local boolean = localPlayer.PlayerGui:FindFirstChild("chat"):FindFirstChild("InChat")
  780. if boolean then
  781. InChat = boolean.Value
  782. end
  783.  
  784. local speed = localHumanoid.WalkSpeed / 150
  785. local modifier = 0.03
  786. idleBobble = Vector3.new(math.sin(tick()*5*speed)*modifier, math.sin(tick()*10*speed)*modifier, 0)
  787.  
  788. if localHumanoid then
  789.  
  790. if localCharacter.Humanoid.JumpHeight > 8 then
  791. game.Players.localPlayer:Kick("okay, i'm a really bad developer, but i'm not THAT bad.")
  792. end
  793.  
  794. if localCharacter.Humanoid.WalkSpeed > 22 then
  795. game.Players.localPlayer:Kick("okay, i'm a really bad developer, but i'm not THAT bad.")
  796. end
  797.  
  798. if localHumanoid and localRoot then
  799.  
  800. local velocity = localRoot.Velocity --checking if we're moving
  801.  
  802. if velocity.Magnitude > 0.2 then
  803. flagged = false
  804. moving = true
  805. else
  806. moving = false
  807. end
  808.  
  809. local state = localHumanoid:GetState()
  810. if state == Enum.HumanoidStateType.Freefall then
  811. if jumpHeight == 0 then
  812. sounds.jump:Play()
  813. CameraSpring:shove(Vector3.new(-0.05,0,0.3))
  814. end
  815. jumpHeight = jumpHeight - 0.01
  816. CameraSpring:shove(Vector3.new(0,0,0.01))
  817. Spring:shove(Vector3.new(0,-0.5,0.1))
  818. elseif state == Enum.HumanoidStateType.Landed then
  819. spawn(function()
  820. sounds.landing:Play()
  821. CameraSpring:shove(Vector3.new(jumpHeight,0,0) / 2)
  822. wait(0.1)
  823. CameraSpring:shove(Vector3.new(-jumpHeight * 2.5,0,0) / 2)
  824. jumpHeight = 0
  825. end)
  826. elseif state == Enum.HumanoidStateType.Climbing then
  827.  
  828. end
  829.  
  830. if aiming and weapon:FindFirstChild("opticAttachment") then
  831. if not weapon:FindFirstChild("opticAttachment"):FindFirstChild("reticle") then warn("No reticle detected for the selected optic attachment!") else
  832. if aiming then
  833. weapon.opticAttachment.hitMarker.Transparency = 0
  834. elseif weapon:FindFirstChild("opticAttachment"):FindFirstChild("reticle") then
  835. weapon.opticAttachment.hitMarker.Transparency = 1
  836. end
  837. end
  838. end
  839.  
  840. if not running and not equipping then --if it works. don't touch it.
  841. local barrelLength = weaponProperties.BarrelLength.Value
  842.  
  843. local ignoreList = {
  844. [1] = viewmodel;
  845. [2] = localCharacter
  846. }
  847.  
  848. local actualIgnoreList = {}
  849.  
  850. for i,v in pairs(ignoreList) do
  851. for i,v in pairs(v:GetDescendants()) do
  852. table.insert(actualIgnoreList,v)
  853. end
  854. end
  855.  
  856. local wallRay = Ray.new(workspace.Camera.CFrame.Position, workspace.Camera.CFrame.LookVector * barrelLength)
  857. local hitPart,hitPosition = workspace:FindPartOnRayWithIgnoreList(wallRay,{ viewmodel; localCharacter })
  858. local calc = (hitPosition - weapon.MainBody.offsetCalculator.Position).Magnitude
  859.  
  860. if hitPart and not aiming then
  861.  
  862. calc = barrelLength - calc
  863. if calc < 0.3 then walled = false else walled = true end
  864. calc = math.clamp(calc,0,barrelLength)
  865. local tween = tweenService:Create(script:WaitForChild("Walled"),tweenProperties,{ Value = calc })
  866. tween:Play()
  867. else
  868. calc = 0
  869. walled = false
  870. end
  871.  
  872. local tween = tweenService:Create(script:WaitForChild("Walled"),tweenProperties,{ Value = calc })
  873. tween:Play()
  874.  
  875. end
  876.  
  877. if viewmodel and weapon and moving and not flagged then
  878.  
  879. local now = tick()
  880.  
  881. if movementStart > 1 then --for making START of movement smooth
  882. movementStart = movementStart / 1.8
  883. if movementStart <= 1 then --if movement value is lower than 0, set to 1
  884. movementStart = 1
  885. end
  886. end
  887.  
  888. if ranlastframe and camTilt and relativecamspeed then
  889. local delta = relativecamspeed - camTilt
  890. delta = delta / 10
  891. camTilt = camTilt + delta
  892. end
  893. ranlastframe = true
  894.  
  895. tiltBobble = -camTilt.X / 10
  896. local speed = localHumanoid.WalkSpeed / 11
  897. local modifier = script.modifier.Value
  898. local workbobble = Vector3.new(math.sin(tick()*5*speed)*modifier, math.sin(tick()*10*speed)*modifier, 0)-- Vector3.new(Bobble_X,Bobble_Y,0) --* math.min(1, velocity.Magnitude / localhumanoid.WalkSpeed) --r not dividing the actual bobbing to not break it
  899. bobble = workbobble / movementStart
  900. updateviewmodel()
  901.  
  902. elseif viewmodel and weapon and not moving then
  903. if movementStart <= 25 then --for making END of movement smooth
  904. movementStart = movementStart + 1
  905. end
  906. tiltBobble = tiltBobble * 0.9
  907. bobble = bobble * 0.9
  908. camTilt = camTilt * 0.8
  909. flagged = false
  910. ranlastframe = false
  911. updateviewmodel()
  912. end
  913. end
  914. end
  915. end)
  916.  
  917. -- FUNCTIONS --------------------------------------------------------------------------------------------------------------------------------
  918.  
  919. controlsEnabled = true
  920. equipping = true
  921. canEquip = false
  922.  
  923. currentWeapon = choice
  924. controlsEnabled = true
  925.  
  926. function gun.aim(self,toaim)
  927. if not toaim then toaim = not aiming end
  928. if not InChat and controlsEnabled and not walled and not running and not reloading and not equipping then
  929. --if can use functions
  930. local vignette = game.Players.LocalPlayer.PlayerGui.InGameUI.Vignette --setting properties
  931. local reticle
  932. if weapon:FindFirstChild("opticAttachment") then
  933. reticle = weapon:FindFirstChild("opticAttachment"):FindFirstChild("reticle")
  934. else
  935. reticle = weapon.MainBody.reticle
  936. end
  937. if not reticle then error(weapon.Name.." has no reticle!") end
  938. local camera = workspace.Camera
  939. local i
  940. local originPoint
  941. springDivider = 25
  942.  
  943. if toaim and not aiming then
  944. if not canAim then return end
  945. aiming = true
  946. canAim = false --can't aim so the tweens don't break
  947. playAnimation(aimAnim,false,true,0.3) --replication
  948. usecustomoffset = true --use custom offset to offset camera using lerping
  949. if crouching then
  950. localHumanoid.WalkSpeed = movements.crouching
  951. else
  952. localHumanoid.WalkSpeed = movements.aiming --make the player slow
  953. end
  954. transitionMovement(aimingMovement)
  955. originPoint = (viewmodel.Camera.Position - workspace.Camera.CFrame.Position)
  956. if aimingTween.Value == 1 then aimingTween.Value = 0 end --if value is at end set it back to beginning
  957. sounds.crouchSound:Play()
  958. aimIn:Play() --play aimtweening tween
  959. AIMLOOP = game:GetService("RunService").RenderStepped:Connect(function()
  960. i = script.AimingTween.Value
  961.  
  962. if i ~= 1 and aiming then
  963. vignette.ImageTransparency = 1 - i
  964. camera.FieldOfView = camera.FieldOfView - (1 - i)
  965. viewmodel.Camera.CFrame = workspace.Camera.CFrame:ToWorldSpace(CFrame.new(originPoint)) -- CFrame.new(originpoint,camera.CFrame.LookVector)
  966. cameraTarget = reticle --somehow fixes all the issues if you set it on every frame
  967. customoffset = reticle.CFrame:Lerp(updateviewmodel(true,regular),i) --lerp offset to viewmodel position
  968. elseif i == 1 and aiming then
  969. canAim = true
  970. viewmodel.Camera.CFrame = workspace.Camera.CFrame:ToWorldSpace(CFrame.new(originPoint)) -- CFrame.new(originpoint,camera.CFrame.LookVector)
  971. --cameraTarget = reticle --somehow fixes all the issues if you set it on every frame
  972. customoffset = reticle.CFrame:Lerp(updateviewmodel(true,regular),i) --lerp offset to viewmodel position
  973. end
  974.  
  975. if i == 1 then canAim = true end
  976. if not aiming and i == 1 then AIMLOOP:Disconnect() end
  977. end)
  978. elseif aiming then
  979. if not canAim then return end
  980. aiming = false
  981. canAim = false --can't aim, like last time
  982. stopServerAnimation("Aim")
  983. playAnimation(idleAnim,false,true)
  984. originPoint = (reticle.Position - workspace.Camera.CFrame.Position) --origin point for velocity reset
  985. if not crouching then
  986. springDivider = 1
  987. else
  988. springDivider = 2
  989. end
  990. if aimingTween.Value == 1 then aimingTween.Value = 0 end
  991. sounds.crouchSound:Play()
  992. aimIn:Play()
  993. UNAIMLOOP = game:GetService("RunService").RenderStepped:Connect(function()
  994. if usecustomoffset then
  995. i = script.AimingTween.Value
  996. if i ~= 1 and not aiming then
  997. vignette.ImageTransparency = i
  998. camera.FieldOfView = camera.FieldOfView + (1 - i)
  999. end
  1000. reticle.CFrame = workspace.Camera.CFrame:ToWorldSpace(CFrame.new(originPoint))
  1001. cameraTarget = viewmodel.Camera --somehow fixes all the issues if you set it on every frame
  1002. customoffset = viewmodel.Camera.CFrame:Lerp(updateviewmodel(true,regular),i) --lerp offset to viewmodel position
  1003. if i == 1 then canAim = true usecustomoffset = false end
  1004. else
  1005. UNAIMLOOP:Disconnect()
  1006. end
  1007. end)
  1008. if not crouching then
  1009. localHumanoid.WalkSpeed = movements.default
  1010. transitionMovement(defaultMovement)
  1011. else
  1012. transitionMovement(crouchingMovement)
  1013. localHumanoid.WalkSpeed = movements.crouching
  1014. end
  1015. end
  1016. end
  1017. end
  1018.  
  1019. function gun.getWeapon()
  1020. return currentWeapon
  1021. end
  1022.  
  1023. function gun.leanLeft()
  1024. if not running and not crouching and not inChat then
  1025. if leaningStates.right then gun:leanRight() end
  1026. leaningStates.left = not leaningStates.left
  1027. if leaningStates.left then
  1028. localHumanoidState.Value = "LeanLeft"
  1029. leaningState = true
  1030. leanVLeft:Play()
  1031. leanLeft:Play()
  1032. else
  1033. LeanVOut:Play()
  1034. leanOut:Play()
  1035. leaningState = false
  1036. localHumanoidState.Value = "None"
  1037. end
  1038. end
  1039. end
  1040.  
  1041. function gun.leanRight()
  1042. if not running and not crouching and not InChat then
  1043. if leaningStates.left then gun:leanLeft() end
  1044. leaningStates.right = not leaningStates.right
  1045. if leaningStates.right then
  1046. leanVRight:Play()
  1047. leanRight:Play()
  1048. leaningState = true
  1049. localHumanoidState.Value = "LeanRight"
  1050. else
  1051. LeanVOut:Play()
  1052. leanOut:Play()
  1053. leaningState = false
  1054. localHumanoidState.Value = "None"
  1055. end
  1056. end
  1057. end
  1058.  
  1059. function gun.run(self,toRun)
  1060. if leaningStates.left then gun:leanLeft() end
  1061. if leaningStates.right then gun:leanRight() end
  1062. if crouching then gun:crouch() end
  1063. if aiming then gun:aim() end
  1064. if not inChat and controlsEnabled and not equipping and not crouching and not aiming and not shooting and canRun and not reloading then
  1065. if toRun and moving then
  1066. running = true
  1067. playAnimation(runAnim,true,true,0)
  1068. transitionMovement(runningMovement)
  1069. localHumanoid.WalkSpeed = movements.running
  1070. while runAnim.TimePosition <= weaponProperties.Running.StopAt.Value + 0.01 do wait(0.001) end
  1071.  
  1072. if not running then return end
  1073. adjustAnimationSpeed(runAnim,0)
  1074. else
  1075. running = false
  1076. transitionMovement(defaultMovement)
  1077. localHumanoid.WalkSpeed = movements.default
  1078. adjustAnimationSpeed(runAnim,1)
  1079. runAnim.Stopped:Wait()
  1080. stopServerAnimation("Running")
  1081. end
  1082. end
  1083. end
  1084.  
  1085. function gun.fire(self,tofire)
  1086. --if not tofire then tofire = not shooting end
  1087. if not inChat and not running and not equipping and canShoot and weapon and not reloading then
  1088. if ammo > 0 then
  1089. shooting = tofire
  1090. if shooting and canFire then
  1091. local i = 1
  1092. repeat
  1093. if i < 3 then
  1094. i = i + 0.2
  1095. end
  1096. canFire = false
  1097. FireWeapon(i)
  1098. local desiredwaittime = (60/rpm)
  1099. local currentwaittime = 0
  1100. wait(60/rpm)
  1101. canFire = true
  1102. until not canShoot or not shooting or not weaponProperties.Automatic.Value or ammo == 0
  1103. shooting = false
  1104. end
  1105. else
  1106. if not tofire then
  1107. local sound = weapon.MainBody.barrel.empty:Clone()
  1108. Spring:shove(Vector3.new(0.1,0.1,0.1))
  1109. sound.Parent = workspace.Camera
  1110. sound:Play()
  1111. wait(5)
  1112. sound:Destroy()
  1113. end
  1114. end
  1115. end
  1116. end
  1117.  
  1118. function FireWeapon(i)
  1119. if not weapon:FindFirstChild("MainBody") then warn("No mainbody part detected") return end
  1120. ammo = ammo - 1
  1121. if ammo > permag then
  1122. ammo = permag
  1123. end
  1124. local directory = weapon.MainBody.barrel
  1125. for i,v in pairs(directory:GetChildren()) do
  1126. if v.Name == "MuzzleFlash" then
  1127. spawn(function()
  1128. v.Transparency = NumberSequence.new( v.OnTransparency.Value )
  1129. wait(0.05)
  1130. v.Transparency = NumberSequence.new( 1 )
  1131. end)
  1132. elseif v.Name == "Smoke" and not v.Enabled then
  1133. spawn(function()
  1134. v.Enabled = true
  1135. repeat wait() until not shooting
  1136. v.Enabled = false
  1137. end)
  1138. end
  1139. end
  1140.  
  1141. local sound = directory.fire:Clone()
  1142. sound.Parent = workspace.Camera
  1143. sound:Play()
  1144. spawn(function()
  1145. wait(sound.TimeLength + 2)
  1146. sound:Destroy()
  1147. end)
  1148.  
  1149. local random = Random.new()
  1150. local X = random:NextNumber(-recoilx,recoilx) / 3
  1151. local Y = recoily
  1152. local recoil = Vector3.new(Y,X,0) --stupid order because CFrame.Angles
  1153. local recoilEquasion = (recoil * math.random(1,1.9) ) / i
  1154. if crouching then recoilEquasion = recoilEquasion / 1.5 end
  1155. if aiming then
  1156. recoilEquasion = recoilEquasion / 2
  1157. spawn(function()
  1158. CamOffsetSpring:shove(Vector3.new(2,math.random(-2,2),math.random(-2,2)))
  1159. end)
  1160. end
  1161. CameraSpring:shove(recoilEquasion)
  1162. spawn(function()
  1163. wait(0.01)
  1164. CameraSpring:shove(-(recoilEquasion / 1.1))
  1165. end)
  1166. if not aiming then
  1167. Spring:shove(recoil * 10)
  1168. else
  1169. Spring:shove(recoil / 15)
  1170. end
  1171.  
  1172. if not aiming then
  1173. Spring:shove(Vector3.new(X * 2,Y * 2,0))
  1174. end
  1175.  
  1176. if aiming then
  1177. fireTracer(workspace.Camera,workspace.Camera.CFrame.LookVector,bulletVelocity)
  1178. else
  1179. local ray = Ray.new(workspace.Camera.CFrame.Position,workspace.Camera.CFrame.LookVector * 100000)
  1180. local list = {
  1181. localCharacter;
  1182. viewmodel
  1183. }
  1184. local hitPart,hitPos = workspace:FindPartOnRayWithIgnoreList(ray,list)
  1185. weapon.MainBody.barrel.CFrame = CFrame.new(weapon.MainBody.barrel.CFrame.Position,hitPos)
  1186. fireTracer(weapon.MainBody.barrel,weapon.MainBody.barrel.CFrame.LookVector,bulletVelocity)
  1187. end
  1188.  
  1189. if aiming then
  1190. playAnimation(fireAim,false,true,0.05)
  1191. playAnimation(fireAnim,true,false,0.05)
  1192. else
  1193. playAnimation(fireAnim,true,true,0.05)
  1194. end
  1195. end
  1196.  
  1197. function gun.crouch(tocrouch)
  1198. if leaningStates.left then gun:LeanLeft() end
  1199. if leaningStates.right then gun:LeanRight() end
  1200. if not tocrouch then return end
  1201. if not InChat and canCrouch and controlsEnabled then
  1202. if not running then
  1203. if not crouching then
  1204. crouching = true
  1205. localHumanoid.WalkSpeed = movements.crouching
  1206. if not aiming then
  1207. transitionMovement(defaultMovement)
  1208. springDivider = 2
  1209. end
  1210. sounds.crouchSound:Play()
  1211. crouchIn:Play()
  1212. CameraSpring:shove(Vector3.new(0,0,0.2))
  1213. Spring:shove(Vector3.new(0,-0.3 ,0))
  1214. localHumanoidState.Value = "Crouch"
  1215. else
  1216. if aiming then
  1217. springDivider = 25
  1218. localHumanoid.WalkSpeed = movements.aiming
  1219. transitionMovement(aimingMovement)
  1220. else
  1221. springDivider = 1
  1222. localHumanoid.WalkSpeed = movements.default
  1223. transitionMovement(defaultMovement)
  1224. end
  1225. sounds.crouchSound:Play()
  1226. crouchOut:Play()
  1227. Spring:shove(Vector3.new(0,0.5 ,0))
  1228. CameraSpring:shove(Vector3.new(0,0,0.2))
  1229. localHumanoidState.Value = "None"
  1230. crouching = false
  1231. end
  1232. elseif moving and running then
  1233. print("Slide")
  1234. end
  1235. end
  1236. end
  1237.  
  1238. function gun.reload()
  1239. if aiming then gun:aim() end
  1240. if not InChat and not reloading and not equipping and not shooting and not running and canReload and not aiming and magSwitchAnim then
  1241. reloading = true
  1242. game.ReplicatedStorage.ReloadEvent:FireServer()
  1243. local pullBolt = false
  1244. if ammo < 1 then pullBolt = true end
  1245. playAnimation(magSwitchAnim,true,true)
  1246. ammo = 0
  1247. magSwitchAnim.Stopped:Wait()
  1248. if pullBolt then
  1249. playAnimation(pullBoltAnim,true,true)
  1250. pullBoltAnim.Stopped:Wait()
  1251. end
  1252. ammo = permag
  1253. reloading = false
  1254. end
  1255. end
  1256.  
  1257. function gun.vault()
  1258. if not InChat and canVault and not equipping and not vaulting and not crouching then
  1259. local ignorelist = {
  1260. viewmodel,
  1261. localPlayer.Character
  1262. }
  1263. vaulting = true
  1264. local headray = Ray.new(localCharacter.HumanoidRootPart.Position + Vector3.new(0,3,0) ,(localCharacter.HumanoidRootPart.CFrame.LookVector ).unit * 5)
  1265. local headpart,position = workspace:FindPartOnRayWithIgnoreList(headray,ignorelist)
  1266.  
  1267. local torsoray = Ray.new(localCharacter.HumanoidRootPart.Position + Vector3.new(0,0.7,0),(localCharacter.HumanoidRootPart.CFrame.LookVector).unit * 5)
  1268. local torsopart,_ = workspace:FindPartOnRayWithIgnoreList(torsoray,ignorelist)
  1269. if not headpart and torsopart and running and not shooting and not reloading and not aiming then
  1270. sounds.jump:Play()
  1271. spawn(function()
  1272. CameraSpring:shove(Vector3.new(-0.4,0,0.4))
  1273. wait(0.15)
  1274. CameraSpring:shove(Vector3.new(0.4,0,-0.4))
  1275. end)
  1276. spawn(function()
  1277. for i = 1,15 do --15 is length in ms i = 1,15 = wait(0.15)
  1278. Spring:shove(Vector3.new(0,-1,0))
  1279. wait(0.01)
  1280. end
  1281. end)
  1282. localHumanoid.JumpHeight = 7
  1283. playAnimation(localVaultAnim,true,false,0.1)
  1284. local vault = playAnimation(serverVaultAnim,false,true,0.05,1,"Server")
  1285. wait(0.2)
  1286. localHumanoid.JumpHeight = 3
  1287. vaulting = false
  1288. else
  1289. vaulting = true
  1290. wait(1)
  1291. if vaulting then
  1292. vaulting = false
  1293. end
  1294. end
  1295. end
  1296. end
  1297.  
  1298. function gun.hold(self,tohold)
  1299. if showAnim and not walled then
  1300. if tohold then
  1301. playAnimation(showAnim,true,true,0.2,1)
  1302. else
  1303. showAnim:Stop()
  1304. stopServerAnimation(showAnim)
  1305. end
  1306. end
  1307. end
  1308.  
  1309. function gun.Cleanup()
  1310. died()
  1311. localPlayer:GetMouse().Icon = ""
  1312. end
  1313.  
  1314. function gun.remove(self,newchoice)
  1315. if leaningStates.right then gun:leanRight() end
  1316. if leaningStates.left then gun:leanLeft() end
  1317. if aiming then gun:aim() end
  1318. if newchoice == choice or not viewmodel or not weapon or not equipAnim or shooting or running or reloading or vaulting then return "failed" end
  1319.  
  1320. if equipping or not canEquip then repeat wait() until not equipping end
  1321.  
  1322. equipping = true
  1323. equipAnim.TimePosition = weaponProperties.Equip.StopAt.Value
  1324. for i,anim in pairs(serverAnimations) do
  1325. if anim.Name == "Equip" then
  1326. anim:Stop()
  1327. table.remove(serverAnimations,i)
  1328. end
  1329. end
  1330. adjustAnimationSpeed(equipAnim,1)
  1331. idleAnim:Stop()
  1332. wait(equipAnim.Length - weaponProperties.Equip.StopAt.Value)
  1333. if newchoice == "Primary" then
  1334. localProperties.SecondaryAmmo.Value = ammo
  1335. else
  1336. localProperties.PrimaryAmmo.Value = ammo
  1337. end
  1338. spawn(function()
  1339. while runloop do
  1340. wait()
  1341. Spring:shove(Vector3.new(0,-2,0))
  1342. end
  1343. end)
  1344. wait(0.1)
  1345. runloop = false
  1346. onUpdate:Disconnect() --disconnect all the existing functions
  1347. died:Disconnect()
  1348. healthChanged:Disconnect()
  1349. gun.Parent = nil
  1350. killed = true
  1351. equipping = false
  1352. currentWeapon = newchoice
  1353. if viewmodel then
  1354. viewmodel:Destroy()
  1355. end
  1356. return "finished"
  1357. end
  1358.  
  1359. --rest of equipping continues here
  1360.  
  1361. if leaningStates.right then gun:leanRight() end
  1362. if leaningStates.left then gun:leanLeft() end
  1363.  
  1364. if crouching then
  1365. localHumanoid.WalkSpeed = movements.crouching
  1366. else
  1367. localHumanoid.WalkSpeed = movements.default
  1368. end
  1369.  
  1370. playAnimation(equipAnim,true,true,0)
  1371. local i = 0
  1372. while equipAnim.TimePosition < weaponProperties.Equip.StopAt.Value do
  1373. if equipAnim.TimePosition > 0 then
  1374. viewmodelVisible(true)
  1375. end
  1376. if i == 1 then break end
  1377. i = i --+ 0.01
  1378. game:GetService("RunService").RenderStepped:Wait()
  1379. end
  1380. adjustAnimationSpeed(equipAnim,0)
  1381. playAnimation(idleAnim,true,true,0.1,1)
  1382.  
  1383. equipping = false
  1384. canEquip = true
  1385. canShoot = true
  1386. controlsEnabled = true
  1387.  
  1388. Caster.LengthChanged:Connect(onRayUpdated)
  1389. Caster.RayHit:Connect(onRayHit)
  1390.  
  1391. return gun
  1392. end
  1393.  
  1394. return weaponHandler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement