Advertisement
yonidrori

Untitled

Oct 6th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.47 KB | None | 0 0
  1. --// New weapon framework
  2. --// Completely made by LordRevorius
  3.  
  4. local Weapon_Name = ""
  5. local Players = game:GetService("Players")
  6. local RunService = game:GetService("RunService")
  7.  
  8. local Heartbeat = RunService.Heartbeat
  9. local RenderStepped = RunService.RenderStepped
  10. local CF, CA, V3, pi, sin, cos, acos, rad, random = CFrame.new, CFrame.Angles, Vector3.new, math.pi, math.sin, math.cos, math.acos, math.rad, math.random
  11.  
  12. local Player = Players.LocalPlayer
  13. local Camera = Workspace.CurrentCamera
  14. local Mouse = Player:GetMouse()
  15.  
  16. repeat RenderStepped:wait() until Player.Character and Player.Character:IsDescendantOf(workspace)
  17.  
  18. local Character = Player.Character
  19.  
  20. local Character_Data = {
  21. HumanoidRootPart = Character:WaitForChild("HumanoidRootPart"),
  22. Humanoid = Character:WaitForChild("Humanoid"),
  23. Head = Character:WaitForChild("Head"),
  24. Torso = Character:WaitForChild("Torso"),
  25. Right_Arm = Character:WaitForChild("Right Arm"),
  26. Right_Leg = Character:WaitForChild("Right Leg"),
  27. Left_Arm = Character:WaitForChild("Left Arm"),
  28. Left_Leg = Character:WaitForChild("Left Leg")
  29. }
  30.  
  31. --// Making sure the limbs won't move in another direction than we made them move.
  32. if Character:FindFirstChild("Animate") then
  33. Character.Animate.Disabled = true
  34. Character.Animate:Destroy()
  35. Character_Data.Humanoid:ClearAllChildren()
  36. end
  37.  
  38. local Main = {
  39. Pose = "Idle",
  40. Position = 0,
  41. Jumping = false,
  42. Idle_Enabled = true,
  43. Moving = false,
  44. KeyDowns = {}
  45. }
  46.  
  47. local Debounces = {}
  48.  
  49. local function Interpolate(Start, End, Alpha)
  50. return Start:lerp(End, Alpha) --// New CFrame:lerp method, Extremely smooth.
  51. end
  52.  
  53. local function Create(Class, Properties)
  54. local Object = Instance.new(Class)
  55. for Index, Value in pairs(Properties or {}) do
  56. if pcall(function() return Object[Index] end) then
  57. Object[Index] = Value
  58. end
  59. end
  60. return Object
  61. end
  62.  
  63. --// Weld Creation
  64. local Default_CFrames = {
  65. Torso = {C0 = CF(0, -1, 0), C1 = CF(0, -1, 0)},
  66. Head = {C0 = CF(0, 1.5, 0), C1 = CF(0,0,0)},
  67. Right_Arm = {C0 = CF(1.5, .5, 0), C1 = CF(0, .5, 0)},
  68. Right_Leg = {C0 = CF(.5, -1, 0), C1 = CF(0, 1, 0)},
  69. Left_Arm = {C0 = CF(-1.5, .5, 0), C1 = CF(0, .5, 0)},
  70. Left_Leg = {C0 = CF(-.5, -1, 0), C1 = CF(0, 1, 0)},
  71. }
  72.  
  73. local Torso = Create("Motor6D", {Parent = Character_Data.Torso, Part0 = Character_Data.HumanoidRootPart, Part1 = Character_Data.Torso, C0 = Default_CFrames.Torso.C0, C1 = Default_CFrames.Torso.C1})
  74. local Head = Create("Motor6D", {Parent = Character_Data.Head, Part0 = Character_Data.Torso, Part1 = Character_Data.Head, C0 = Default_CFrames.Head.C0, C1 = Default_CFrames.Head.C1})
  75. local Right_Arm = Create("Motor6D", {Parent = Character_Data.Right_Arm, Part0 = Character_Data.Torso, Part1 = Character_Data.Right_Arm, C0 = Default_CFrames.Right_Arm.C0, C1 = Default_CFrames.Left_Arm.C1})
  76. local Right_Leg = Create("Motor6D", {Parent = Character_Data.Right_Leg, Part0 = Character_Data.Torso, Part1 = Character_Data.Right_Leg, C0 = Default_CFrames.Right_Leg.C0, C1 = Default_CFrames.Right_Leg.C1})
  77. local Left_Arm = Create("Motor6D", {Parent = Character_Data.Left_Arm, Part0 = Character_Data.Torso, Part1 = Character_Data.Left_Arm, C0 = Default_CFrames.Left_Arm.C0, C1 = Default_CFrames.Left_Arm.C1})
  78. local Left_Leg = Create("Motor6D", {Parent = Character_Data.Left_Leg, Part0 = Character_Data.Torso, Part1 = Character_Data.Left_Leg, C0 = Default_CFrames.Left_Leg.C0, C1 = Default_CFrames.Left_Leg.C1})
  79.  
  80. local Weapon_Model = Create("Model", {Parent = Character, Name = Weapon_Name})
  81.  
  82. local function OnKeyDown(Key)
  83. Main.KeyDowns[Key] = true
  84. Main.KeyDowns[Key:byte()] = true
  85. if not Main.Moving then
  86. Main.Moving = true
  87. Main.Idle_Enabled = false
  88. if Key == "q" then
  89. local Original_WalkSpeed = Character_Data.Humanoid.WalkSpeed
  90. Character_Data.Humanoid.WalkSpeed = 0
  91. repeat
  92. Character_Data.Humanoid.CameraOffset = Interpolate(Character_Data.Humanoid.CameraOffset, V3(-Character_Data.Torso.Size.X/(4/3), 0, 0), .05)
  93. Torso.C1 = Interpolate(Torso.C1, Default_CFrames.Torso.C1 * CA(0, 0, rad(-35)), .1)
  94. Head.C0 = Interpolate(Head.C0, Default_CFrames.Head.C0 * CA(rad(-5 + sin(Main.Position/24)), 0, 0), .1)
  95. Right_Arm.C0 = Interpolate(Right_Arm.C0, Default_CFrames.Right_Arm.C0 * CA(0, 0, rad(5 + sin(Main.Position/24))), .1)
  96. Left_Arm.C0 = Interpolate(Left_Arm.C0, Default_CFrames.Left_Arm.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24) - 25)), .1)
  97. Right_Leg.C0 = Interpolate(Right_Leg.C0, Default_CFrames.Right_Leg.C0 * CFrame.new(0, -Character_Data.Right_Leg.Size.Y/8, 0) * CA(0, 0, rad(5 + sin(Main.Position/24) - 25)), .1)
  98. Left_Leg.C0 = Interpolate(Left_Leg.C0, Default_CFrames.Left_Leg.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24) - 25)), .1)
  99. RenderStepped:wait()
  100. until not Main.KeyDowns[Key]
  101. for _ = 1, 40 do
  102. Character_Data.Humanoid.CameraOffset = Interpolate(Character_Data.Humanoid.CameraOffset, V3(), .05)
  103. Torso.C1 = Interpolate(Torso.C1, Default_CFrames.Torso.C1, .1)
  104. Head.C0 = Interpolate(Head.C0, Default_CFrames.Head.C0 * CA(rad(-5 + sin(Main.Position/24)), 0, 0), .1)
  105. Right_Arm.C0 = Interpolate(Right_Arm.C0, Default_CFrames.Right_Arm.C0 * CA(0, 0, rad(5 + sin(Main.Position/24))), .1)
  106. Left_Arm.C0 = Interpolate(Left_Arm.C0, Default_CFrames.Left_Arm.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24))), .1)
  107. Right_Leg.C0 = Interpolate(Right_Leg.C0, Default_CFrames.Right_Leg.C0 * CA(0, 0, rad(5 + sin(Main.Position/24))), .1)
  108. Left_Leg.C0 = Interpolate(Left_Leg.C0, Default_CFrames.Left_Leg.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24))), .1)
  109. RenderStepped:wait()
  110. end
  111. Character_Data.Humanoid.WalkSpeed = Original_WalkSpeed
  112. elseif Key == "e" then
  113. local Original_WalkSpeed = Character_Data.Humanoid.WalkSpeed
  114. Character_Data.Humanoid.WalkSpeed = 0
  115. repeat
  116. Character_Data.Humanoid.CameraOffset = Interpolate(Character_Data.Humanoid.CameraOffset, V3(Character_Data.Torso.Size.X/(4/3), 0, 0), .05)
  117. Torso.C1 = Interpolate(Torso.C1, Default_CFrames.Torso.C1 * CA(0, 0, rad(35)), .1)
  118. Head.C0 = Interpolate(Head.C0, Default_CFrames.Head.C0 * CA(rad(-5 + sin(Main.Position/24)), 0, 0), .1)
  119. Right_Arm.C0 = Interpolate(Right_Arm.C0, Default_CFrames.Right_Arm.C0 * CA(0, 0, rad(5 + sin(Main.Position/24) + 25)), .1)
  120. Left_Arm.C0 = Interpolate(Left_Arm.C0, Default_CFrames.Left_Arm.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24))), .1)
  121. Right_Leg.C0 = Interpolate(Right_Leg.C0, Default_CFrames.Right_Leg.C0 * CA(0, 0, rad(5 + sin(Main.Position/24) + 25)), .1)
  122. Left_Leg.C0 = Interpolate(Left_Leg.C0, Default_CFrames.Left_Leg.C0 * CFrame.new(0, -Character_Data.Left_Leg.Size.Y/8, 0) * CA(0, 0, rad(-5 - sin(Main.Position/24) + 25)), .1)
  123. RenderStepped:wait()
  124. until not Main.KeyDowns[Key]
  125. for _ = 1, 40 do
  126. Character_Data.Humanoid.CameraOffset = Interpolate(Character_Data.Humanoid.CameraOffset, V3(), .05)
  127. Torso.C1 = Interpolate(Torso.C1, Default_CFrames.Torso.C1, .1)
  128. Head.C0 = Interpolate(Head.C0, Default_CFrames.Head.C0 * CA(rad(-5 + sin(Main.Position/24)), 0, 0), .1)
  129. Right_Arm.C0 = Interpolate(Right_Arm.C0, Default_CFrames.Right_Arm.C0 * CA(0, 0, rad(5 + sin(Main.Position/24))), .1)
  130. Left_Arm.C0 = Interpolate(Left_Arm.C0, Default_CFrames.Left_Arm.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24))), .1)
  131. Right_Leg.C0 = Interpolate(Right_Leg.C0, Default_CFrames.Right_Leg.C0 * CA(0, 0, rad(5 + sin(Main.Position/24))), .1)
  132. Left_Leg.C0 = Interpolate(Left_Leg.C0, Default_CFrames.Left_Leg.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24))), .1)
  133. RenderStepped:wait()
  134. end
  135. Character_Data.Humanoid.WalkSpeed = Original_WalkSpeed
  136. end
  137. Main.Moving = false
  138. Main.Idle_Enabled = true
  139. end
  140. end
  141.  
  142. local function OnKeyUp(Key)
  143. Main.KeyDowns[Key] = false
  144. Main.KeyDowns[Key:byte()] = false
  145. end
  146.  
  147. local function CheckJump(Value)
  148. Main.Jumping = Value
  149. end
  150.  
  151. --// Weapon Creation
  152. --// Parts
  153.  
  154.  
  155. --// Meshes
  156.  
  157.  
  158. --// Welds
  159.  
  160.  
  161. local function Main_RenderStepped() --// Main animation loop.
  162. local Movement = 1
  163. if Main.Idle_Enabled then
  164. if Main.Jumping then
  165. Main.Pose = "Jumping"
  166. elseif (Character_Data.Torso.Velocity * V3(1, 0, 1)).magnitude < 2 then
  167. Main.Pose = "Idle"
  168. elseif (Character_Data.Torso.Velocity * V3(1, 0, 1)).magnitude < 24 then
  169. Main.Pose = "Walking"
  170. elseif (Character_Data.Torso.Velocity * V3(1, 0, 1)).magnitude >= 24 then
  171. Main.Pose = "Running"
  172. end
  173. if Main.Pose == "Idle" then
  174. Head.C0 = Interpolate(Head.C0, Default_CFrames.Head.C0 * CA(rad(-5 + sin(Main.Position/24)), 0, 0), .2)
  175. Torso.C0 = Interpolate(Torso.C0, Default_CFrames.Torso.C0, .2)
  176. Right_Arm.C0 = Interpolate(Right_Arm.C0, Default_CFrames.Right_Arm.C0 * CA(0, 0, rad(5 + sin(Main.Position/24))), .2)
  177. Left_Arm.C0 = Interpolate(Left_Arm.C0, Default_CFrames.Left_Arm.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24))), .2)
  178. Right_Leg.C0 = Interpolate(Right_Leg.C0, Default_CFrames.Right_Leg.C0 * CA(0, 0, rad(5 + sin(Main.Position/24))), .2)
  179. Left_Leg.C0 = Interpolate(Left_Leg.C0, Default_CFrames.Left_Leg.C0 * CA(0, 0, rad(-5 - sin(Main.Position/24))), .2)
  180. elseif Main.Pose == "Jumping" then
  181. Movement = 2
  182. Head.C0 = Interpolate(Head.C0, Default_CFrames.Head.C0 * CA(rad(-5 + sin(Main.Position/24)), 0, 0), .2)
  183. Torso.C0 = Interpolate(Torso.C0, Default_CFrames.Torso.C0, .2)
  184. Right_Arm.C0 = Interpolate(Right_Arm.C0, Default_CFrames.Right_Arm.C0 * CA(rad(150 + sin(Main.Position/6)*5), 0, rad(5 + sin(Main.Position/24))), .2)
  185. Left_Arm.C0 = Interpolate(Left_Arm.C0, Default_CFrames.Left_Arm.C0 * CA(rad(150 + sin(Main.Position/6)*5), 0, rad(-5 - sin(Main.Position/24))), .2)
  186. Right_Leg.C0 = Interpolate(Right_Leg.C0, Default_CFrames.Right_Leg.C0 * CA(sin(Main.Position/24)/8, 0, rad(5) + cos(Main.Position/24)/24), .2)
  187. Left_Leg.C0 = Interpolate(Left_Leg.C0, Default_CFrames.Left_Leg.C0 * CA(sin(-Main.Position/24)/8, 0, rad(-5) - cos(Main.Position/24)/24), .2)
  188. elseif Main.Pose == "Walking" then
  189. Head.C0 = Interpolate(Head.C0, Default_CFrames.Head.C0 * CA(rad(-5 + sin(Main.Position/8)), 0, 0), .2)
  190. Torso.C0 = Interpolate(Torso.C0, Default_CFrames.Torso.C0, .2)
  191. Right_Arm.C0 = Interpolate(Right_Arm.C0, Default_CFrames.Right_Arm.C0 * CA(sin(-Main.Position/8)/2, 0, rad(5 + sin(Main.Position/24))), .2)
  192. Left_Arm.C0 = Interpolate(Left_Arm.C0, Default_CFrames.Left_Arm.C0 * CA(sin(Main.Position/8)/2, 0, rad(-5 - sin(Main.Position/24))), .2)
  193. Right_Leg.C0 = Interpolate(Right_Leg.C0, Default_CFrames.Right_Leg.C0 * CA(sin(Main.Position/8)/1.5, 0, 0), .2)
  194. Left_Leg.C0 = Interpolate(Left_Leg.C0, Default_CFrames.Left_Leg.C0 * CA(sin(-Main.Position/8)/1.5, 0, 0), .2)
  195. elseif Main.Pose == "Running" then
  196. Head.C0 = Interpolate(Head.C0, Default_CFrames.Head.C0 * CA(rad(-5 + sin(Main.Position/5)), 0, 0), .2)
  197. Torso.C0 = Interpolate(Torso.C0, Default_CFrames.Torso.C0, .2)
  198. Right_Arm.C0 = Interpolate(Right_Arm.C0, Default_CFrames.Right_Arm.C0 * CA(sin(-Main.Position/5)/1.5, 0, rad(5 + sin(Main.Position/24))), .2)
  199. Left_Arm.C0 = Interpolate(Left_Arm.C0, Default_CFrames.Left_Arm.C0 * CA(sin(Main.Position/5)/1.5, 0, rad(-5 - sin(Main.Position/24))), .2)
  200. Right_Leg.C0 = Interpolate(Right_Leg.C0, CF(.5, -1, 0) * CA(sin(Main.Position/5)/1.25, 0, 0), .2)
  201. Left_Leg.C0 = Interpolate(Left_Leg.C0, Default_CFrames.Left_Leg.C0 * CA(sin(-Main.Position/5)/1.25, 0, 0), .2)
  202. end
  203. end
  204. Main.Position = Main.Position + Movement
  205. end
  206.  
  207. Mouse.KeyDown:connect(OnKeyDown)
  208. Mouse.KeyUp:connect(OnKeyUp)
  209. RenderStepped:connect(Main_RenderStepped)
  210. Character_Data.Humanoid.FreeFalling:connect(CheckJump)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement