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