Expl0re

The Mad Murderer Knife

Aug 4th, 2017
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.59 KB | None | 0 0
  1. local tool=Instance.new("HopperBin", game.Players.LocalPlayer.Backpack)
  2. tool.Name="Knife"
  3.  
  4. wait()
  5. script.Parent=tool
  6. wait()
  7. local camera = game.Workspace.CurrentCamera
  8. local player = game.Players.LocalPlayer
  9. local character = player.Character
  10. local humanoid = character.Humanoid
  11. local head = character.Head
  12. local torso = character.Torso
  13. local pl_mouse = player:GetMouse()
  14.  
  15. local rs = game:GetService("RunService")
  16.  
  17. local stab_damage = 110
  18. local walkspeeds = {16, 19}
  19.  
  20. Settings = {
  21. Equip_time = 0.4,
  22. Idle_speed = 5,
  23. Attack_speed = 0.65,
  24. }
  25.  
  26. local assetlink = "http://www.roblox.com/asset/?id="
  27. local hit_sounds = {"153647516", "153647519", "153647522", "153647526"}
  28. local death_sounds = {"146594640", "146594648", "146457047"}
  29. function Clean(obj)
  30. spawn(function()
  31. wait(6)
  32. obj:remove()
  33. end)
  34. end
  35.  
  36. function HIT_HANDLE(hit, dmg, pos)
  37. if hit == nil then return end
  38. local h = hit.Parent:findFirstChild("Humanoid")
  39. if h == nil then
  40. h = hit.Parent.Parent:findFirstChild("Humanoid")
  41. end
  42. if h == nil then return end
  43. if h.Health <= 0 then return end
  44.  
  45. local head = h.Parent:findFirstChild("Head")
  46. if head == nil then return end
  47.  
  48. local sound_part = Instance.new("Part")
  49. sound_part.formFactor = "Custom"
  50. sound_part.Size = Vector3.new(0.2, 0.2, 0.2)
  51. sound_part.Transparency = 1
  52. sound_part.CanCollide = false
  53. sound_part.Anchored = true
  54. sound_part.CFrame = head.CFrame
  55. Clean(sound_part)
  56. sound_part.Parent = Workspace
  57. local s_hit = Instance.new("Sound")
  58. s_hit.Volume = 1
  59. s_hit.SoundId = assetlink .. hit_sounds[math.random(1, #hit_sounds)]
  60. s_hit.Parent = sound_part
  61. local s_die = Instance.new("Sound")
  62. s_die.Volume = 1
  63. s_die.SoundId = assetlink .. death_sounds[math.random(1, #death_sounds)]
  64. s_die.Parent = sound_part
  65.  
  66. s_hit:play()
  67.  
  68. local c_tag = Instance.new("ObjectValue")
  69. c_tag.Name = "creator"
  70. c_tag.Value = player
  71. c_tag.Parent = h
  72. h.Health=0
  73. s_die:play()
  74. end
  75.  
  76. function GENERATE_IGNORELIST()
  77. local result = {character, camera}
  78. local plr = game.Players:GetPlayers()
  79. for i = 1, #plr do
  80. if plr[i] ~= player then
  81. local char = plr[i].Character
  82. if char ~= nil then
  83. local ch = char:GetChildren()
  84. for i = 1, #ch do
  85. if ch[i]:IsA("Hat") or ch[i]:IsA("Tool") then
  86. result[#result + 1] = ch[i]
  87. end
  88. end
  89. end
  90. end
  91. end
  92. return result
  93. end
  94.  
  95. function RayCast(pos1, pos2, dist, ign)
  96. local ray = Ray.new(
  97. pos1,
  98. (pos2 - pos1).unit * math.abs(dist)
  99. )
  100. local hit, hpos = Workspace:FindPartOnRayWithIgnoreList(ray, ign, false)
  101. return hit, hpos
  102. end
  103.  
  104. local larm = character:findFirstChild("Left Arm")
  105. local rarm = character:findFirstChild("Right Arm")
  106. function Slash(del)
  107. coroutine.resume(coroutine.create(function()
  108. local hits = {}
  109.  
  110. local start = tick()
  111. local actv = true
  112.  
  113. local function ishitted(obj)
  114. for i = 1, #hits do
  115. if obj:IsDescendantOf(hits[i]) then
  116. return true
  117. end
  118. end
  119. return false
  120. end
  121.  
  122. local function hitp(hit)
  123. if ishitted(hit) then return end
  124. local h = hit.Parent:findFirstChild("Humanoid")
  125. if h == nil then
  126. h = hit.Parent.Parent:findFirstChild("Humanoid")
  127. end
  128. if h == nil then return end
  129. hits[#hits + 1] = h.Parent
  130. HIT_HANDLE(hit, stab_damage)
  131. end
  132.  
  133. local con = {
  134. larm.Touched:connect(hitp),
  135. rarm.Touched:connect(hitp),
  136. }
  137.  
  138. while tick() - start <= Settings.Attack_speed do wait() end
  139. actv = false
  140. con[1]:disconnect()
  141. con[2]:disconnect()
  142. end))
  143. end
  144.  
  145. local dg_sounds = {
  146. equip = {
  147. "153647514"
  148. },
  149. hit = {
  150. "153647516",
  151. "153647519",
  152. "153647522",
  153. "153647526"
  154. },
  155. swing = {
  156. "153647529",
  157. "153647534",
  158. "153647539",
  159. "153647540"
  160. }
  161. }
  162.  
  163. local dg_soundobj = {}
  164. for k, v in pairs(dg_sounds) do
  165. dg_soundobj[k] = {}
  166. for i = 1, #v do
  167. local ns = Instance.new("Sound")
  168. ns.SoundId = assetlink .. v[i]
  169. ns.Volume = 1
  170. dg_soundobj[k][#dg_soundobj[k] + 1] = ns
  171. end
  172. end
  173.  
  174. function LoadSounds()
  175. for __, v in pairs(dg_soundobj) do
  176. for i = 1, #v do
  177. v[i].Parent = head
  178. end
  179. end
  180. end
  181. function RemoveSounds()
  182. for __, v in pairs(dg_soundobj) do
  183. for i = 1, #v do
  184. v[i].Parent = nil
  185. end
  186. end
  187. end
  188. function PlaySound(nm, dl)
  189. if dl == nil then
  190. dg_soundobj[nm][math.random(1, #dg_soundobj[nm])]:play()
  191. else
  192. coroutine.resume(coroutine.create(function()
  193. wait(dl)
  194. dg_soundobj[nm][math.random(1, #dg_soundobj[nm])]:play()
  195. end))
  196. end
  197. end
  198.  
  199. _G.MurderKnife_AnimType = "Default"
  200. _G.MurderKnife_AnimState = 0
  201.  
  202. function Animate(tp, st)
  203. _G.MurderKnife_AnimType = tp
  204. _G.MurderKnife_AnimState = st
  205. end
  206.  
  207. tool.Selected:connect(function(mouse) --Default, Idle1, Idle2, Attack1, Attack2
  208. humanoid.WalkSpeed = walkspeeds[2]
  209. mouse.Icon = assetlink .. "54019936"
  210. Animate("Equip", 0)
  211. LoadSounds()
  212. PlaySound("equip", 0.1)
  213.  
  214. local anim_equip = 1
  215. local last_action = tick()
  216. local idle_rand = math.random(4, 7)
  217. local idle_perform = 0
  218. local idle_type = 1
  219.  
  220. local attack_perform = 0
  221. local attack_type = 1
  222.  
  223. local running = true
  224. local last_c = tick()
  225.  
  226. local click_start = tick()
  227. mouse.Button1Down:connect(function()
  228. if not running or anim_equip > 0 then return end
  229. if tick() - attack_perform <= Settings.Attack_speed then return end
  230. attack_perform = tick()
  231. last_action = tick()
  232. attack_type = math.random(1, 3)
  233. idle_perform = 0
  234. PlaySound("swing", 0.15)
  235. Slash(0.17)
  236. end)
  237.  
  238. local conn = rs.RenderStepped:connect(function()
  239. if not running then return end
  240. local delta = tick() - last_c
  241. last_c = tick()
  242.  
  243. if anim_equip > 0 then
  244. anim_equip = math.max(0, anim_equip - (delta / Settings.Equip_time))
  245. Animate("Equip", 1 - anim_equip)
  246. elseif tick() - attack_perform <= Settings.Attack_speed then
  247. Animate("Attack" .. attack_type, (tick() - attack_perform) / Settings.Attack_speed)
  248. idle_perform = 0
  249. elseif tick() - idle_perform <= Settings.Idle_speed then
  250. Animate("Idle" .. idle_type, (tick() - idle_perform) / Settings.Idle_speed)
  251. else
  252. Animate("Default", 0)
  253. end
  254.  
  255. if tick() - last_action >= idle_rand then
  256. idle_rand = math.random(12, 20)
  257. last_action = tick()
  258. idle_perform = tick()
  259. idle_type = math.random(1, 2)
  260. end
  261.  
  262. end)
  263. tool.Deselected:connect(function() running = false conn:disconnect() end)
  264. end)
  265. tool.Deselected:connect(function()
  266. RemoveSounds()
  267. humanoid.WalkSpeed = walkspeeds[1]
  268. end)
  269.  
  270. --Murderer knife animation module, original code from The Mad Murderer, by loleris.
  271.  
  272. local mouse = pl_mouse
  273.  
  274. local conn_type = "Snap"
  275.  
  276. local anim_head = false
  277.  
  278. weapon_properties = {
  279. mesh_id = "http://www.roblox.com/asset/?id=121944778",
  280. texture_id = "http://www.roblox.com/asset/?id=121944805",
  281. scale = Vector3.new(0.6, 0.6, 0.6),
  282. transparency = 0,
  283. reflectance = 0,
  284. brick_color = BrickColor.new("Really black"),
  285. }
  286.  
  287. --How did I make all of this? Magic. Didn't even need an animation editor :)
  288. Animations = {
  289. Default = {
  290. {{}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)}
  291. },
  292. Equip = {
  293. {{}, 0, CFrame.new(0, 0, 0) * CFrame.Angles(-1.571, 0, 0), CFrame.new(0, 0, 0) * CFrame.Angles(-1.571, 0, 0), CFrame.new(0, -1.3, -0.5) * CFrame.Angles(-2.618, 0, 0)},
  294. {{0.8, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.524, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(0, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  295. {{0.2, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  296. },
  297. Idle1 = {
  298. {{}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  299. {{0.3, 2}, 0, CFrame.new(0.8, -0.301, 0.2) * CFrame.Angles(-0.35, 0, 0.872), CFrame.new(-0.201, 0, 0) * CFrame.Angles(0.523, 1.221, -0.699), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 1.221, 0)},
  300. {{0.55, 2}, 0, CFrame.new(0.2, -0.5, 0.2) * CFrame.Angles(-0.14, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(0, 1.221, -0.175), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.746, 1.221, 0.174)},
  301. {{0.15, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  302. },
  303. Idle2 = {
  304. {{}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  305. {{0.3, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.524, 0, 0.872), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, -0.175, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0.523, 0)},
  306. {{0.3, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(0.349, 0, 0.523), CFrame.new(-0.201, 0, 0) * CFrame.Angles(0.174, 0.698, -0.524), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, -1.222, 0)},
  307. {{0.2, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(0.61, 0, 0.349), CFrame.new(-0.201, 0, 0) * CFrame.Angles(0.139, 0.663, -0.489), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, -1.222, 0)},
  308. {{0.2, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)}
  309. },
  310. Attack1 = {
  311. {{}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  312. {{0.25, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-1.048, 0, 0.349), CFrame.new(-0.201, 0, 0) * CFrame.Angles(0.872, 0.349, 0.087), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  313. {{0.15, 2}, 0, CFrame.new(0.4, -0.101, 0.1) * CFrame.Angles(-1.571, 0, -0.35), CFrame.new(-0.301, -0.301, 0.1) * CFrame.Angles(-1.048, -0.175, -0.524), CFrame.new(0, -1.201, -0.801) * CFrame.Angles(-2.095, 0, 0)},
  314. {{0.6, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)}
  315. },
  316. Attack2 = {
  317. {{}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  318. {{0.25, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.699, 0, 0.872), CFrame.new(-0.401, 0.3, 0.1) * CFrame.Angles(1.919, 2.443, -1.222), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  319. {{0.15, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-1.048, 0, -0.524), CFrame.new(-0.5, -0.201, -0.101) * CFrame.Angles(0.523, 1.396, -0.873), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  320. {{0.6, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)}
  321. },
  322. Attack3 = {
  323. {{}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)},
  324. {{0.25, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-1.397, 0, 0.174), CFrame.new(-0.401, -0.201, 0) * CFrame.Angles(1.396, 0.698, -1.571), CFrame.new(0, -1.3, -0.401) * CFrame.Angles(-2.444, 0, 0)},
  325. {{0.15, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-1.397, 0, 0.174), CFrame.new(-0.401, 0.1, 0) * CFrame.Angles(0.349, 2.094, -0.524), CFrame.new(0, -1.3, 0.1) * CFrame.Angles(-3.84, 0, 0)},
  326. {{0.6, 2}, 0, CFrame.new(0.4, -0.201, 0.2) * CFrame.Angles(-0.873, 0, 0.698), CFrame.new(-0.201, 0, 0) * CFrame.Angles(-0.175, 0.349, -0.262), CFrame.new(0, -0.95, -0.801) * CFrame.Angles(-1.571, 0, 0)} --Psst. Create a dummy, try setting position and angles of limbs and the weapon, save CFrame data to code. Easy? Yes. When making a single knife tool, it was all you needed.
  327. }
  328. }
  329.  
  330.  
  331. function CFrameTrans(GetCFrame1, GetCFrame2, GetNumber)
  332. local Diff2 = GetCFrame2.p - GetCFrame1.p
  333. GetCFrame1_s = GetCFrame1 - GetCFrame1.p
  334. GetCFrame2 = GetCFrame2 - GetCFrame2.p
  335. local Diff = GetCFrame1_s:inverse() * GetCFrame2
  336. local x1, y1, z1 = Diff:toEulerAnglesXYZ()
  337. return (GetCFrame1 + (Diff2 * GetNumber)) * CFrame.Angles(x1 * GetNumber, y1 * GetNumber, z1 * GetNumber)
  338. end
  339.  
  340. function TransEff(x, type)
  341. if type == 1 then
  342. return x
  343. elseif type == 2 then
  344. return x*x*(3 - 2*x)
  345. elseif type == 3 then
  346. return math.sin(math.rad(x * 90))
  347. elseif type == 4 then
  348. return 1 - math.sin(math.rad((1 - x) * 90))
  349. end
  350. end
  351.  
  352. function num_trans(n1, n2, x)
  353. return n1 + ((n2 - n1) * x)
  354. end
  355.  
  356. function PlayAnimation(anim_name, tm) --return {left, right, wep, trans}
  357. tm = math.min(1, math.max(0, tm))
  358. local animd = Animations[anim_name]
  359. if #animd == 1 then
  360. return {animd[1][3], animd[1][4], animd[1][5], animd[1][2]}
  361. else
  362. local trans_from = 1
  363. local trans_to = 1
  364. local tm_left = tm
  365. for i = 2, #animd do
  366. tm_left = tm_left - animd[i][1][1]
  367. if tm_left <= 0 then
  368. trans_from = i - 1
  369. trans_to = i
  370. break
  371. end
  372. end
  373. local trans_amm = TransEff((animd[trans_to][1][1] + tm_left) / animd[trans_to][1][1], animd[trans_to][1][2])
  374. return {
  375. CFrameTrans(animd[trans_from][3], animd[trans_to][3], trans_amm),
  376. CFrameTrans(animd[trans_from][4], animd[trans_to][4], trans_amm),
  377. CFrameTrans(animd[trans_from][5], animd[trans_to][5], trans_amm),
  378. num_trans(animd[trans_from][2], animd[trans_to][2], trans_amm)
  379. }
  380. end
  381. end
  382.  
  383. rot_amplitude_head = 20
  384. rot_amplitude_chest = 15
  385.  
  386. anim_p = {
  387. cam_offset = CFrame.new(0.2, -0.37, 0.91) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(0)),
  388. aim_amp = 0.5,
  389. aim_max_change = 4,
  390. aim_retract = 15,
  391. aim_max_deg = 20,
  392. }
  393.  
  394. local weapon_model = Instance.new("Part")
  395. weapon_model.CanCollide = false
  396. weapon_model.Name = "WeaponObject"
  397. weapon_model.formFactor = "Custom"
  398. weapon_model.Size = Vector3.new(0.2, 0.2, 0.2)
  399. weapon_model.TopSurface = 0
  400. weapon_model.BottomSurface = 0
  401. weapon_model.BrickColor = weapon_properties.brick_color
  402. weapon_model.Transparency = weapon_properties.transparency
  403. weapon_model.Reflectance = weapon_properties.reflectance
  404. local mesh = Instance.new("SpecialMesh", weapon_model)
  405. mesh.Scale = weapon_properties.scale
  406. mesh.MeshId = weapon_properties.mesh_id
  407. mesh.TextureId = weapon_properties.texture_id
  408.  
  409. torso = character.Torso
  410. head = character.Head
  411.  
  412. motors = {torso:findFirstChild("Left Shoulder"), torso:findFirstChild("Right Shoulder"), torso:findFirstChild("Neck")}
  413. welds = {nil, nil, nil}
  414. weapon_parts = {weapon_model:clone(), weapon_model:clone()}
  415. weapon_model = nil
  416.  
  417. function EndAnimation()
  418. if motors[1] then
  419. motors[1].Part1 = character:findFirstChild("Left Arm")
  420. end
  421. if motors[2] then
  422. motors[2].Part1 = character:findFirstChild("Right Arm")
  423. end
  424. if motors[3] then
  425. motors[3].Part1 = character:findFirstChild("Head")
  426. end
  427. if welds[1] then
  428. welds[1]:remove()
  429. welds[1] = nil
  430. end
  431. if welds[2] then
  432. welds[2]:remove()
  433. welds[2] = nil
  434. end
  435. if welds[3] then
  436. welds[3]:remove()
  437. welds[3] = nil
  438. end
  439. weapon_parts[1].Parent = nil
  440. if weapon_model then
  441. weapon_model.Parent = nil
  442. end
  443. coroutine.resume(coroutine.create(function()
  444. local swm = weapon_model
  445. wait()
  446. swm.Parent = nil
  447. wait(0.1)
  448. swm.Parent = nil
  449. wait(0.5)
  450. swm.Parent = nil
  451. end))
  452. end
  453.  
  454. local anim_model = Instance.new("Model")
  455. anim_model.Name = "WeaponAnimation"
  456. weapon_model = anim_model
  457.  
  458. local cam_larm = Instance.new("Part")
  459. cam_larm.Parent = anim_model
  460. cam_larm.BrickColor = BrickColor.new("Really black")
  461. cam_larm.formFactor = "Custom"
  462. cam_larm.Size = Vector3.new(0.2, 0.2, 0.2)
  463. cam_larm.TopSurface = 0
  464. cam_larm.BottomSurface = 0
  465. cam_larm.Transparency = 0.4
  466. cam_larm.CanCollide = false
  467. local hmesh = Instance.new("BlockMesh", cam_larm)
  468. hmesh.Scale = Vector3.new(5, 10, 5)
  469.  
  470. local cam_rarm = cam_larm:clone()
  471. cam_rarm.Parent = anim_model
  472.  
  473. function StartAnimation()
  474. local check = {torso:findFirstChild("LeftWeld"), torso:findFirstChild("RightWeld"), torso:findFirstChild("HeadWeld")}
  475. if check[1] then check[1]:remove() end
  476. if check[2] then check[2]:remove() end
  477. if check[3] then check[3]:remove() end
  478. local check2 = {character:findFirstChild("WeaponObject"), camera:findFirstChild("WeaponAnimation")}
  479. if check2[1] then check2[1].Parent = nil end
  480. if check2[2] then check2[2].Parent = nil end
  481. if motors[1] then
  482. motors[1].Part1 = nil
  483. end
  484. if motors[2] then
  485. motors[2].Part1 = nil
  486. end
  487. if motors[3] then
  488. motors[3].Part1 = nil
  489. end
  490. welds = {Instance.new(conn_type), Instance.new(conn_type), Instance.new(conn_type)}
  491. welds[1].Part0 = torso
  492. welds[2].Part0 = torso
  493. welds[3].Part0 = torso
  494. welds[1].Part1 = character:findFirstChild("Left Arm")
  495. welds[2].Part1 = character:findFirstChild("Right Arm")
  496. welds[3].Part1 = character:findFirstChild("Head")
  497. welds[1].Name = "LeftWeld"
  498. welds[2].Name = "RightWeld"
  499. welds[2].Name = "HeadWeld"
  500. welds[1].C0 = CFrame.new(-1.5, 0, 0)
  501. welds[2].C0 = CFrame.new(1.5, 0, 0)
  502. welds[3].C0 = CFrame.new(0, 1.5, 0)
  503. welds[1].Parent = torso
  504. welds[2].Parent = torso
  505. welds[3].Parent = torso
  506.  
  507. weapon_parts[1].Parent = character
  508. local wep_weld = Instance.new(conn_type)
  509. wep_weld.Part0 = character:findFirstChild("Right Arm")
  510. wep_weld.Part1 = weapon_parts[1]
  511. wep_weld.C0 = CFrame.new()
  512. wep_weld.Parent = weapon_parts[1]
  513.  
  514. local weld1 = welds[1]
  515. local weld2 = welds[2]
  516. local weld3 = welds[3]
  517.  
  518. local cam_welds = {Instance.new(conn_type), Instance.new(conn_type), Instance.new(conn_type)}
  519. cam_welds[1].Part0 = torso
  520. cam_welds[1].Part1 = cam_larm
  521. cam_welds[1].Parent = cam_larm
  522. cam_welds[2].Part0 = torso
  523. cam_welds[2].Part1 = cam_rarm
  524. cam_welds[2].Parent = cam_rarm
  525. cam_welds[3].Part0 = cam_rarm
  526. cam_welds[3].Part1 = weapon_parts[2]
  527. cam_welds[3].Parent = weapon_parts[2]
  528. weapon_parts[2].Parent = anim_model
  529.  
  530. local move_anim_speed = 3
  531. local last_p = Vector3.new()
  532. local move_amm = 0
  533. coroutine.resume(coroutine.create(function()
  534. while weld1.Parent ~= nil do
  535. local delta = wait(1/25)
  536. local cur_p = torso.Position
  537. if (cur_p - last_p).magnitude >= 0.1 then
  538. move_amm = math.min(1, move_amm + delta * move_anim_speed)
  539. else
  540. move_amm = math.max(0, move_amm - delta * move_anim_speed)
  541. end
  542. last_p = cur_p
  543. end
  544. end))
  545.  
  546. local r_serv = game:GetService("RunService")
  547.  
  548. --EASTER EGG
  549. function easein(x)
  550. return math.sin(math.rad(x * 90))
  551. end
  552.  
  553. local a_horse = (character:findFirstChild("HorseHead") ~= nil)
  554. local horse_displace = {0, 0}
  555. local horse_cf = CFrame.Angles(0.0001, 0.0001, 0)
  556. if a_horse then
  557. coroutine.resume(coroutine.create(function()
  558. while weld1.Parent ~= nil do
  559. local rndwait = (math.random(100, 1000) / 1000) * 4
  560. wait(rndwait)
  561. local oldd = {horse_displace[1], horse_displace[2]}
  562. local disp2 = {math.random(-60, 60), math.random(0, 25)}
  563.  
  564. local ld = 0
  565. while ld ~= 1 do
  566. local st = tick()
  567. r_serv.RenderStepped:wait()
  568. ld = math.min(1, ld + ((tick() - st) * 4))
  569. local eff = easein(ld)
  570.  
  571. local x = oldd[1] - ((oldd[1] - disp2[1]) * eff)
  572. local y = oldd[2] - ((oldd[2] - disp2[2]) * eff)
  573. horse_displace = {x, y}
  574. horse_cf = CFrame.Angles(math.rad(y), math.rad(x) , 0)
  575. end
  576. end
  577. end))
  578. end
  579.  
  580. --EASTER EGG
  581.  
  582. local last_va = 0
  583. local last_va2 = 0
  584. local view_velocity = {0, 0}
  585.  
  586. coroutine.resume(coroutine.create(function()
  587. local last_time = tick()
  588. while weld1.Parent ~= nil do
  589. r_serv.RenderStepped:wait() ------------------------------------------------
  590. local delta = tick() - last_time
  591. last_time = tick()
  592.  
  593. local breathe_amp = 2
  594. local breathe_freq = 0.8
  595. local breathe = math.sin(math.rad(tick() * 90 * breathe_freq)) * breathe_amp
  596.  
  597. local shake_freq = 5
  598. local shake_amp = {0.05, 0.05}
  599. local arm_shake = CFrame.new(
  600. math.sin(math.rad(tick() * 90 * shake_freq)) * move_amm * shake_amp[1],
  601. 0,
  602. math.abs(math.sin(math.rad(tick() * 90 * shake_freq)) * move_amm * shake_amp[2]))
  603.  
  604.  
  605. --ANIMATION LOOP
  606. local p_distance = (head.Position - mouse.Hit.p).magnitude
  607. if p_distance == 0 then p_distance = 0.0001 end
  608. local p_height = mouse.Hit.p.y - head.Position.y
  609. local view_angle
  610. if p_height ~= 0 then
  611. view_angle = math.deg(math.asin(math.abs(p_height) / p_distance)) * (math.abs(p_height) / p_height)
  612. else
  613. view_angle = 0
  614. end
  615.  
  616. local cam_cf = camera.CoordinateFrame
  617. local looking_at = cam_cf * CFrame.new(0, 0, -100)
  618. local view_angle2 = math.deg(math.atan2(cam_cf.p.x - looking_at.p.x, cam_cf.p.z - looking_at.p.z)) + 180
  619.  
  620. local v_delta1, v_delta2
  621. local dir1 = 0
  622. local dir2 = 0
  623. v_delta1 = math.abs(view_angle - last_va)
  624. if v_delta1 ~= 0 then
  625. dir1 = (view_angle - last_va) / v_delta1
  626. end
  627. local va_check = {math.abs(view_angle2 - last_va2), 360 - math.abs(view_angle2 - last_va2)}
  628. if view_angle2 == last_va2 then
  629. dir2 = 0
  630. v_delta2 = 0
  631. elseif va_check[1] < va_check[2] then
  632. v_delta2 = va_check[1]
  633. dir2 = (view_angle2 - last_va2) / va_check[1]
  634. else
  635. v_delta2 = va_check[2]
  636. if last_va2 > view_angle2 then
  637. dir2 = 1
  638. else
  639. dir2 = -1
  640. end
  641. end
  642. last_va = view_angle
  643. last_va2 = view_angle2
  644.  
  645. view_velocity[1] = view_velocity[1] / (1 + (delta * anim_p.aim_retract))
  646. view_velocity[2] = view_velocity[2] / (1 + (delta * anim_p.aim_retract))
  647.  
  648. local calc1 = v_delta1 * dir1 * anim_p.aim_amp
  649. if calc1 ~= 0 then
  650. view_velocity[1] = view_velocity[1] + (math.min(anim_p.aim_max_change, math.abs(calc1)) * (calc1 / math.abs(calc1)))
  651. end
  652. local calc2 = v_delta2 * dir2 * anim_p.aim_amp
  653. if calc2 ~= 0 then
  654. view_velocity[2] = view_velocity[2] + (math.min(anim_p.aim_max_change, math.abs(calc2)) * (calc2 / math.abs(calc2)))
  655. end
  656.  
  657. if view_velocity[1] ~= 0 then
  658. view_velocity[1] = math.min(anim_p.aim_max_deg, math.abs(view_velocity[1])) * (math.abs(view_velocity[1]) / view_velocity[1])
  659. end
  660. if view_velocity[2] ~= 0 then
  661. view_velocity[2] = math.min(anim_p.aim_max_deg, math.abs(view_velocity[2])) * (math.abs(view_velocity[2]) / view_velocity[2])
  662. end
  663.  
  664. local anmtp = _G.MurderKnife_AnimType
  665. local anmst = _G.MurderKnife_AnimState
  666.  
  667. if anmst == nil then
  668. anmst = 0
  669. end
  670.  
  671. if anmtp ~= nil then
  672. if Animations[anmtp] == nil then
  673. anmtp = "Default"
  674. end
  675. else
  676. anmtp = "Default"
  677. end
  678. local curr_anim = PlayAnimation(anmtp, anmst) --left, right, weapon, wep trans
  679.  
  680. --curr_anim = {Animations.Default[1][3], Animations.Default[1][4], Animations.Default[1][5], 0}
  681.  
  682. local chestCF = CFrame.new(0, 0.5, 0) * CFrame.Angles(math.rad(math.max(-rot_amplitude_chest, math.min(rot_amplitude_chest, view_angle)) + 90 + breathe), 0, 0)
  683. weld1.C1 = (chestCF * curr_anim[1] * CFrame.new(0, -0.5, 0)):inverse()
  684. weld2.C1 = (chestCF * curr_anim[2] * CFrame.new(0, -0.5, 0)):inverse()
  685. wep_weld.C1 = (curr_anim[3]):inverse()
  686. weapon_parts[1].Transparency = curr_anim[4]
  687. if anim_head then
  688. weld3.C1 = (CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(math.max(-rot_amplitude_head, math.min(rot_amplitude_head, view_angle))), 0, 0) * horse_cf):inverse()
  689. else
  690. weld3.C1 = (CFrame.new(0, 0, 0)):inverse()
  691. end
  692.  
  693. if (head.Position - camera.CoordinateFrame.p).magnitude < 3 then
  694. if anim_model.Parent == nil then
  695. anim_model.Parent = camera
  696. end
  697. cam_welds[1].Parent = cam_larm
  698. cam_welds[2].Parent = cam_rarm
  699. cam_welds[3].Parent = weapon_parts[2]
  700. local cam_cf = camera.CoordinateFrame * CFrame.Angles(math.rad(90 + (breathe / 2) - view_velocity[1]), 0, math.rad(view_velocity[2])) * arm_shake * anim_p.cam_offset
  701. cam_welds[1].C1 = (torso.CFrame:inverse() * cam_cf * CFrame.new(-1.5, 0, 0) * curr_anim[1] * CFrame.new(0, -0.5, 0)):inverse()
  702. cam_welds[2].C1 = (torso.CFrame:inverse() * cam_cf * CFrame.new(1.5, 0, 0) * curr_anim[2] * CFrame.new(0, -0.5, 0)):inverse()
  703. cam_welds[3].C1 = (curr_anim[3]):inverse()
  704. weapon_parts[2].Transparency = curr_anim[4]
  705. else
  706. if anim_model.Parent ~= nil then
  707. anim_model.Parent = nil
  708. end
  709. end
  710. --ANIMATION LOOP
  711. end
  712. end))
  713. end
  714.  
  715. local last_st = 0
  716. local eq = false
  717. tool.Selected:connect(function(mouse)
  718. if eq then return end
  719. eq = true
  720. wait()
  721. StartAnimation()
  722. end)
  723.  
  724. tool.Deselected:connect(function()
  725. eq = false
  726. EndAnimation()
  727. end)
Advertisement
Add Comment
Please, Sign In to add comment