View difference between Paste ID: av8CiQwd and wukHA6Gj
SHOW: | | - or go back to the newest paste.
1
print 'RUSSIAN DANCE BY LYKASPARS4! HAS BEEN RUNNED!'
2
print 'SOUND:YES'
3
print 'ANIMATION:YES'
4
5
local s = Instance.new("Sound")
6
 
7
s.Name = "Sound"
8
s.SoundId = "http://www.roblox.com/asset/?id=169566828"
9
s.Volume = 1
10
s.Looped = true
11
s.archivable = false
12
 
13
s.Parent = game.Workspace
14
 
15
wait(3)
16
 
17
s:play()
18
19
function   waitForChild(parent, childName)
20
	local child = parent:findFirstChild(childName)
21
	if child then return child end
22
	while true do
23
		child = parent.ChildAdded:wait()
24
		if child.Name==childName then return child end
25
	end
26
end
27
28
local Figure = script.Parent
29
local Torso = waitForChild(Figure, "Torso")
30
local RightShoulder = waitForChild(Torso, "Right Shoulder")
31
local LeftShoulder = waitForChild(Torso, "Left Shoulder")
32
local RightHip = waitForChild(Torso, "Right Hip")
33
local LeftHip = waitForChild(Torso, "Left Hip")
34
local Neck = waitForChild(Torso, "Neck")
35
local Humanoid = waitForChild(Figure, "Humanoid")
36
local pose = "Standing"
37
38
local currentAnim = ""
39
local currentAnimTrack = nil
40
local currentAnimKeyframeHandler = nil
41
local currentAnimSpeed = 1.0
42
local oldAnimTrack = nil
43
local animTable = {}
44
local animNames = { 
45
	idle = 	{	
46
				{ id = "rbxassetid://125750544", weight = 9 },
47
				{ id = "rbxassetid://125750618", weight = 1 }
48
			},
49
	walk = 	{ 	
50
				{ id = "rbxassetid://125749145", weight = 10 } 
51
			}, 
52
	run = 	{
53
				{ id = "run.xml", weight = 10 } 
54
			}, 
55
	jump = 	{
56
				{ id = "rbxassetid://125750702", weight = 10 } 
57
			}, 
58
	fall = 	{
59
				{ id = "rbxassetid://125750759", weight = 10 } 
60
			}, 
61
	climb = {
62
				{ id = "rbxassetid://125750800", weight = 10 } 
63
			}, 
64
	toolnone = {
65
				{ id = "rbxassetid://125750867", weight = 10 } 
66
			},
67
	toolslash = {
68
				{ id = "rbxassetid://129967390", weight = 10 } 
69
--				{ id = "slash.xml", weight = 10 } 
70
			},
71
	toollunge = {
72
				{ id = "rbxassetid://129967478", weight = 10 } 
73
			},
74
	wave = {
75
				{ id = "rbxassetid://128777973", weight = 10 } 
76
			},
77
	point = {
78
				{ id = "rbxassetid://128853357", weight = 10 } 
79
			},
80
	dance = {
81
				{ id = "rbxassetid://130018893", weight = 10 }, 
82
				{ id = "rbxassetid://132546839", weight = 10 }, 
83
				{ id = "rbxassetid://132546884", weight = 10 } 
84
			},
85
	laugh = {
86
				{ id = "rbxassetid://129423131", weight = 10 } 
87
			},
88
	cheer = {
89
				{ id = "rbxassetid://=129423030", weight = 10 } 
90
			},
91
}
92
93
-- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
94
local emoteNames = { wave = false, point = false, dance = true, laugh = false, cheer = false}
95
96
math.randomseed(tick())
97
98
-- Setup animation objects
99
for name, fileList in pairs(animNames) do 
100
	animTable[name] = {}
101
	animTable[name].count = 0
102
	animTable[name].totalWeight = 0
103
104
	-- check for config values
105
	local config = script:FindFirstChild(name)
106
	if (config ~= nil) then
107
--		print("Loading anims " .. name)
108
		local idx = 1
109
		for _, childPart in pairs(config:GetChildren()) do
110
			animTable[name][idx] = {}
111
			animTable[name][idx].anim = childPart
112
			local weightObject = childPart:FindFirstChild("Weight")
113
			if (weightObject == nil) then
114
				animTable[name][idx].weight = 1
115
			else
116
				animTable[name][idx].weight = weightObject.Value
117
			end
118
			animTable[name].count = animTable[name].count + 1
119
			animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
120
--			print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
121
			idx = idx + 1
122
		end
123
	end
124
125
	-- fallback to defaults
126
	if (animTable[name].count <= 0) then
127
		for idx, anim in pairs(fileList) do
128
			animTable[name][idx] = {}
129
			animTable[name][idx].anim = Instance.new("Animation")
130
			animTable[name][idx].anim.Name = name
131
			animTable[name][idx].anim.AnimationId = anim.id
132
			animTable[name][idx].weight = anim.weight
133
			animTable[name].count = animTable[name].count + 1
134
			animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
135
--			print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
136
		end
137
	end
138
end
139
140
-- ANIMATION
141
142
-- declarations
143
local toolAnim = "None"
144
local toolAnimTime = 0
145
146
local jumpAnimTime = 0
147
local jumpAnimDuration = 0.175
148
149
local toolTransitionTime = 0.1
150
local fallTransitionTime = 0.2
151
local jumpMaxLimbVelocity = 0.75
152
153
-- functions
154
155
function stopAllAnimations()
156
	local oldAnim = currentAnim
157
158
	-- return to idle if finishing an emote
159
	if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
160
		oldAnim = "idle"
161
	end
162
163
	currentAnim = ""
164
	if (currentAnimKeyframeHandler ~= nil) then
165
		currentAnimKeyframeHandler:disconnect()
166
	end
167
168
	if (oldAnimTrack ~= nil) then
169
		oldAnimTrack:Stop()
170
		oldAnimTrack:Destroy()
171
		oldAnimTrack = nil
172
	end
173
	if (currentAnimTrack ~= nil) then
174
		currentAnimTrack:Stop()
175
		currentAnimTrack:Destroy()
176
		currentAnimTrack = nil
177
	end
178
	return oldAnim
179
end
180
181
function setAnimationSpeed(speed)
182
	if speed ~= currentAnimSpeed then
183
		currentAnimSpeed = speed
184
		currentAnimTrack:AdjustSpeed(currentAnimSpeed)
185
	end
186
end
187
188
function keyFrameReachedFunc(frameName)
189
	if (frameName == "End") then
190
--		print("Keyframe : ".. frameName)
191
		local repeatAnim = stopAllAnimations()
192
		local animSpeed = currentAnimSpeed
193
		playAnimation(repeatAnim, 0.0, Humanoid)
194
		setAnimationSpeed(animSpeed)
195
	end
196
end
197
198
-- Preload animations
199
function playAnimation(animName, transitionTime, humanoid)
200
	if (animName ~= currentAnim) then		 
201
		
202
		if (oldAnimTrack ~= nil) then
203
			oldAnimTrack:Stop()
204
			oldAnimTrack:Destroy()
205
		end
206
207
		currentAnimSpeed = 1.0
208
		local roll = math.random(1, animTable[animName].totalWeight) 
209
		local origRoll = roll
210
		local idx = 1
211
		while (roll > animTable[animName][idx].weight) do
212
			roll = roll - animTable[animName][idx].weight
213
			idx = idx + 1
214
		end
215
--		print(animName .. " " .. idx .. " [" .. origRoll .. "]")
216
		local anim = animTable[animName][idx].anim
217
218
		-- load it to the humanoid; get AnimationTrack
219
		oldAnimTrack = currentAnimTrack
220
		currentAnimTrack = humanoid:LoadAnimation(anim)
221
		 
222
		-- play the animation
223
		currentAnimTrack:Play(transitionTime)
224
		currentAnim = animName
225
226
		-- set up keyframe name triggers
227
		if (currentAnimKeyframeHandler ~= nil) then
228
			currentAnimKeyframeHandler:disconnect()
229
		end
230
		currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
231
	end
232
end
233
234
-------------------------------------------------------------------------------------------
235
-------------------------------------------------------------------------------------------
236
237
local toolAnimName = ""
238
local toolOldAnimTrack = nil
239
local toolAnimTrack = nil
240
local currentToolAnimKeyframeHandler = nil
241
242
function toolKeyFrameReachedFunc(frameName)
243
	if (frameName == "End") then
244
--		print("Keyframe : ".. frameName)
245
		local repeatAnim = stopToolAnimations()
246
		playToolAnimation(repeatAnim, 0.0, Humanoid)
247
	end
248
end
249
250
251
function playToolAnimation(animName, transitionTime, humanoid)
252
	if (animName ~= toolAnimName) then		 
253
		
254
		if (toolAnimTrack ~= nil) then
255
			toolAnimTrack:Stop()
256
			toolAnimTrack:Destroy()
257
			transitionTime = 0
258
		end
259
260
		local roll = math.random(1, animTable[animName].totalWeight) 
261
		local origRoll = roll
262
		local idx = 1
263
		while (roll > animTable[animName][idx].weight) do
264
			roll = roll - animTable[animName][idx].weight
265
			idx = idx + 1
266
		end
267
--		print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
268
		local anim = animTable[animName][idx].anim
269
270
		-- load it to the humanoid; get AnimationTrack
271
		toolOldAnimTrack = toolAnimTrack
272
		toolAnimTrack = humanoid:LoadAnimation(anim)
273
		 
274
		-- play the animation
275
		toolAnimTrack:Play(transitionTime)
276
		toolAnimName = animName
277
278
		currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
279
	end
280
end
281
282
function stopToolAnimations()
283
	local oldAnim = toolAnimName
284
285
	if (currentToolAnimKeyframeHandler ~= nil) then
286
		currentToolAnimKeyframeHandler:disconnect()
287
	end
288
289
	toolAnimName = ""
290
	if (toolAnimTrack ~= nil) then
291
		toolAnimTrack:Stop()
292
		toolAnimTrack:Destroy()
293
		toolAnimTrack = nil
294
	end
295
296
297
	return oldAnim
298
end
299
300
-------------------------------------------------------------------------------------------
301
-------------------------------------------------------------------------------------------
302
303
304
function onRunning(speed)
305
	if speed>0 then
306
		playAnimation("walk", 0.1, Humanoid)
307
		pose = "Running"
308
	else
309
		playAnimation("idle", 0.1, Humanoid)
310
		pose = "Standing"
311
	end
312
end
313
314
function onDied()
315
	pose = "Dead"
316
end
317
318
function onJumping()
319
	playAnimation("jump", 0.1, Humanoid)
320
	jumpAnimTime = jumpAnimDuration
321
	pose = "Jumping"
322
end
323
324
function onClimbing(speed)
325
	playAnimation("climb", 0.1, Humanoid)
326
	setAnimationSpeed(speed / 12.0)
327
	pose = "Climbing"
328
end
329
330
function onGettingUp()
331
	pose = "GettingUp"
332
end
333
334
function onFreeFall()
335
	if (jumpAnimTime <= 0) then
336
		playAnimation("fall", fallTransitionTime, Humanoid)
337
	end
338
	pose = "FreeFall"
339
end
340
341
function onFallingDown()
342
	pose = "FallingDown"
343
end
344
345
function onSeated()
346
	pose = "Seated"
347
end
348
349
function onPlatformStanding()
350
	pose = "PlatformStanding"
351
end
352
353
function onSwimming(speed)
354
	if speed>0 then
355
		pose = "Running"
356
	else
357
		pose = "Standing"
358
	end
359
end
360
361
function getTool()	
362
	for _, kid in ipairs(Figure:GetChildren()) do
363
		if kid.className == "Tool" then return kid end
364
	end
365
	return nil
366
end
367
368
function getToolAnim(tool)
369
	for _, c in ipairs(tool:GetChildren()) do
370
		if c.Name == "toolanim" and c.className == "StringValue" then
371
			return c
372
		end
373
	end
374
	return nil
375
end
376
377
function animateTool()
378
	
379
	if (toolAnim == "None") then
380
		playToolAnimation("toolnone", toolTransitionTime, Humanoid)
381
		return
382
	end
383
384
	if (toolAnim == "Slash") then
385
		playToolAnimation("toolslash", 0, Humanoid)
386
		return
387
	end
388
389
	if (toolAnim == "Lunge") then
390
		playToolAnimation("toollunge", 0, Humanoid)
391
		return
392
	end
393
end
394
395
function moveSit()
396
	RightShoulder.MaxVelocity = 0.15
397
	LeftShoulder.MaxVelocity = 0.15
398
	RightShoulder:SetDesiredAngle(3.14 /2)
399
	LeftShoulder:SetDesiredAngle(-3.14 /2)
400
	RightHip:SetDesiredAngle(3.14 /2)
401
	LeftHip:SetDesiredAngle(-3.14 /2)
402
end
403
404
local lastTick = 0
405
406
function move(time)
407
	local amplitude = 1
408
	local frequency = 1
409
  	local deltaTime = time - lastTick
410
  	lastTick = time
411
412
	local climbFudge = 0
413
	local setAngles = false
414
415
  	if (jumpAnimTime > 0) then
416
  		jumpAnimTime = jumpAnimTime - deltaTime
417
  	end
418
419
	if (pose == "FreeFall" and jumpAnimTime <= 0) then
420
		playAnimation("fall", fallTransitionTime, Humanoid)
421
	elseif (pose == "Seated") then
422
		stopAllAnimations()
423
		moveSit()
424
		return
425
	elseif (pose == "Running") then
426
		playAnimation("walk", 0.1, Humanoid)
427
	elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
428
--		print("Wha " .. pose)
429
		amplitude = 0.1
430
		frequency = 1
431
		setAngles = true
432
	end
433
434
	if (setAngles) then
435
		desiredAngle = amplitude * math.sin(time * frequency)
436
437
		RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
438
		LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
439
		RightHip:SetDesiredAngle(-desiredAngle)
440
		LeftHip:SetDesiredAngle(-desiredAngle)
441
	end
442
443
	-- Tool Animation handling
444
	local tool = getTool()
445
	if tool then
446
	
447
		animStringValueObject = getToolAnim(tool)
448
449
		if animStringValueObject then
450
			toolAnim = animStringValueObject.Value
451
			-- message recieved, delete StringValue
452
			animStringValueObject.Parent = nil
453
			toolAnimTime = time + .3
454
		end
455
456
		if time > toolAnimTime then
457
			toolAnimTime = 0
458
			toolAnim = "None"
459
		end
460
461
		animateTool()		
462
	else
463
		stopToolAnimations()
464
		toolAnim = "None"
465
		toolAnimTime = 0
466
	end
467
end
468
469
-- connect events
470
Humanoid.Died:connect(onDied)
471
Humanoid.Running:connect(onRunning)
472
Humanoid.Jumping:connect(onJumping)
473
Humanoid.Climbing:connect(onClimbing)
474
Humanoid.GettingUp:connect(onGettingUp)
475
Humanoid.FreeFalling:connect(onFreeFall)
476
Humanoid.FallingDown:connect(onFallingDown)
477
Humanoid.Seated:connect(onSeated)
478
Humanoid.PlatformStanding:connect(onPlatformStanding)
479
Humanoid.Swimming:connect(onSwimming)
480
481
-- setup emote chat hook
482-
Game.Players.LocalPlayer.Chatted:connect(function(msg)
482+
Game.Players.contentdeleted93726.Chatted:connect(function(msg)
483
	local emote = ""
484
	if (string.sub(msg, 1, 3) == "/e ") then
485
		emote = string.sub(msg, 4)
486
	elseif (string.sub(msg, 1, 7) == "/emote ") then
487
		emote = string.sub(msg, 8)
488
	end
489
	
490
	if (pose == "Standing" and emoteNames[emote] ~= nil) then
491
		playAnimation(emote, 0.1, Humanoid)
492
	end
493
--	print("===> " .. string.sub(msg, 1, 3) .. "(" .. emote .. ")")
494
end)
495
496
497
-- main program
498
499
local runService = game:service("RunService");
500
501
-- initialize to idle
502
playAnimation("idle", 0.1, Humanoid)
503
pose = "Standing"
504
505
while Figure.Parent~=nil do
506
	local _, time = wait(0.1)
507
	move(time)
508
end