-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
83 lines (67 loc) · 1.99 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
repeat task.wait() until Players.LocalPlayer
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
LocalPlayer.CharacterAdded:Connect(function(Character)
Character = Character
Humanoid = Character:WaitForChild("Humanoid")
end)
local AnimSocket = {}
function AnimSocket.Connect(Channel)
local Socket = {
Send = function(self, Message)
local Payload = string.format("rbxassetid://%s\255%s\255%s", math.floor(os.clock() * 10000), Channel, Message)
local Animation = Instance.new("Animation")
Animation.AnimationId = Payload
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
AnimationTrack:Stop()
end,
Close = function(self)
self.OnClose()
end,
OnMessage = {
Connections = {},
Connect = function(self, f)
table.insert(self.Connections, f)
end,
Fire = function(self, ...)
for _, f in pairs(self.Connections) do
f(...)
end
end
},
OnClose = function() end
}
local Complete = {}
RunService.RenderStepped:Connect(function()
for _, Player in pairs(Players:GetPlayers()) do
pcall(function()
local Character = Player.Character
local Humanoid = Character and Character:FindFirstChildOfClass("Humanoid")
for _, Animation in pairs(Humanoid:GetPlayingAnimationTracks()) do
local Data = string.sub(Animation.Animation.AnimationId, 14, -1)
Data = string.split(Data, "\255")
if not Complete[Data[1]] then
Complete[Data[1]] = true
if Data[2] == Channel then
local Source, Error = pcall(function()
for i = 1, 2 do
table.remove(Data, 1)
end
Socket.OnMessage:Fire(Player, table.concat(Data, "\255"))
end)
if not Source then
warn(Error)
end
end
end
end
end)
end
end)
return Socket
end
return AnimSocket