View difference between Paste ID: e8hAn90h and MYjwe7Ug
SHOW: | | - or go back to the newest paste.
1
wait(5)
2
3
--NOTE: This version uses a hack to create a second part for shirt textures
4
--                Mesh behavior may change to where this hack will become un-needed
5
--                Let me know if you want me to create a toggle for this
6
7
Player = game.Players.localPlayer
8
9
10
local function CharacterAdded(Character)
11
                if Character then
12
                        
13
                        local R15Model = Instance.new("Model")
14
                        R15Model.Name = "R15Model"
15
                        R15Model.Parent = Character
16
                        
17
                        local function CreateLimb(Name,Color,Size,Transparency,ConnectToLimb,MotorName,C0,C1,MeshId)
18
                                local Part = Instance.new("Part")
19
                                Part.FormFactor = "Custom"
20
                                Part.Size = Size
21
                                Part.BrickColor = Color
22
                                Part.CanCollide = false
23
                                Part.Name = Name
24
                                Part.Transparency = (Transparency == 0.001 and 0 or Transparency)
25
                                Part.TopSurface = "Smooth"
26
                                Part.BottomSurface = "Smooth"
27
                                
28
                                local Motor = Instance.new("Motor6D")
29
                                Motor.C0 = C0
30
                                Motor.C1 = C1
31
                                Motor.Part0 = ConnectToLimb
32
                                Motor.Part1 = Part
33
                                Motor.Name = MotorName
34
                                Motor.MaxVelocity = 0.1
35
                                Motor.Parent = ConnectToLimb
36
                                
37
                                if MeshId then
38
                                        local Mesh = Instance.new("SpecialMesh")
39
                                        Mesh.MeshType = "FileMesh"
40
                                        Mesh.MeshId = MeshId
41
                                        Mesh.Scale = Vector3.new(0.99,0.99,0.99)
42
                                        Mesh.Parent = Part
43
                                end
44
                                
45
                                if MeshId and Transparency == 0.001 then
46
                                        local ShirtTexturePart = Instance.new("Part")
47
                                        ShirtTexturePart.FormFactor = "Custom"
48
                                        ShirtTexturePart.Size = Size
49
                                        ShirtTexturePart.BrickColor = Color
50
                                        ShirtTexturePart.CanCollide = false
51
                                        ShirtTexturePart.Name = "ShirtTexturePart"
52
                                        ShirtTexturePart.Transparency = Transparency
53
                                        ShirtTexturePart.TopSurface = "Smooth"
54
                                        ShirtTexturePart.BottomSurface = "Smooth"
55
                                        
56
                                        local Mesh = Instance.new("SpecialMesh")
57
                                        Mesh.MeshType = "FileMesh"
58
                                        Mesh.MeshId = MeshId
59
                                        Mesh.Parent = ShirtTexturePart
60
                                        
61
                                        local Weld = Instance.new("Weld")
62
                                        Weld.Part0 = Part
63
                                        Weld.Part1 = ShirtTexturePart
64
                                        Weld.Parent = ShirtTexturePart
65
                                        
66
                                        ShirtTexturePart.Parent = Part
67
                                end
68
                                Part.Parent = R15Model
69
                                return Part
70
                        end
71
                        
72
                        local HumanoidRootPart = CreateLimb("HumanoidRootPart",BrickColor.new("Medium stone grey"),Vector3.new(1,1,1),1,Character.HumanoidRootPart,"RootConnector",CFrame.new(),CFrame.new(0,0.7,0))
73
                        local TorsoLower = CreateLimb("TorsoLower",BrickColor.new("Bright blue"),Vector3.new(0.5,0.5,0.5),0.001,HumanoidRootPart,"Root",CFrame.new(0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, -1),CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366190286")
74
                        local TorsoUpper = CreateLimb("TorsoUpper",BrickColor.new("Bright blue"),Vector3.new(0.2,0.74,0.2),0.001,TorsoLower,"Waist",CFrame.new(0, 0.739968002, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, -0.369984001, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366190087")
75
                        local Head = CreateLimb("FakeHead",BrickColor.new("Bright yellow"),Vector3.new(1,1,1),0,TorsoUpper,"Neck",CFrame.new(0, 0.566236973, -0.0666489974, 1, 0, 0, 0, 0.993143976, 0.116898, 0, -0.116898, 0.993143976),CFrame.new(0, -0.285073012, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366190426")
76
                        local LeftArmUpper = CreateLimb("LeftArmUpper",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.536,0.2),0.001,TorsoUpper,"LeftShoulder",CFrame.new(1.50177097, 0.220340997, 0, 0, -0.999044001, -0.0437170006, -1, 0, 0, 0, 0.0437170006, -0.999044001),CFrame.new(0, 0.336115986, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366186808")
77
                        local LeftArmLower = CreateLimb("LeftArmLower",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.739,0.2),0.001,LeftArmUpper,"LeftElbow",CFrame.new(0, -0.267791986, 0, 1, 0, 0, 0, 0.998493016, -0.0548710003, 0, 0.0548710003, 0.998493016),CFrame.new(0, 0.369605988, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366187079")
78
                        local LeftHand = CreateLimb("LeftHand",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.37,0.2),0.001,LeftArmLower,"LeftWrist",CFrame.new(0, -0.369605988, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1),CFrame.new(0, -0.184802994, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366187331")
79
                        local RightArmUpper = CreateLimb("RightArmUpper",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.536,0.2),0.001,TorsoUpper,"RightShoulder",CFrame.new(-1.50049305, 0.219521001, 0, 0, 0.999041975, -0.0437709987, -1, 0, 0, 0, 0.0437709987, 0.999041975),CFrame.new(0, 0.335705996, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366188623")
80
                        local RightArmLower = CreateLimb("RightArmLower",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.739,0.2),0.001,RightArmUpper,"RightElbow",CFrame.new(0, -0.296110988, 0, 1, 0, 0, 0, 0.998767972, 0.0496239997, 0, -0.0496239997, 0.998767972),CFrame.new(0, 0.337754011, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366188798")
81
                        local RightHand = CreateLimb("RightHand",BrickColor.new("Bright yellow"),Vector3.new(),0.001,RightArmLower,"RightWrist",CFrame.new(0, -0.337754011, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1),CFrame.new(0, -0.168877006, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366189081")
82
                        local LeftLegUpper = CreateLimb("LeftLegUpper",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.784,0.2),0.001,TorsoLower,"LeftHip",CFrame.new(0.457044005, -0.495086014, 0, 1, 0, 0, 0, 1, -0.000100999998, 0, 0.000100999998, 1),CFrame.new(0, 0.388933986, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366187724")
83
                        local LeftLegLower = CreateLimb("LeftLegLower",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.803,0.2),0.001,LeftLegUpper,"LeftKnee",CFrame.new(0, -0.388933986, 0, 1, 9.99999997e-007, 0, -9.99999997e-007, 0.991840005, -0.127486005, 0, 0.127486005, 0.991840005),CFrame.new(0, 0.401580006, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366188102")
84
                        local LeftFoot = CreateLimb("LeftFoot",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.402,0.2),0.001,LeftLegLower,"LeftAnkle",CFrame.new(0, -0.401578993, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1),CFrame.new(0, -0.200790003, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366188387")
85
                        local RightLegUpper = CreateLimb("RightLegUpper",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.784,0.2),0.001,TorsoLower,"RightHip",CFrame.new(-0.451141, -0.498115987, 0, 1, 0, 0, 0, 0.999954998, 0.0095180003, 0, -0.0095180003, 0.999954998),CFrame.new(0, 0.391921997, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366189770")
86
                        local RightLegLower = CreateLimb("RightLegLower",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.796,0.2),0.001,RightLegUpper,"RightKnee",CFrame.new(0, -0.391921997, 0, 1, 0, 0, 0, 0.992762029, -0.120096996, 0, 0.120096996, 0.992762029),CFrame.new(0, 0.39814499, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366189509")
87
                        local RightFoot = CreateLimb("RightFoot",BrickColor.new("Br. yellowish green"),Vector3.new(0.2, 0.398, 0.2),0.001,RightLegLower,"RightAnkle",CFrame.new(0, -0.39814499, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1),CFrame.new(0, -0.199073002, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366189977")
88
                        
89
                        --if Character:WaitForChild("Head"):WaitForChild("Mesh").MeshId ~= "" then
90
                        --        Head.MeshId = Character.Head.Mesh.MeshId
91
                        --end
92
                        
93
                        spawn(function() Character:WaitForChild("Animate").Disabled = false end)
94
                        
95
                        
96
                        local function Clear(Name,Alternative,ColorParts)
97
                                local Part = Character:WaitForChild(Name)
98
                                Part.Transparency = (Name == "Head" and 0.99 or 1)
99
                                local function ChildAdded(Ins)
100
                                        delay(0.05,function()
101
                                                if Ins.Name == "face" then
102
                                                        if Alternative:FindFirstChild("face") then Alternative:FindFirstChild("face"):Destroy() end
103
                                                        Ins.Parent = Alternative
104
                                                elseif Ins:IsA("Motor6D") and string.sub(Ins.Name,1,5) ~= "Fake_" then
105
                                                        Ins.Name = "Fake_"..Ins.Name
106
                                                elseif Ins.Name == "HeadWeld" then
107
                                                        delay(0.05,function()
108
                                                                Ins.Parent = Head
109
                                                                Ins.Part0 = Head
110
                                                                Ins.C1 = CFrame.new(0,-0.15,0.125) * Ins.C1 * CFrame.Angles(0,math.pi,0)
111
                                                        end)
112
                                                elseif not Ins:IsA("Weld") then
113
                                                        Ins:Destroy()
114
                                                end
115
                                        end)
116
                                end
117
                                for _,Sub in pairs(Part:GetChildren()) do
118
                                        ChildAdded(Sub)
119
                                end
120
                                Part.ChildAdded:connect(ChildAdded)
121
                                
122
                                local function Color()
123
                                        for _,Sub in pairs(ColorParts) do
124
                                                Sub.BrickColor = Part.BrickColor
125
                                                local TexturePart = Sub:FindFirstChild("ShirtTexturePart")
126
                                                if TexturePart then
127
                                                        TexturePart.BrickColor = Part.BrickColor
128
                                                end
129
                                        end
130
                                end
131
                                Color()
132
                                Part.Changed:connect(Color)
133
                        end
134
                        
135
                        Clear("HumanoidRootPart",HumanoidRootPart,{HumanoidRootPart})
136
                        Clear("Head",Head,{Head})
137
                        Clear("Torso",nil,{TorsoLower,TorsoUpper})
138
                        Clear("Left Arm",nil,{LeftArmLower,LeftArmUpper,LeftHand})
139
                        Clear("Right Arm",nil,{RightArmLower,RightArmUpper,RightHand})
140
                        Clear("Left Leg",nil,{LeftLegLower,LeftLegUpper,LeftFoot})
141
                        Clear("Right Leg",nil,{RightLegLower,RightLegUpper,RightFoot})
142
                        
143
                        local ShirtUsed = false
144
                        local function ChildAdded(Ins)
145
                                if Ins:IsA("Hat") and string.sub(Ins.Name,1,7) ~= "Scaled_" then
146
                                        delay(0.05,function()
147
                                                local Mesh = Ins:WaitForChild("Handle"):WaitForChild("Mesh")
148
                                                Ins.AttachmentPos = Ins.AttachmentPos 
149
                                                Mesh.Scale = Mesh.Scale
150
                                                Ins.Name = "Scaled_"..Ins.Name
151
                                        end)
152
                                elseif Ins:IsA("Shirt") then
153
                                        ShirtUsed = true
154
                                        TorsoLower.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
155
                                        TorsoUpper.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
156
                                        LeftArmLower.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
157
                                        LeftArmUpper.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
158
                                        LeftHand.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
159
                                        RightArmLower.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
160
                                        RightArmUpper.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
161
                                        RightHand.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
162
                                elseif Ins:IsA("Pants") then
163
                                        LeftLegUpper.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
164
                                        LeftLegLower.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
165
                                        LeftFoot.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
166
                                        RightLegUpper.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
167
                                        RightLegLower.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
168
                                        RightFoot.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
169
                                        if ShirtUsed ~= true then
170
                                                TorsoLower.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
171
                                                TorsoUpper.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
172
                                        end
173
                                end
174
                        end
175
                        
176
                        for _,Sub in pairs(Character:GetChildren()) do
177
                                ChildAdded(Sub)
178
                        end
179
                        Character.ChildAdded:connect(ChildAdded)
180
                end
181
        end
182
        
183
        CharacterAdded(Player.Character)
184
        Player.CharacterAdded:connect(CharacterAdded)
185
186
script.Parent = game.Players.LocalPlayer.Character
187
function   waitForChild(parent, childName)
188
        local child = parent:findFirstChild(childName)
189
        if child then return child end
190
        while true do
191
                child = parent.ChildAdded:wait()
192
                if child.Name==childName then return child end
193
        end
194
end
195
196
local Figure = script.Parent
197
local Humanoid = waitForChild(Figure, "Humanoid")
198
local pose = "Standing"
199
200
local currentAnim = ""
201
local currentAnimInstance = nil
202
local currentAnimTrack = nil
203
local currentAnimKeyframeHandler = nil
204
local currentAnimSpeed = 1.0
205
local animTable = {}
206
local animNames = { 
207
        idle =         {        
208
                                { id = "http://www.roblox.com/asset/?id=361250879", weight = 1 },
209
                                { id = "http://www.roblox.com/asset/?id=361250964", weight = 1 },
210
                                { id = "http://www.roblox.com/asset/?id=361250801", weight = 9 }
211
                        },
212
        walk =         {         
213
                                { id = "http://www.roblox.com/asset/?id=361250532", weight = 10 } 
214
                        }, 
215
        run =         {
216
                                { id = "http://www.roblox.com/asset/?id=361250532", weight = 10 } 
217
                        }, 
218
        jump =         {
219
                                { id = "http://www.roblox.com/asset/?id=361251250", weight = 10 } 
220
                        }, 
221
        fall =         {
222
                                { id = "http://www.roblox.com/asset/?id=361259102", weight = 10 } 
223
                        }, 
224
        climb = {
225
                                { id = "http://www.roblox.com/asset/?id=361251073", weight = 10 } 
226
                        }, 
227
        sit =         {
228
                                { id = "http://www.roblox.com/asset/?id=178130996", weight = 10 } 
229
                        },        
230
        toolnone = {
231
                                { id = "http://www.roblox.com/asset/?id=182393478", weight = 10 } 
232
                        },
233
        toolslash = {
234
                                { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 } 
235
--                                { id = "slash.xml", weight = 10 } 
236
                        },
237
        toollunge = {
238
                                { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 } 
239
                        },
240
        wave = {
241
                                { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 } 
242
                        },
243
        point = {
244
                                { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 } 
245
                        },
246
        dance = {
247
                                { id = "http://www.roblox.com/asset/?id=182435998", weight = 10 }, 
248
                                { id = "http://www.roblox.com/asset/?id=182491037", weight = 10 }, 
249
                                { id = "http://www.roblox.com/asset/?id=182491065", weight = 10 } 
250
                        },
251
        dance2 = {
252
                                { id = "http://www.roblox.com/asset/?id=182436842", weight = 10 }, 
253
                                { id = "http://www.roblox.com/asset/?id=182491248", weight = 10 }, 
254
                                { id = "http://www.roblox.com/asset/?id=182491277", weight = 10 } 
255
                        },
256
        dance3 = {
257
                                { id = "http://www.roblox.com/asset/?id=182436935", weight = 10 }, 
258
                                { id = "http://www.roblox.com/asset/?id=182491368", weight = 10 }, 
259
                                { id = "http://www.roblox.com/asset/?id=182491423", weight = 10 } 
260
                        },
261
        laugh = {
262
                                { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 } 
263
                        },
264
        cheer = {
265
                                { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 } 
266
                        },
267
}
268
269
-- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
270
local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
271
272
math.randomseed(tick())
273
274
function configureAnimationSet(name, fileList)
275
        if (animTable[name] ~= nil) then
276
                for _, connection in pairs(animTable[name].connections) do
277
                        connection:disconnect()
278
                end
279
        end
280
        animTable[name] = {}
281
        animTable[name].count = 0
282
        animTable[name].totalWeight = 0        
283
        animTable[name].connections = {}
284
285
        -- check for config values
286
        local config = script:FindFirstChild(name)
287
        if (config ~= nil) then
288
--                print("Loading anims " .. name)
289
                table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
290
                table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
291
                local idx = 1
292
                for _, childPart in pairs(config:GetChildren()) do
293
                        if (childPart:IsA("Animation")) then
294
                                table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
295
                                animTable[name][idx] = {}
296
                                animTable[name][idx].anim = childPart
297
                                local weightObject = childPart:FindFirstChild("Weight")
298
                                if (weightObject == nil) then
299
                                        animTable[name][idx].weight = 1
300
                                else
301
                                        animTable[name][idx].weight = weightObject.Value
302
                                end
303
                                animTable[name].count = animTable[name].count + 1
304
                                animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
305
        --                        print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
306
                                idx = idx + 1
307
                        end
308
                end
309
        end
310
311
        -- fallback to defaults
312
        if (animTable[name].count <= 0) then
313
                for idx, anim in pairs(fileList) do
314
                        animTable[name][idx] = {}
315
                        animTable[name][idx].anim = Instance.new("Animation")
316
                        animTable[name][idx].anim.Name = name
317
                        animTable[name][idx].anim.AnimationId = anim.id
318
                        animTable[name][idx].weight = anim.weight
319
                        animTable[name].count = animTable[name].count + 1
320
                        animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
321
--                        print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
322
                end
323
        end
324
end
325
326
-- Setup animation objects
327
function scriptChildModified(child)
328
        local fileList = animNames[child.Name]
329
        if (fileList ~= nil) then
330
                configureAnimationSet(child.Name, fileList)
331
        end        
332
end
333
334
script.ChildAdded:connect(scriptChildModified)
335
script.ChildRemoved:connect(scriptChildModified)
336
337
338
for name, fileList in pairs(animNames) do 
339
        configureAnimationSet(name, fileList)
340
end        
341
342
-- ANIMATION
343
344
-- declarations
345
local toolAnim = "None"
346
local toolAnimTime = 0
347
348
local jumpAnimTime = 0
349
local jumpAnimDuration = 0.3
350
351
local toolTransitionTime = 0.1
352
local fallTransitionTime = 0.0
353
354
-- functions
355
356
function stopAllAnimations()
357
        local oldAnim = currentAnim
358
359
        -- return to idle if finishing an emote
360
        if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
361
                oldAnim = "idle"
362
        end
363
364
        currentAnim = ""
365
        currentAnimInstance = nil
366
        if (currentAnimKeyframeHandler ~= nil) then
367
                currentAnimKeyframeHandler:disconnect()
368
        end
369
370
        if (currentAnimTrack ~= nil) then
371
                currentAnimTrack:Stop()
372
                currentAnimTrack:Destroy()
373
                currentAnimTrack = nil
374
        end
375
        return oldAnim
376
end
377
378
function setAnimationSpeed(speed)
379
        if speed ~= currentAnimSpeed then
380
                currentAnimSpeed = speed
381
                currentAnimTrack:AdjustSpeed(currentAnimSpeed)
382
        end
383
end
384
385
function keyFrameReachedFunc(frameName)
386
        if (frameName == "End") then
387
--                print("Keyframe : ".. frameName)
388
389
                local repeatAnim = currentAnim
390
                -- return to idle if finishing an emote
391
                if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
392
                        repeatAnim = "idle"
393
                end
394
                
395
                local animSpeed = currentAnimSpeed
396
                playAnimation(repeatAnim, 0.05, Humanoid)
397
                setAnimationSpeed(animSpeed)
398
        end
399
end
400
401
-- Preload animations
402
function playAnimation(animName, transitionTime, humanoid) 
403
                
404
        local roll = math.random(1, animTable[animName].totalWeight) 
405
        local origRoll = roll
406
        local idx = 1
407
        while (roll > animTable[animName][idx].weight) do
408
                roll = roll - animTable[animName][idx].weight
409
                idx = idx + 1
410
        end
411
        
412
--        print(animName .. " " .. idx .. " [" .. origRoll .. "]")
413
        
414
        local anim = animTable[animName][idx].anim
415
416
        -- switch animation                
417
        if (anim ~= currentAnimInstance) then
418
                
419
                if (currentAnimTrack ~= nil) then
420
                        currentAnimTrack:Stop(transitionTime)
421
                        currentAnimTrack:Destroy()
422
                end
423
424
                currentAnimSpeed = 1.0
425
        
426
                -- load it to the humanoid; get AnimationTrack
427
                currentAnimTrack = humanoid:LoadAnimation(anim)
428
                 
429
                -- play the animation
430
                currentAnimTrack:Play(transitionTime)
431
                currentAnim = animName
432
                currentAnimInstance = anim
433
434
                -- set up keyframe name triggers
435
                if (currentAnimKeyframeHandler ~= nil) then
436
                        currentAnimKeyframeHandler:disconnect()
437
                end
438
                currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
439
                
440
        end
441
442
end
443
444
-------------------------------------------------------------------------------------------
445
-------------------------------------------------------------------------------------------
446
447
local toolAnimName = ""
448
local toolAnimTrack = nil
449
local toolAnimInstance = nil
450
local currentToolAnimKeyframeHandler = nil
451
452
function toolKeyFrameReachedFunc(frameName)
453
        if (frameName == "End") then
454
--                print("Keyframe : ".. frameName)        
455
                playToolAnimation(toolAnimName, 0.0, Humanoid)
456
        end
457
end
458
459
460
function playToolAnimation(animName, transitionTime, humanoid)         
461
                
462
                local roll = math.random(1, animTable[animName].totalWeight) 
463
                local origRoll = roll
464
                local idx = 1
465
                while (roll > animTable[animName][idx].weight) do
466
                        roll = roll - animTable[animName][idx].weight
467
                        idx = idx + 1
468
                end
469
--                print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
470
                local anim = animTable[animName][idx].anim
471
472
                if (toolAnimInstance ~= anim) then
473
                        
474
                        if (toolAnimTrack ~= nil) then
475
                                toolAnimTrack:Stop()
476
                                toolAnimTrack:Destroy()
477
                                transitionTime = 0
478
                        end
479
                                        
480
                        -- load it to the humanoid; get AnimationTrack
481
                        toolAnimTrack = humanoid:LoadAnimation(anim)
482
                         
483
                        -- play the animation
484
                        toolAnimTrack:Play(transitionTime)
485
                        toolAnimName = animName
486
                        toolAnimInstance = anim
487
488
                        currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
489
                end
490
end
491
492
function stopToolAnimations()
493
        local oldAnim = toolAnimName
494
495
        if (currentToolAnimKeyframeHandler ~= nil) then
496
                currentToolAnimKeyframeHandler:disconnect()
497
        end
498
499
        toolAnimName = ""
500
        toolAnimInstance = nil
501
        if (toolAnimTrack ~= nil) then
502
                toolAnimTrack:Stop()
503
                toolAnimTrack:Destroy()
504
                toolAnimTrack = nil
505
        end
506
507
508
        return oldAnim
509
end
510
511
-------------------------------------------------------------------------------------------
512
-------------------------------------------------------------------------------------------
513
514
515
function onRunning(speed)
516
        if speed > 0.01 then
517
                playAnimation("walk", 0.1, Humanoid)
518
                if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=361250532" then
519
                        setAnimationSpeed(speed / 14.5)
520
                end
521
                pose = "Running"
522
        else
523
                playAnimation("idle", 0.1, Humanoid)
524
                pose = "Standing"
525
        end
526
end
527
528
function onDied()
529
        pose = "Dead"
530
end
531
532
function onJumping()
533
        playAnimation("jump", 0.1, Humanoid)
534
        jumpAnimTime = jumpAnimDuration
535
        pose = "Jumping"
536
end
537
538
function onClimbing(speed)
539
        local scale = 2.0
540
        playAnimation("climb", 0.1, Humanoid)
541
        setAnimationSpeed(speed / scale)
542
        pose = "Climbing"
543
end
544
545
function onGettingUp()
546
        pose = "GettingUp"
547
end
548
549
function onFreeFall()
550
        if (jumpAnimTime <= 0) then
551
                playAnimation("fall", fallTransitionTime, Humanoid)
552
        end
553
        pose = "FreeFall"
554
end
555
556
function onFallingDown()
557
        pose = "FallingDown"
558
end
559
560
function onSeated()
561
        pose = "Seated"
562
end
563
564
function onPlatformStanding()
565
        pose = "PlatformStanding"
566
end
567
568
function onSwimming(speed)
569
        if speed>0 then
570
                pose = "Running"
571
        else
572
                pose = "Standing"
573
        end
574
end
575
576
function getTool()        
577
        for _, kid in ipairs(Figure:GetChildren()) do
578
                if kid.className == "Tool" then return kid end
579
        end
580
        return nil
581
end
582
583
function getToolAnim(tool)
584
        for _, c in ipairs(tool:GetChildren()) do
585
                if c.Name == "toolanim" and c.className == "StringValue" then
586
                        return c
587
                end
588
        end
589
        return nil
590
end
591
592
function animateTool()
593
        
594
        if (toolAnim == "None") then
595
                playToolAnimation("toolnone", toolTransitionTime, Humanoid)
596
                return
597
        end
598
599
        if (toolAnim == "Slash") then
600
                playToolAnimation("toolslash", 0, Humanoid)
601
                return
602
        end
603
604
        if (toolAnim == "Lunge") then
605
                playToolAnimation("toollunge", 0, Humanoid)
606
                return
607
        end
608
end
609
610
function moveSit()
611
        RightShoulder.MaxVelocity = 0.15
612
        LeftShoulder.MaxVelocity = 0.15
613
        RightShoulder:SetDesiredAngle(3.14 /2)
614
        LeftShoulder:SetDesiredAngle(-3.14 /2)
615
        RightHip:SetDesiredAngle(3.14 /2)
616
        LeftHip:SetDesiredAngle(-3.14 /2)
617
end
618
619
local lastTick = 0
620
621
function move(time)
622
        local amplitude = 1
623
        local frequency = 1
624
          local deltaTime = time - lastTick
625
          lastTick = time
626
627
        local climbFudge = 0
628
        local setAngles = false
629
630
          if (jumpAnimTime > 0) then
631
                  jumpAnimTime = jumpAnimTime - deltaTime
632
          end
633
634
        if (pose == "FreeFall" and jumpAnimTime <= 0) then
635
                playAnimation("fall", fallTransitionTime, Humanoid)
636
        elseif (pose == "Seated") then
637
                playAnimation("sit", 0.5, Humanoid)
638
                return
639
        elseif (pose == "Running") then
640
                playAnimation("walk", 0.1, Humanoid)
641
        elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
642
--                print("Wha " .. pose)
643
                stopAllAnimations()
644
                amplitude = 0.1
645
                frequency = 1
646
                setAngles = true
647
        end
648
649
--        if (setAngles) then
650
        if (false) then
651
                desiredAngle = amplitude * math.sin(time * frequency)
652
653
                RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
654
                LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
655
                RightHip:SetDesiredAngle(-desiredAngle)
656
                LeftHip:SetDesiredAngle(-desiredAngle)
657
        end
658
659
        -- Tool Animation handling
660
        local tool = getTool()
661
        if tool then
662
        
663
                animStringValueObject = getToolAnim(tool)
664
665
                if animStringValueObject then
666
                        toolAnim = animStringValueObject.Value
667
                        -- message recieved, delete StringValue
668
                        animStringValueObject.Parent = nil
669
                        toolAnimTime = time + .3
670
                end
671
672
                if time > toolAnimTime then
673
                        toolAnimTime = 0
674
                        toolAnim = "None"
675
                end
676
677
                animateTool()                
678
        else
679
                stopToolAnimations()
680
                toolAnim = "None"
681
                toolAnimInstance = nil
682
                toolAnimTime = 0
683
        end
684
end
685
686
-- connect events
687
Humanoid.Died:connect(onDied)
688
Humanoid.Running:connect(onRunning)
689
Humanoid.Jumping:connect(onJumping)
690
Humanoid.Climbing:connect(onClimbing)
691
Humanoid.GettingUp:connect(onGettingUp)
692
Humanoid.FreeFalling:connect(onFreeFall)
693
Humanoid.FallingDown:connect(onFallingDown)
694
Humanoid.Seated:connect(onSeated)
695
Humanoid.PlatformStanding:connect(onPlatformStanding)
696
Humanoid.Swimming:connect(onSwimming)
697
698
-- setup emote chat hook
699
Game.Players.LocalPlayer.Chatted:connect(function(msg)
700
        local emote = ""
701
        if (string.sub(msg, 1, 3) == "/e ") then
702
                emote = string.sub(msg, 4)
703
        elseif (string.sub(msg, 1, 7) == "/emote ") then
704
                emote = string.sub(msg, 8)
705
        end
706
        
707
        if (pose == "Standing" and emoteNames[emote] ~= nil) then
708
                playAnimation(emote, 0.1, Humanoid)
709
        end
710
--        print("===> " .. string.sub(msg, 1, 3) .. "(" .. emote .. ")")
711
end)
712
713
714
-- main program
715
716
local runService = game:service("RunService");
717
718
-- print("bottom")
719
720
-- initialize to idle
721
playAnimation("idle", 0.1, Humanoid)
722
pose = "Standing"
723
724
while Figure.Parent~=nil do
725
        local _, time = wait(0.1)
726
        move(time)
727
end