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