Advertisement
Guest User

Blood and Iron gun handler

a guest
Aug 8th, 2019
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.08 KB | None | 0 0
  1. --SynapseX Decompiler
  2.  
  3. script:WaitForChild("ToolName")
  4. ToolName = script.ToolName.Value
  5. ToolData = require(game.ReplicatedStorage.ToolData[ToolName])
  6. HandlerData = require(game.ReplicatedStorage.HandlerData[script.Name])
  7. EaseJoint = require(game.ReplicatedStorage.CustomLibraries.CFrameEasing)
  8. Notification = require(game.ReplicatedStorage.CustomLibraries.Notifications)
  9. Maths = require(game.ReplicatedStorage.CustomLibraries.MathsMethods)
  10. BulletImpact = require(game.ReplicatedStorage.CustomLibraries.BulletImpacts)
  11. Player = game.Players.LocalPlayer
  12. Character = Player.Character
  13. Humanoid = Character.Humanoid
  14. ArmTorso = Character.ArmTorso
  15. Tool = Character[ToolName]
  16. Mouse = Player:GetMouse()
  17. EaseJoint.Halt(Player)
  18. local BulletLoaded = Player.Inventory[ToolName].BulletLoaded.Value
  19. BulletLoadedThread = coroutine.create(function()
  20. BulletLoaded = game.ReplicatedStorage.Requests.RequestInventoryVariable:InvokeServer(Tool, script, "BulletLoaded")
  21. end)
  22. coroutine.resume(BulletLoadedThread)
  23. local ReloadStage = Player.Inventory[ToolName].ReloadStage.Value
  24. ReloadStageThread = coroutine.create(function()
  25. ReloadStage = game.ReplicatedStorage.Requests.RequestInventoryVariable:InvokeServer(Tool, script, "ReloadStage")
  26. if ReloadStage == 2 then
  27. game.ReplicatedStorage.Requests.RequestCartridgeRemoval:InvokeServer(Tool, Character["Right Arm"], true)
  28. end
  29. end)
  30. coroutine.resume(ReloadStageThread)
  31. HaltAnimation = false
  32. Bracing = false
  33. Stance = "Equip"
  34. AnimationTimeCoefficient = ToolData.Properties.AnimationTimeCoefficient
  35. Bayonet = ToolData.Properties.Bayonet
  36. Brace = ToolData.Properties.Brace
  37. BulletMuzzleVelocity = ToolData.Properties.BulletMuzzleVelocity
  38. GravityVector = HandlerData.GravityVector
  39. BulletDrag = BulletMuzzleVelocity / HandlerData.BulletDragCoefficient
  40. BlockWalkSpeedReduction = HandlerData.BlockWalkSpeedReduction
  41. AccuracyBuffCoefficient = 0.8
  42. ReloadSpeedBuffCoefficient = 0.85
  43. MeleeSpeedBuffCoefficient = 0.85
  44. Mouse.TargetFilter = Character
  45. Mouse.Icon = HandlerData.MouseIcon
  46. LastReplicate = tick()
  47. ReplicateDelay = 0.03333333333333333
  48. Mouse.Move:connect(function()
  49. local YAxis = Mouse.UnitRay.Direction.Y
  50. local Angle = math.asin(YAxis)
  51. if Character.Torso:FindFirstChild("Neck") then
  52. Character.Torso.Neck.C1 = CFrame.new(0, -0.5, 0) * CFrame.Angles(math.rad(-90) - Angle, 0, math.rad(180))
  53. if tick() > LastReplicate + ReplicateDelay then
  54. game.ReplicatedStorage.SelectiveReplication.UpdateObject:FireServer(Character.Torso.Neck, "C1", CFrame.new(0, -0.5, 0) * CFrame.Angles(math.rad(-90) - Angle, 0, math.rad(180)))
  55. end
  56. end
  57. if not string.match(Stance, "Present") and not string.match(Stance, "Bayonet") or Bracing then
  58. Angle = 0
  59. elseif string.match(Stance, "Bayonet") and math.abs(Angle) > math.rad(20) then
  60. if Angle > math.rad(20) then
  61. Angle = math.rad(20)
  62. else
  63. Angle = math.rad(-20)
  64. end
  65. end
  66. if Character.Torso:FindFirstChild("TorsoJoint") then
  67. Character.Torso.TorsoJoint.C1 = CFrame.new(0, 0, 0) * CFrame.Angles(-Angle, 0, 0)
  68. if tick() > LastReplicate + ReplicateDelay then
  69. LastReplicate = tick()
  70. game.ReplicatedStorage.SelectiveReplication.UpdateObject:FireServer(Character.Torso.TorsoJoint, "C1", CFrame.new(0, 0, 0) * CFrame.Angles(-Angle, 0, 0))
  71. end
  72. end
  73. local MouseTarget = Mouse.Target
  74. if MouseTarget then
  75. if game.Players:FindFirstChild(MouseTarget.Parent.Name) and Player.TeamColor == game.Players[MouseTarget.Parent.Name].TeamColor then
  76. Mouse.Icon = HandlerData.FriendlyMouseIcon
  77. elseif game.Players:FindFirstChild(MouseTarget.Parent.Parent.Name) and Player.TeamColor == game.Players[MouseTarget.Parent.Parent.Name].TeamColor then
  78. Mouse.Icon = HandlerData.FriendlyMouseIcon
  79. elseif MouseTarget.Parent.Parent:FindFirstChild("HorseHumanoid") and Player.TeamColor == MouseTarget.Parent.Parent.HorseHumanoid.Team.Value then
  80. Mouse.Icon = HandlerData.FriendlyMouseIcon
  81. else
  82. Mouse.Icon = HandlerData.MouseIcon
  83. end
  84. end
  85. end)
  86. function DetermineWalkSpeed(QuieredStance, IgnoreCrouching)
  87. local WalkSpeed = ToolData.Properties.DefaultWalkSpeed
  88. if Character.HumanoidRootPart.RootJoint.C1 ~= CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0) and not IgnoreCrouching then
  89. WalkSpeed = 0
  90. elseif string.match(QuieredStance, "Present") then
  91. WalkSpeed = ToolData.Properties.PresentWalkSpeed
  92. elseif string.match(QuieredStance, "MakeReady") then
  93. WalkSpeed = ToolData.Properties.MakeReadyWalkSpeed
  94. elseif string.match(QuieredStance, "Block") then
  95. WalkSpeed = ToolData.Properties.BayonetWalkSpeed - BlockWalkSpeedReduction
  96. elseif string.match(QuieredStance, "Bayonet") then
  97. WalkSpeed = ToolData.Properties.BayonetWalkSpeed
  98. elseif string.match(QuieredStance, "Reload") then
  99. WalkSpeed = ToolData.Properties.ReloadWalkSpeed
  100. end
  101. return WalkSpeed
  102. end
  103. function DetermineAutoRotate(QuieredStance)
  104. return not string.match(QuieredStance, "Reload") or string.match(QuieredStance, "ReloadRecover") or DetermineWalkSpeed(QuieredStance, true) ~= 0 or Bracing
  105. end
  106. function DetermineAccuracyBuffCoefficient()
  107. for _, Status in pairs(Player.PlayerGui.Backpack.StatusControl.RequestStatuses:Invoke()) do
  108. if Status.Name == "OfficerAccuracy" and Status.GivenByServer then
  109. return AccuracyBuffCoefficient
  110. end
  111. end
  112. return 1
  113. end
  114. function DetermineAnimationSpeedBuffCoefficient()
  115. for _, Status in pairs(Player.PlayerGui.Backpack.StatusControl.RequestStatuses:Invoke()) do
  116. if Status.Name == "MusicianReloadSpeed" and Status.GivenByServer and string.match(Stance, "Reload") then
  117. return ReloadSpeedBuffCoefficient
  118. elseif Status.Name == "ColourMeleeSpeed" and Status.GivenByServer and string.match(Stance, "Bayonet") then
  119. return MeleeSpeedBuffCoefficient
  120. end
  121. end
  122. return 1
  123. end
  124. function BulletFire()
  125. local InitialVector = (Mouse.Hit.p - Tool.Muzzle.Position).unit + BulletCalculateDeviation().unit
  126. local AimVector = Character.Head.CFrame.lookVector
  127. if (InitialVector - AimVector).magnitude > ToolData.Properties.BulletInitialVectorTolerance then
  128. InitialVector = AimVector
  129. end
  130. local NewBullet = BulletInitialise()
  131. NewBullet.Parent, NewBullet.CFrame = workspace, CFrame.new(Tool.Muzzle.Position, Tool.Muzzle.Position + InitialVector)
  132. local BulletThread = coroutine.create(function()
  133. BulletTravel(NewBullet, InitialVector, BulletMuzzleVelocity, nil)
  134. end)
  135. coroutine.resume(BulletThread)
  136. local EffectThread = coroutine.create(function()
  137. PlayEffect("BulletFire")
  138. end)
  139. coroutine.resume(EffectThread)
  140. game.ReplicatedStorage.Requests.RequestBulletLoadedUpdate:FireServer(Player.Inventory[Tool.Name])
  141. end
  142. function BulletInitialise()
  143. local NewBullet = Instance.new("Part")
  144. NewBullet.Name = "Bullet"
  145. NewBullet.Anchored, NewBullet.CanCollide = true, false
  146. NewBullet.BrickColor, NewBullet.Material = BrickColor.White(), Enum.Material.Neon
  147. NewBullet.formFactor = Enum.FormFactor.Custom
  148. NewBullet.Size = Vector3.new(0.2, 0.2, 0.2)
  149. Instance.new("BlockMesh", NewBullet).Scale = Vector3.new(0.5, 0.5, 40)
  150. NewBullet.Mesh.Offset = Vector3.new(0, 0, -5)
  151. game.ReplicatedStorage.SelectiveReplication.PlayerDied.OnClientEvent:connect(function()
  152. if NewBullet then
  153. NewBullet:Destroy()
  154. end
  155. end)
  156. game:GetService("Debris"):AddItem(NewBullet)
  157. return NewBullet
  158. end
  159. function BulletTravel(Bullet, BulletVector, BulletVelocity, PreviousHit)
  160. local BulletRay = Ray.new(Bullet.Position, BulletVector * BulletVelocity)
  161. local Hit, HitPos = workspace:FindPartOnRayWithIgnoreList(BulletRay, {Tool, PreviousHit})
  162. game.ReplicatedStorage.Requests.RequestBulletCrack:FireServer(Tool, BulletRay)
  163. if Hit and Hit.Transparency ~= 1 then
  164. BulletHit(Hit, HitPos, BulletVector)
  165. Bullet:Destroy()
  166. else
  167. Bullet.CFrame = CFrame.new(HitPos, HitPos + BulletVector)
  168. wait(0.03333333333333333)
  169. if BulletVelocity > 0 then
  170. BulletTravel(Bullet, BulletVector.unit, BulletVelocity - BulletDrag, Hit)
  171. else
  172. Bullet:Destroy()
  173. end
  174. end
  175. end
  176. function BulletHit(Hit, HitPos, BulletVector)
  177. if Hit.Parent:FindFirstChild("Humanoid") or Hit.Parent:FindFirstChild("HumanoidLink") then
  178. game.ReplicatedStorage.Requests.RequestDamage:FireServer(Hit, HitPos, Tool, "Bullet")
  179. elseif Hit.Parent:FindFirstChild("HorseHumanoid") or Hit.Parent.Parent:FindFirstChild("HorseHumanoid") then
  180. game.ReplicatedStorage.Requests.RequestDamage:FireServer(Hit.Parent:FindFirstChild("HorseCentre") or Hit.Parent.Parent:FindFirstChild("HorseCentre"), Tool.Handle.Position, Tool, "Bullet")
  181. elseif Hit.Parent:FindFirstChild("ConstructCentre") then
  182. game.ReplicatedStorage.Requests.RequestDamage:FireServer(Hit.Parent.ConstructCentre, Tool.Handle.Position, Tool, "Bullet")
  183. end
  184. BulletImpact.new(Hit, HitPos, BulletVector)
  185. game.ReplicatedStorage.SelectiveReplication.InstanciateBulletImpact:FireServer(Tool, script, Hit, HitPos, BulletVector)
  186. end
  187. function BulletCalculateDeviation()
  188. local MaximumDeviation = ToolData.Properties.BulletMaximumDeviation
  189. local function CalculateDeviation()
  190. return math.random(-10000 * MaximumDeviation, 10000 * MaximumDeviation) / 10000 * DetermineAccuracyBuffCoefficient()
  191. end
  192. return Vector3.new(CalculateDeviation(), CalculateDeviation(), CalculateDeviation())
  193. end
  194. function IsInFirstPerson()
  195. return (Character.Head.Position - workspace.CurrentCamera.CoordinateFrame.p).magnitude <= 1.2
  196. end
  197. script:WaitForChild("RequestStance")
  198. function script.RequestStance.OnClientInvoke()
  199. return Stance
  200. end
  201. script:WaitForChild("RequestBulletLoaded")
  202. function script.RequestBulletLoaded.OnClientInvoke()
  203. return BulletLoaded
  204. end
  205. script:WaitForChild("RequestReloadStage")
  206. function script.RequestReloadStage.OnClientInvoke()
  207. return ReloadStage
  208. end
  209. function PlayEffect(EffectName)
  210. local Effect = ToolData.Effects[EffectName]
  211. for _, Stage in pairs(Effect) do
  212. for _, Element in pairs(Stage) do
  213. if Element.SoundName then
  214. Tool[Element.SoundParent][Element.SoundName]:Play()
  215. elseif Element.EffectName then
  216. Tool[Element.EffectParent][Element.EffectName].Enabled = Element.EffectValue
  217. game.ReplicatedStorage.SelectiveReplication.UpdateObject:FireServer(Tool[Element.EffectParent][Element.EffectName], "Enabled", Element.EffectValue)
  218. elseif Element.FlashParent then
  219. Tool[Element.FlashParent].Flash.Flash.Visible = Element.FlashValue
  220. game.ReplicatedStorage.SelectiveReplication.UpdateObject:FireServer(Tool[Element.FlashParent].Flash.Flash, "Visible", Element.FlashValue)
  221. elseif Element.Wait then
  222. wait(Element.Wait)
  223. end
  224. end
  225. end
  226. end
  227. function PlayAnimation(StartStance, EndStance, ImmuneToHalt)
  228. if HaltAnimation and not ImmuneToHalt then
  229. return
  230. end
  231. local Animation = ToolData.Animations[StartStance .. "To" .. EndStance]
  232. game.ReplicatedStorage.SelectiveReplication.ReplicateAnimation:FireServer("Tool", ToolName, StartStance .. "To" .. EndStance)
  233. Stance = StartStance .. "Moving"
  234. Humanoid.WalkSpeed = math.min(DetermineWalkSpeed(StartStance), DetermineWalkSpeed(EndStance))
  235. Humanoid.AutoRotate = DetermineAutoRotate(StartStance) and DetermineAutoRotate(EndStance)
  236. for _, KeyFrame in pairs(Animation) do
  237. for _, Transition in pairs(KeyFrame) do
  238. if Transition.JointName then
  239. if Transition.C0 then
  240. local TransitionThread = coroutine.create(function()
  241. EaseJoint[Transition.Style](ArmTorso[Transition.JointName], "C0", ArmTorso[Transition.JointName].C0, Transition.C0 * CFrame.new(0, 1.5, 0), Transition.Duration * AnimationTimeCoefficient * DetermineAnimationSpeedBuffCoefficient())
  242. end)
  243. coroutine.resume(TransitionThread)
  244. end
  245. if Transition.C1 then
  246. local TransitionThread = coroutine.create(function()
  247. EaseJoint[Transition.Style](ArmTorso[Transition.JointName], "C1", ArmTorso[Transition.JointName].C1, Transition.C1 * CFrame.new(0, 1.5, 0), Transition.Duration * AnimationTimeCoefficient * DetermineAnimationSpeedBuffCoefficient())
  248. end)
  249. coroutine.resume(TransitionThread)
  250. end
  251. elseif Transition.RotationName then
  252. if Transition.C0 then
  253. local TransitionThread = coroutine.create(function()
  254. EaseJoint[Transition.Style](Tool[Transition.RotationName].RotationJoint, "C0", Tool[Transition.RotationName].RotationJoint.C0, Transition.C0, Transition.Duration * AnimationTimeCoefficient * DetermineAnimationSpeedBuffCoefficient())
  255. end)
  256. coroutine.resume(TransitionThread)
  257. end
  258. if Transition.C1 then
  259. local TransitionThread = coroutine.create(function()
  260. EaseJoint[Transition.Style](Tool[Transition.RotationName].RotationJoint, "C1", Tool[Transition.RotationName].RotationJoint.C1, Transition.C1, Transition.Duration * AnimationTimeCoefficient * DetermineAnimationSpeedBuffCoefficient())
  261. end)
  262. coroutine.resume(TransitionThread)
  263. end
  264. elseif Transition.TorsoAngle then
  265. local TransitionThread = coroutine.create(function()
  266. EaseJoint[Transition.Style](Character.HumanoidRootPart.RootJoint, "C0", Character.HumanoidRootPart.RootJoint.C0, CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0) * CFrame.Angles(0, 0, Transition.TorsoAngle), Transition.Duration * AnimationTimeCoefficient * DetermineAnimationSpeedBuffCoefficient())
  267. end)
  268. coroutine.resume(TransitionThread)
  269. local TransitionThread = coroutine.create(function()
  270. EaseJoint[Transition.Style](Character.Torso.TorsoJoint, "C0", Character.Torso.TorsoJoint.C0, CFrame.new(0, 1.5, 0) * CFrame.Angles(0, -Transition.TorsoAngle, 0), Transition.Duration * AnimationTimeCoefficient * DetermineAnimationSpeedBuffCoefficient())
  271. end)
  272. coroutine.resume(TransitionThread)
  273. local TransitionThread = coroutine.create(function()
  274. EaseJoint[Transition.Style](Character.Torso.Neck, "C0", Character.Torso.Neck.C0, CFrame.new(0, 1, 0) * CFrame.Angles(math.rad(-90), 0, math.rad(180) - Transition.TorsoAngle), Transition.Duration * AnimationTimeCoefficient * DetermineAnimationSpeedBuffCoefficient())
  275. end)
  276. coroutine.resume(TransitionThread)
  277. elseif Transition.SoundName then
  278. Tool[Transition.SoundParent][Transition.SoundName]:Play()
  279. elseif Transition.Cartridge ~= nil then
  280. if Transition.Cartridge and not Transition.SeparateThread then
  281. game.ReplicatedStorage.Requests.RequestCartridge:InvokeServer(Tool, Character["Right Arm"], true)
  282. elseif not Transition.Cartridge and not Transition.SeparateThread then
  283. game.ReplicatedStorage.Requests.RequestCartridgeRemoval:InvokeServer(Tool, Character["Right Arm"], true)
  284. elseif not Transition.Cartridge and Transition.SeparateThread and Transition.CartridgeModifyModel then
  285. local CartridgeThread = coroutine.create(function()
  286. game.ReplicatedStorage.Requests.RequestCartridgeRemoval:InvokeServer(Tool, Character["Right Arm"], true)
  287. end)
  288. coroutine.resume(CartridgeThread)
  289. elseif not Transition.Cartridge and Transition.SeparateThread and not Transition.CartridgeModifyModel then
  290. local CartridgeThread = coroutine.create(function()
  291. game.ReplicatedStorage.Requests.RequestCartridgeRemoval:InvokeServer(Tool, Character["Right Arm"], false)
  292. end)
  293. coroutine.resume(CartridgeThread)
  294. end
  295. elseif Transition.Wait then
  296. for SplitWait = 1, 4 do
  297. if not ImmuneToHalt and HaltAnimation then
  298. return
  299. end
  300. Humanoid.WalkSpeed = math.min(DetermineWalkSpeed(StartStance), DetermineWalkSpeed(EndStance))
  301. wait(0.25 * Transition.Wait * AnimationTimeCoefficient * DetermineAnimationSpeedBuffCoefficient())
  302. end
  303. elseif not ImmuneToHalt and HaltAnimation then
  304. return
  305. end
  306. end
  307. if not ImmuneToHalt and HaltAnimation then
  308. return
  309. end
  310. end
  311. if not ImmuneToHalt and HaltAnimation then
  312. return
  313. end
  314. Stance = EndStance
  315. Humanoid.WalkSpeed = DetermineWalkSpeed(EndStance)
  316. Humanoid.AutoRotate = DetermineAutoRotate(EndStance)
  317. end
  318. game.ReplicatedStorage.SelectiveReplication.PlayerDied.OnClientEvent:connect(function()
  319. Stance = "Dead"
  320. EaseJoint.Halt(Player)
  321. end)
  322. function FailSafe()
  323. if not script.Parent then
  324. warn(script.Name .. " fail-safe fired for: " .. ToolName .. ", owned by: " .. Player.Name .. ".")
  325. game:GetService("Debris"):AddItem(script, 1)
  326. script.Disabled = true
  327. end
  328. end
  329. FailSafe()
  330. script.Changed:connect(FailSafe)
  331. Mouse.Button1Down:connect(function()
  332. if BulletLoaded and Stance == "Shoulder" then
  333. PlayAnimation(Stance, "MakeReady")
  334. elseif BulletLoaded and Stance == "MakeReady" then
  335. PlayAnimation(Stance, "Shoulder")
  336. elseif BulletLoaded and Stance == "PresentUnready" then
  337. PlayAnimation(Stance, "PresentReady")
  338. elseif BulletLoaded and Stance == "PresentReady" then
  339. PlayAnimation(Stance, "PresentFire")
  340. BulletFire()
  341. BulletLoaded = false
  342. Player.PlayerScripts.CameraScript.AlterMouseSensitivity:Fire(1)
  343. PlayAnimation(Stance, "ReloadRecover")
  344. elseif Bayonet and not Bracing and Stance == "Bayonet" then
  345. PlayAnimation(Stance, "BayonetReady")
  346. Notification.WaitFor(script, "BayonetReady")
  347. PlayAnimation(Stance, "BayonetThrustOut")
  348. PlayAnimation(Stance, "BayonetThrustIn")
  349. PlayAnimation(Stance, "Bayonet")
  350. Notification.Give(script, "BayonetFinished", 0.1)
  351. if Brace then
  352. Bracing = Character.Crouching.Enabled.Value
  353. Humanoid.AutoRotate = not Character.Crouching.Enabled.Value
  354. end
  355. elseif not BulletLoaded and Stance == "ReloadRecover" then
  356. PlayAnimation(Stance, "ReloadStage1")
  357. PlayAnimation(Stance, "ReloadStage2")
  358. if not HaltAnimation then
  359. ReloadStage = 2
  360. end
  361. PlayAnimation(Stance, "ShoulderRecoverVariant0")
  362. PlayAnimation(Stance, "Shoulder")
  363. if not HaltAnimation then
  364. BulletLoaded = true
  365. ReloadStage = 1
  366. end
  367. end
  368. end)
  369. Mouse.Button2Down:connect(function()
  370. if IsInFirstPerson() and Stance == "Shoulder" then
  371. PlayAnimation(Stance, "PresentUnready")
  372. Player.PlayerScripts.CameraScript.AlterMouseSensitivity:Fire(0.5)
  373. elseif IsInFirstPerson() and BulletLoaded and Stance == "MakeReady" then
  374. PlayAnimation(Stance, "PresentReady")
  375. Player.PlayerScripts.CameraScript.AlterMouseSensitivity:Fire(0.5)
  376. elseif IsInFirstPerson() and Stance == "PresentReady" then
  377. PlayAnimation(Stance, "Shoulder")
  378. Player.PlayerScripts.CameraScript.AlterMouseSensitivity:Fire(1)
  379. elseif IsInFirstPerson() and Stance == "PresentUnready" then
  380. PlayAnimation(Stance, "Shoulder")
  381. Player.PlayerScripts.CameraScript.AlterMouseSensitivity:Fire(1)
  382. elseif Bayonet and not Bracing and Stance == "Bayonet" then
  383. game.ReplicatedStorage.Requests.RequestToolBlockToggle:FireServer(Tool, script, true)
  384. PlayAnimation(Stance, "BayonetBlock")
  385. Notification.WaitFor(script, "BayonetStopBlocking")
  386. game.ReplicatedStorage.Requests.RequestToolBlockToggle:FireServer(Tool, script, false)
  387. PlayAnimation(Stance, "Bayonet")
  388. if Brace then
  389. Bracing = Character.Crouching.Enabled.Value
  390. Humanoid.AutoRotate = not Character.Crouching.Enabled.Value
  391. end
  392. elseif Stance == "ReloadRecover" then
  393. PlayAnimation(Stance, "ShoulderRecover")
  394. PlayAnimation(Stance, "Shoulder")
  395. end
  396. end)
  397. Mouse.Button1Up:connect(function()
  398. if Bayonet and (Stance == "BayonetMoving" or Stance == "BayonetReady") then
  399. Notification.Give(script, "BayonetReady")
  400. end
  401. end)
  402. Mouse.Button2Up:connect(function()
  403. if Bayonet and (Stance == "BayonetMoving" or Stance == "BayonetBlock") then
  404. Notification.Give(script, "BayonetStopBlocking")
  405. end
  406. end)
  407. Mouse.KeyDown:connect(function(Key)
  408. Key = string.upper(Key)
  409. if DetermineWalkSpeed(Stance) == 0 and Character.Crouching.Enabled.Value and string.match("WASD\017\018", Key) then
  410. Notification.WaitForExternal(Character.Crouching, "CrouchStarted")
  411. Humanoid.WalkSpeed = DetermineWalkSpeed(Stance)
  412. wait(0.1)
  413. Notification.WaitForExternal(Character.Crouching, "CrouchFinished")
  414. Humanoid.WalkSpeed = DetermineWalkSpeed(Stance)
  415. if Bayonet and Brace and Stance == "Bayonet" then
  416. Bracing = false
  417. Humanoid.AutoRotate = true
  418. end
  419. end
  420. if DetermineWalkSpeed(Stance, true) == 0 and string.match("WASD\017\018", Key) and BulletLoaded and Stance == "MakeReady" then
  421. PlayAnimation(Stance, "Shoulder")
  422. Player.PlayerScripts.CameraScript.AlterMouseSensitivity:Fire(1)
  423. elseif DetermineWalkSpeed(Stance, true) == 0 and string.match("WASD\017\018", Key) and Stance == "PresentReady" then
  424. PlayAnimation(Stance, "Shoulder")
  425. Player.PlayerScripts.CameraScript.AlterMouseSensitivity:Fire(1)
  426. elseif DetermineWalkSpeed(Stance, true) == 0 and string.match("WASD\017\018", Key) and Stance == "PresentUnready" then
  427. PlayAnimation(Stance, "Shoulder")
  428. Player.PlayerScripts.CameraScript.AlterMouseSensitivity:Fire(1)
  429. elseif DetermineWalkSpeed(Stance, true) == 0 and string.match("WASD\017\018", Key) and Stance == "ReloadRecover" then
  430. PlayAnimation(Stance, "ShoulderRecover")
  431. PlayAnimation(Stance, "Shoulder")
  432. elseif DetermineWalkSpeed("Reload", true) == 0 and string.match("WASD\017\018", Key) and Stance == "ReloadStage1Moving" and not HaltAnimation then
  433. HaltAnimation = true
  434. EaseJoint.Halt(Player)
  435. PlayAnimation(Stance, "ShoulderRecoverVariant1", true)
  436. PlayAnimation(Stance, "Shoulder", true)
  437. HaltAnimation = false
  438. elseif DetermineWalkSpeed("Reload", true) == 0 and string.match("WASD\017\018", Key) and Stance == "ReloadStage2Moving" and not HaltAnimation then
  439. HaltAnimation = true
  440. EaseJoint.Halt(Player)
  441. PlayAnimation(Stance, "ShoulderRecoverVariant2", true)
  442. PlayAnimation(Stance, "Shoulder", true)
  443. HaltAnimation = false
  444. elseif Key == "R" and not BulletLoaded and ReloadStage == 1 and Stance == "Shoulder" then
  445. PlayAnimation(Stance, "ReloadRecover")
  446. PlayAnimation(Stance, "ReloadStage1")
  447. PlayAnimation(Stance, "ReloadStage2")
  448. if not HaltAnimation then
  449. ReloadStage = 2
  450. end
  451. PlayAnimation(Stance, "ShoulderRecoverVariant0")
  452. PlayAnimation(Stance, "Shoulder")
  453. if not HaltAnimation then
  454. BulletLoaded = true
  455. ReloadStage = 1
  456. end
  457. elseif Key == "R" and not BulletLoaded and ReloadStage == 2 and Stance == "Shoulder" then
  458. PlayAnimation(Stance, "ReloadRecover")
  459. PlayAnimation(Stance, "ReloadStage2")
  460. PlayAnimation(Stance, "ShoulderRecoverVariant0")
  461. PlayAnimation(Stance, "Shoulder")
  462. if not HaltAnimation then
  463. BulletLoaded = true
  464. ReloadStage = 1
  465. end
  466. elseif Key == "R" and not BulletLoaded and ReloadStage == 1 and Stance == "ReloadRecover" then
  467. PlayAnimation(Stance, "ReloadStage1")
  468. PlayAnimation(Stance, "ReloadStage2")
  469. if not HaltAnimation then
  470. ReloadStage = 2
  471. end
  472. PlayAnimation(Stance, "ShoulderRecoverVariant0")
  473. PlayAnimation(Stance, "Shoulder")
  474. if not HaltAnimation then
  475. BulletLoaded = true
  476. ReloadStage = 1
  477. end
  478. elseif Key == "R" and not BulletLoaded and ReloadStage == 2 and Stance == "ReloadRecover" then
  479. PlayAnimation(Stance, "ReloadStage2")
  480. PlayAnimation(Stance, "Shoulder")
  481. if not HaltAnimation then
  482. BulletLoaded = true
  483. ReloadStage = 1
  484. end
  485. elseif Bayonet and Key == "X" and Stance == "Shoulder" then
  486. PlayAnimation(Stance, "Bayonet")
  487. if Brace then
  488. Bracing = Character.Crouching.Enabled.Value
  489. Humanoid.AutoRotate = not Character.Crouching.Enabled.Value
  490. end
  491. elseif Bayonet and Key == "X" and Stance == "ReloadRecover" then
  492. PlayAnimation(Stance, "Bayonet")
  493. if Brace then
  494. Bracing = Character.Crouching.Enabled.Value
  495. Humanoid.AutoRotate = not Character.Crouching.Enabled.Value
  496. end
  497. elseif Bayonet and Key == "X" and Stance == "Bayonet" then
  498. PlayAnimation(Stance, "Shoulder")
  499. if Brace and Bracing then
  500. Bracing = false
  501. Humanoid.AutoRotate = true
  502. end
  503. elseif Key == "C" then
  504. Notification.WaitForExternal(Character.Crouching, "CrouchStarted")
  505. Humanoid.WalkSpeed = DetermineWalkSpeed(Stance)
  506. wait(0.1)
  507. Notification.WaitForExternal(Character.Crouching, "CrouchFinished")
  508. Humanoid.WalkSpeed = DetermineWalkSpeed(Stance)
  509. if Bayonet and Brace and Stance == "Bayonet" then
  510. Bracing = Character.Crouching.Enabled.Value
  511. Humanoid.AutoRotate = not Character.Crouching.Enabled.Value
  512. end
  513. end
  514. end)
  515. if Bayonet then
  516. do
  517. local BayonetDebounce = false
  518. Tool.BayonetHitBox.Touched:connect(function(Hit)
  519. if string.match(Stance, "BayonetThrustOut") and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") and not BayonetDebounce then
  520. BayonetDebounce = true
  521. local Blocked = false
  522. local OtherHandle = Hit.Parent:FindFirstChild("Handle", true)
  523. if OtherHandle and game.Players:FindFirstChild(Hit.Parent.Name) and OtherHandle.Parent:IsA("Model") and game.Players[Hit.Parent.Name].Inventory[OtherHandle.Parent.Name]:FindFirstChild("Blocking") and game.Players[Hit.Parent.Name].Inventory[OtherHandle.Parent.Name].Blocking.Value and not (math.rad(180) - Maths.AngleBetweenTwoParts(Character.Torso, Hit.Parent.Torso) >= math.rad(90)) then
  524. Blocked = true
  525. end
  526. if not Blocked then
  527. Tool.BayonetHitBox.HitFlesh:Play()
  528. game.ReplicatedStorage.Requests.RequestDamage:FireServer(Hit, Tool.BayonetHitBox.Position, Tool, "Melee")
  529. else
  530. OtherHandle.Block:Play()
  531. end
  532. Notification.WaitFor(script, "BayonetFinished")
  533. BayonetDebounce = false
  534. elseif string.match(Stance, "BayonetThrustOut") and Hit.Parent and (Hit.Parent:FindFirstChild("HorseHumanoid") or Hit.Parent.Parent:FindFirstChild("HorseHumanoid")) and not BayonetDebounce then
  535. BayonetDebounce = true
  536. Tool.BayonetHitBox.HitFlesh:Play()
  537. game.ReplicatedStorage.Requests.RequestDamage:FireServer(Hit.Parent:FindFirstChild("HorseCentre") or Hit.Parent.Parent:FindFirstChild("HorseCentre"), Tool.Handle.Position, Tool, "Melee")
  538. Notification.WaitFor(script, "BayonetFinished")
  539. BayonetDebounce = false
  540. elseif string.match(Stance, "BayonetThrustOut") and Hit.Parent and Hit.Parent:FindFirstChild("Integrity") and Hit.Parent:FindFirstChild("ConstructCentre") and not BayonetDebounce then
  541. BayonetDebounce = true
  542. Tool.BayonetHitBox.HitConstruct:Play()
  543. game.ReplicatedStorage.Requests.RequestDamage:FireServer(Hit.Parent.ConstructCentre, Tool.Handle.Position, Tool, "Melee")
  544. Notification.WaitFor(script, "BayonetFinished")
  545. BayonetDebounce = false
  546. elseif Brace and Bracing and Hit.Parent and (Hit.Parent:FindFirstChild("HorseHumanoid") or Hit.Parent.Parent:FindFirstChild("HorseHumanoid")) and not BayonetDebounce then
  547. BayonetDebounce = true
  548. Tool.BayonetHitBox.HitFlesh:Play()
  549. game.ReplicatedStorage.Requests.RequestDamage:FireServer(Hit.Parent:FindFirstChild("HorseCentre") or Hit.Parent.Parent:FindFirstChild("HorseCentre"), Tool.Handle.Position, Tool, "Melee")
  550. BayonetDebounce = false
  551. end
  552. end)
  553. end
  554. end
  555. wait()
  556. PlayAnimation(Stance, "Shoulder")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement