Advertisement
KrYn0MoRe

dance animations

Sep 11th, 2022 (edited)
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.56 KB | None | 0 0
  1. -- animator
  2.  
  3. local function init()
  4.     local JointData = {}
  5.     JointData["Right Shoulder"] = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0)
  6.     JointData["Left Shoulder"] = CFrame.new(-1, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  7.     JointData["Right Hip"] = CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0)
  8.     JointData["Left Hip"] = CFrame.new(-1, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  9.     JointData["Neck"] = CFrame.new(0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  10.     JointData["RootJoint"] = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0)
  11.  
  12.     local Animator = {}
  13.     local Playing = {}
  14.     local JointC0 = {}
  15.    
  16.     local GlobalPlaying = _G['GlobalPlaying']
  17.     if not GlobalPlaying then
  18.         _G['GlobalPlaying'] = {}
  19.         GlobalPlaying = _G['GlobalPlaying']
  20.     end
  21.    
  22.     local global_welds = _G['global_welds']
  23.     if not global_welds then
  24.         _G['global_welds'] = {}
  25.         global_welds = _G['global_welds']
  26.     end
  27.  
  28.     local TS = game:GetService("TweenService")
  29.  
  30.     local function Ver(Model)
  31.         if Model and Model.Parent then
  32.             if not GlobalPlaying[Model] then
  33.                 GlobalPlaying[Model] = {}
  34.             end
  35.             if not Playing[Model] then
  36.                 Playing[Model] = {}
  37.                 return true
  38.             end
  39.         end
  40.     end
  41.  
  42.     function Animator.create_welds(targchar)
  43.         if not global_welds[targchar] then else
  44.             return
  45.         end
  46.  
  47.         local anim_welds = {}
  48.         local char_welds = {}
  49.  
  50.         for i,v in ipairs(targchar:GetDescendants()) do
  51.             if v:IsA("Motor6D") or v:IsA("Weld") then
  52.                 if game:GetService("CollectionService"):HasTag(v,'fakemotor') then
  53.                     anim_welds[v] = v.Part0
  54.                 elseif game:GetService("CollectionService"):HasTag(v,'realmotor') then
  55.                     char_welds[v] = v.Part0
  56.                 end
  57.             end
  58.         end
  59.  
  60.         for i,v in ipairs(targchar:GetDescendants()) do
  61.             if v:IsA("Motor6D") and not char_welds[v] then
  62.                 local m = Instance.new("Weld")
  63.                 m.Name = v.Name
  64.                 m.Part0 = v.Part0
  65.                 m.Part1 = v.Part1
  66.                 m.C0 = v.C0
  67.                 m.C1 = v.C1
  68.                 m.Parent = v.Parent
  69.  
  70.                 game:GetService("CollectionService"):AddTag(m,'fakemotor')
  71.                 game:GetService("CollectionService"):AddTag(v,'realmotor')
  72.  
  73.                 anim_welds[m] = v.Part0
  74.                 char_welds[v] = v.Part0
  75.             end
  76.         end
  77.  
  78.         global_welds[targchar] = {
  79.             anim_welds = anim_welds,
  80.             char_welds = char_welds,
  81.             taid = 0,
  82.         }
  83.     end
  84.  
  85.     function Animator.toggle_anim(mode,targchar)
  86.         local welds = global_welds[targchar]
  87.  
  88.         if welds then else
  89.             return
  90.         end
  91.  
  92.         welds.taid += 1
  93.         local cid = welds.taid
  94.  
  95.         local function run()
  96.             if cid == welds.taid then else return end
  97.             if mode then
  98.                 for i,v in pairs(welds.anim_welds) do
  99.                     i.Enabled = true
  100.                 end
  101.                 for i,v in pairs(welds.char_welds) do
  102.                     i.Enabled = false
  103.                 end
  104.             else
  105.                 for i,v in pairs(welds.char_welds) do
  106.                     i.Enabled = true
  107.                 end
  108.                 for i,v in pairs(welds.anim_welds) do
  109.                     i.Enabled = false
  110.                 end
  111.             end
  112.         end
  113.  
  114.         if not mode then
  115.             --task.delay(0.2,run)
  116.             run()
  117.         else
  118.             run()
  119.         end
  120.  
  121.         return cid
  122.     end
  123.  
  124.     function Animator.get_aid(targchar)
  125.         local welds = global_welds[targchar]
  126.         return welds.taid
  127.     end
  128.  
  129.     local function Play(self, FadeIn, Speed, Looped)
  130.         self.TimePosition = 0
  131.         self.StartInternal = os.clock()
  132.  
  133.         self.FadeIn = FadeIn or 0
  134.         self.Speed = Speed or self.Speed
  135.         self.Looped = Looped or self.Looped
  136.         self.LastPlayed = os.clock()
  137.         self.fired = {}
  138.         self.RecoverFade = {}
  139.  
  140.         local StopEvent = Instance.new("BindableEvent")
  141.         self.Stopped = StopEvent.Event
  142.         self.StopEvent = StopEvent
  143.  
  144.         local LoopedEvent = Instance.new("BindableEvent")
  145.         self.OnLooped = LoopedEvent.Event
  146.         self.LoopedEvent = LoopedEvent
  147.  
  148.         local KeyframeReachedEvent = Instance.new("BindableEvent")
  149.         self.KeyframeReached = KeyframeReachedEvent.Event
  150.         self.KeyframeReachedEvent = KeyframeReachedEvent
  151.  
  152.         local MarkerReachedEvent = Instance.new("BindableEvent")
  153.         self.MarkerReached = MarkerReachedEvent.Event
  154.         self.MarkerReachedEvent = MarkerReachedEvent
  155.  
  156.         local I = Playing[self.Model]
  157.         if I then else
  158.             return
  159.         end
  160.         self.Playing = true
  161.         I[self] = true
  162.     end
  163.  
  164.     local function Stop(self,fire)
  165.         local I = Playing[self.Model]
  166.         if I then
  167.             if fire then
  168.                 self.StopEvent:Fire()
  169.             end
  170.         end
  171.  
  172.         self.LastPlayed = 0
  173.         self.Playing = false
  174.         I[self] = nil
  175.  
  176.         self.Stopped = nil
  177.         if self.StopEvent then
  178.             self.StopEvent:Destroy()
  179.         end
  180.         self.StopEvent = nil
  181.  
  182.         self.OnLooped = nil
  183.         if self.StopEvent then
  184.             self.LoopedEvent:Destroy()
  185.         end
  186.         self.LoopedEvent = nil
  187.  
  188.         self.KeyframeReached = nil
  189.         if self.StopEvent then
  190.             self.KeyframeReachedEvent:Destroy()
  191.         end
  192.         self.KeyframeReachedEvent = nil
  193.  
  194.         self.MarkerReached = nil
  195.         if self.StopEvent then
  196.             self.MarkerReachedEvent:Destroy()
  197.         end
  198.         self.MarkerReachedEvent = nil
  199.  
  200.         self.FadeIn = nil
  201.     end
  202.  
  203.     local function Resume(self)
  204.         if self.PauseInternal then
  205.             self.StartInternal = os.clock() - self.PauseInternal
  206.         end
  207.         local I = Playing[self.Model]
  208.         self.Playing = true
  209.         I[self] = true
  210.     end
  211.  
  212.     local function Pause(self)
  213.         local TimeSince = os.clock() - self.StartInternal
  214.         self.PauseInternal = TimeSince
  215.         local I = Playing[self.Model]
  216.         self.Playing = false
  217.         I[self] = nil
  218.     end
  219.  
  220.     local function SetTime(self, Time)
  221.         self.StartInternal = os.clock() - Time
  222.     end
  223.  
  224.     local function AdjustSpeed(self, NewSpeed)
  225.         self.Speed = NewSpeed
  226.     end
  227.  
  228.     local function ft(t,c)
  229.         for i,v in pairs(t) do
  230.             --if i == 'Parent' or i == 'Name' or i == 'Marker' or i == 'Time' or i == 'CF' then continue end
  231.             if typeof(v) == 'table' then
  232.                 ft(v,true)
  233.                 local name = v.Name
  234.                 v.Name = nil
  235.                 local index_t = {
  236.                     Parent = t,
  237.                     Name = name or i,
  238.                 }
  239.                 if v.Marker then
  240.                     index_t.Marker = v.Marker
  241.                     v.Marker = nil
  242.                 end
  243.                 if v.Time then
  244.                     index_t.Time = v.Time
  245.                     v.Time = nil
  246.                 end
  247.                 if v.CF then
  248.                     index_t.CF = v.CF
  249.                     v.CF = nil
  250.                 end
  251.                 if tonumber(i) and not v.CF then
  252.                     index_t.Time = tonumber(i)
  253.                 end
  254.                 v = setmetatable(v,{
  255.                     __index = index_t
  256.                 })
  257.             end
  258.         end
  259.         return t
  260.     end
  261.  
  262.     local function iter(t)
  263.         local new_t = {}
  264.         for i,v in pairs(t) do
  265.             --if i == 'Parent' or i == 'Name' or i == 'Marker' or i == 'Time' or i == 'CF' then continue end
  266.             table.insert(new_t,v)
  267.             if typeof(v) == 'table' then
  268.                 for ii,vv in pairs(iter(v)) do
  269.                     table.insert(new_t,vv)
  270.                 end
  271.             end
  272.         end
  273.         return new_t
  274.     end
  275.  
  276.     local ModelAnimations = {}
  277.     local hasloaded = {}
  278.     local TrackKeyframes = {}
  279.  
  280.     function Animator.Preload(Track)
  281.         if TrackKeyframes[Track] then
  282.             return TrackKeyframes[Track]
  283.         end
  284.  
  285.         Track.Keyframes = ft(Track.Keyframes)
  286.         local kf = Track.Keyframes
  287.         table.sort(kf, function(a, b) return a.Time < b.Time end)
  288.  
  289.         local Keyframes = {}
  290.         local jdata = {}
  291.         local largest_time = 0
  292.  
  293.         do
  294.             for STime, SKeyframe in next, kf do
  295.                 STime = tonumber(STime)
  296.                 if STime > largest_time then
  297.                     largest_time = STime
  298.                 end
  299.                 local descendants = iter(SKeyframe)
  300.  
  301.                 local function set_marker(name)
  302.                     if not Keyframes['_null'] then
  303.                         Keyframes['_null'] = {}
  304.                     end
  305.                     Keyframes['_null'][#Keyframes['_null'] + 1] = {Time = STime, Name = name, Marker = 1, ["Info"] = nil}
  306.                 end
  307.  
  308.                 if 0 >= #descendants then
  309.                     set_marker(SKeyframe.Name)
  310.                 end
  311.                 for _,Pose in next, descendants do
  312.                     if typeof(Pose) ~= 'table' then continue end
  313.                     if Pose.Name == 'HumanoidRootPart' then continue end
  314.  
  315.                     if Pose.Marker then
  316.                         set_marker(Pose.Name)
  317.                     end
  318.  
  319.                     local P0 = Pose.Parent.Name
  320.                     local P1 = Pose.Name
  321.  
  322.                     local JT = Keyframes[P0..'KEyjtsep'..P1]
  323.                     if not JT then
  324.                         JT = {}
  325.                         Keyframes[P0..'KEyjtsep'..P1] = JT
  326.                         jdata[P0..'KEyjtsep'..P1] = 1
  327.                     end
  328.  
  329.                     local Style = Pose.ES or 'Linear'
  330.                     local Direction = Pose.ED or 'In'
  331.                     local Weight = Pose.Weight or 1
  332.                     local PCF = Pose.CF
  333.  
  334.                     if not PCF then continue end
  335.                    
  336.                     local CF
  337.                     for i,v in pairs(PCF) do
  338.                         PCF[i] = tonumber(v)
  339.                     end
  340.  
  341.                     if PCF[1] then
  342.                         CF = CFrame.new(PCF[1],PCF[2],PCF[3])
  343.                     else
  344.                         CF = CFrame.new()
  345.                     end
  346.                     if PCF[4] then
  347.                         CF = CF*CFrame.Angles(PCF[4],PCF[5],PCF[6])
  348.                     end
  349.  
  350.                     local Info = {EasingStyle = Style, EasingDirection = Direction, Weight = Weight, CFrame = CF}
  351.  
  352.                     JT[#JT+1] = {Time = STime, Name = SKeyframe.Name, ["Info"] = Info}
  353.                 end
  354.             end
  355.  
  356.             for Joint,Poses in pairs(Keyframes) do
  357.                 table.sort(Poses, function(a, b) return a.Time < b.Time end)
  358.             end
  359.  
  360.             TrackKeyframes[Track] = {
  361.                 Keyframes,
  362.                 jdata,
  363.                 largest_time
  364.             }
  365.  
  366.             return TrackKeyframes[Track]
  367.         end
  368.     end
  369.  
  370.     function Animator.LoadAnimation(Track, Model)
  371.         assert(Track,'No track.')
  372.         assert(Model,'No model.')
  373.         local notmodel
  374.         if not ModelAnimations[Model] then
  375.             notmodel = true
  376.             ModelAnimations[Model] = {}
  377.             ModelAnimations[Model].Joints = {}
  378.         elseif ModelAnimations[Model][Track] then
  379.             return ModelAnimations[Model][Track]
  380.         end
  381.         local Animation = {}
  382.         ModelAnimations[Model][Track] = Animation
  383.  
  384.         if not hasloaded[Track] then
  385.             Track.Properties.Priority = Enum.AnimationPriority[Track.Properties.Priority]
  386.         end
  387.  
  388.         local set_model = Ver(Model)
  389.  
  390.         local largest_time = 0
  391.  
  392.         if not GlobalPlaying[Model][Animation] then
  393.             GlobalPlaying[Model][Animation] = {}
  394.         end
  395.  
  396.         if notmodel then
  397.             local function new_joint(Obj)
  398.                 if Obj:IsA("Weld") then
  399.                     local P0 = Obj.Part0
  400.                     local P1 = Obj.Part1
  401.                     if not P0 or not P1 then return end
  402.  
  403.                     local jd = JointData[Obj.Name]
  404.                     if jd then
  405.                         Obj.C0 = jd
  406.                         JointC0[Obj] = jd
  407.                     else
  408.                         JointC0[Obj] = Obj.C0
  409.                     end
  410.  
  411.                     local T = ModelAnimations[Model].Joints[P0.Name]
  412.                     if not T then
  413.                         T = {}
  414.                         ModelAnimations[Model].Joints[P0.Name] = T
  415.                     end
  416.                     if not T[P1.Name] then
  417.                         T[P1.Name] = Obj
  418.                     end
  419.                 end
  420.             end
  421.  
  422.             for _,v in ipairs(Model:GetDescendants()) do
  423.                 new_joint(v)
  424.             end
  425.             Model.DescendantAdded:Connect(new_joint)
  426.         end
  427.  
  428.         local track_data = Animator.Preload(Track)
  429.         if track_data then
  430.             local Keyframes,jdata,lt = unpack(track_data)
  431.             Animation.Keyframes = Keyframes
  432.             GlobalPlaying[Model][Animation] = jdata
  433.             largest_time = lt
  434.         else
  435.             error('No track preloaded.')
  436.         end
  437.  
  438.         Animation.TimePosition = 0
  439.         Animation.TimeLength = largest_time
  440.         Animation.Track = Track
  441.         Animation.Model = Model
  442.         Animation.TimeScale = 1
  443.         Animation.GeneralWeight = 1
  444.         Animation.Play = Play
  445.         Animation.Stop = Stop
  446.         Animation.Resume = Resume
  447.         Animation.Pause = Pause
  448.         Animation.SetTime = SetTime
  449.         Animation.AdjustSpeed = AdjustSpeed
  450.         Animation.Looped = Track.Properties.Looping or false
  451.         Animation.Speed = 1
  452.         Animation.FadeIn = 0
  453.         Animation.LastPlayed = 0
  454.         Animation.i = 0
  455.         Animation.Playing = false
  456.         Animation.fired = {}
  457.         Animation.RecoverFade = {}
  458.  
  459.         if Track.Properties.Priority == Enum.AnimationPriority.Idle then
  460.             Animation.Priority = 1
  461.         elseif Track.Properties.Priority == Enum.AnimationPriority.Movement then
  462.             Animation.Priority = 2
  463.         elseif Track.Properties.Priority == Enum.AnimationPriority.Action then
  464.             Animation.Priority = 3
  465.         else--if Track.Properties.Priority == Enum.AnimationPriority.Core then
  466.             Animation.Priority = 0
  467.         end
  468.  
  469.         Animation.StartInternal = 0
  470.         Animation.PauseInternal = 0
  471.  
  472.         Animation.GetTimeOfKeyframe = function(name)
  473.             for Time,v in ipairs(Animation.Keyframes) do
  474.                 if v.Name == name then
  475.                     return Time
  476.                 end
  477.             end
  478.         end
  479.  
  480.         hasloaded[Track] = true
  481.  
  482.         return Animation
  483.     end
  484.  
  485.     local CF = CFrame.new()
  486.     local function GetPose(TimeSince, Poses, Joint, Animation)
  487.         for i = 1,#Poses do
  488.             local Keyframe = Poses[i]
  489.             local NextKeyframe = Poses[i+1]
  490.             local Time = Keyframe.Time
  491.  
  492.             --local JT = Joint.Transform
  493.  
  494.             if TimeSince >= Time then
  495.                 if not Animation.fired[Keyframe.Name .. Time] and Keyframe.Name ~= 'Keyframe' then
  496.                     Animation.fired[Keyframe.Name .. Time] = 1
  497.                     if Keyframe.Marker then -- keymarker
  498.                         Animation.MarkerReachedEvent:Fire(Keyframe.Name)
  499.                     else -- keyframe
  500.                         Animation.KeyframeReachedEvent:Fire(Keyframe.Name)
  501.                     end
  502.                 end
  503.             end
  504.  
  505.             if (TimeSince >= Time) or Poses[1].Time > TimeSince then
  506.                 if NextKeyframe then
  507.                     local NextTime = NextKeyframe.Time
  508.                     if TimeSince < NextTime then
  509.                         if Keyframe.Marker then
  510.                             return {nil, nil, Keyframe.Name, Time, Keyframe.Marker}
  511.                         end
  512.                         local Info1 = Keyframe.Info
  513.                         local Info2 = NextKeyframe.Info
  514.  
  515.                         local Alpha = (TimeSince - Time) / (NextTime - Time)
  516.  
  517.                         local CFA = CF:Lerp(Info1.CFrame, Info1.Weight)
  518.                         local CFB = CF:Lerp(Info2.CFrame, Info2.Weight)
  519.  
  520.                         local Pose
  521.                         if Info2.EasingStyle == 'Constant' then
  522.                             Pose = CFA
  523.                         else
  524.                             Pose = CFA:Lerp(CFB, TS:GetValue(Alpha, Enum.EasingStyle[Info2.EasingStyle], Enum.EasingDirection[Info2.EasingDirection]))
  525.                         end
  526.  
  527.                         return {Joint, Pose, Keyframe.Name, Time}
  528.                     end
  529.                 else
  530.                     if Keyframe.Marker then
  531.                         return {nil, nil, Keyframe.Name, Time, Keyframe.Marker}
  532.                     end
  533.                     return {Joint, Keyframe.Info.CFrame, Keyframe.Name, Time}
  534.                 end
  535.             end
  536.         end
  537.     end
  538.  
  539.     local total_playing = 0
  540.  
  541.     local function UpdatePlaying()
  542.         local tp = 0
  543.         for Model, Animations in next, Playing do
  544.             for Animation,_ in next, Animations do
  545.                 if not Animation.Playing then
  546.                     continue
  547.                 end
  548.                 if not Model or not Model.Parent then
  549.                     Playing[Model] = nil
  550.                     Animation.FadeIn = nil
  551.                     Animation.fired = {}
  552.                     Animation.Playing = false
  553.  
  554.                     continue
  555.                 end
  556.  
  557.                 local TimeSince = Animation.StartInternal
  558.                 TimeSince = os.clock() - ((os.clock() - TimeSince) * Animation.Speed)
  559.                 TimeSince = os.clock() - TimeSince
  560.  
  561.                 --local TimeSince = os.clock() - Animation.StartInternal
  562.                 --TimeSince = TimeSince * Animation.Speed
  563.  
  564.                 if Animation.FadeIn then
  565.                     Animation.OFadeIn = Animation.FadeIn
  566.                 end
  567.  
  568.                 local Length = Animation.TimeLength
  569.  
  570.                 if TimeSince > Length then
  571.                     Animation.FadeIn = nil
  572.                     Animation.fired = {}
  573.                     if Animation.Looped then
  574.                         Animation.LoopedEvent:Fire()
  575.                         if 0 >= Length then
  576.                             TimeSince = 0
  577.                         else
  578.                             TimeSince = TimeSince%Length
  579.                         end
  580.                         --Animation.StartInternal += Length-TimeSince
  581.                     else
  582.                         Animation.TimePosition = 0
  583.                         Playing[Model][Animation] = nil
  584.                         Animation.Playing = false
  585.                         Animation.StopEvent:Fire()
  586.                         continue
  587.                     end
  588.                 end
  589.  
  590.                 local Keyframes = Animation.Keyframes
  591.  
  592.                 if Keyframes then else continue end
  593.                 tp += 1
  594.                 local ToAnimate = {}
  595.                 local StartFade = nil
  596.                 for Joint, Poses in pairs(Keyframes) do
  597.                     local strjoint = Joint
  598.                     local jd = string.split(strjoint,'KEyjtsep')
  599.                     local Joint
  600.                     if jd[1] and jd[2] then
  601.                         Joint = ModelAnimations[Model].Joints[jd[1]]
  602.                         if not Joint then
  603.                             continue
  604.                         end
  605.                         Joint = Joint[jd[2]]
  606.                         if not Joint then
  607.                             continue
  608.                         end
  609.                     end
  610.                     if not Poses[1] or not Poses[1].Marker then
  611.                         local f,fade
  612.                         for i,using in pairs(GlobalPlaying[Model]) do
  613.                             if i ~= Animation then else
  614.                                 continue
  615.                             end
  616.                             if i.Playing then else
  617.                                 continue
  618.                             end
  619.                             if using[strjoint] then else
  620.                                 continue
  621.                             end
  622.                             if i.Priority > Animation.Priority or (i.Priority == Animation.Priority and i.LastPlayed > Animation.LastPlayed) then else
  623.                                 continue
  624.                             end
  625.                             f = true
  626.                         end
  627.                         if f then
  628.                             Animation.RecoverFade[Joint.Name] = os.clock()
  629.                             continue
  630.                         end
  631.                     end
  632.                     if Poses[1] and Poses[1].Time > TimeSince then
  633.                         --StartFade = Poses[1].Time * Animation.Speed
  634.                     end
  635.  
  636.                     ToAnimate[#ToAnimate+1] = GetPose(TimeSince, Poses, Joint, Animation)
  637.                 end
  638.                 for i = 1,#ToAnimate do
  639.                     local Pose = ToAnimate[i]
  640.                     if not Pose[5] then
  641.                         local TCF = Pose[2]
  642.                         local FadeIn = Animation.FadeIn
  643.                         local RF = Animation.RecoverFade[Pose[1].Name]
  644.                         local TimeSince = TimeSince
  645.                         if RF then
  646.                             TimeSince = os.clock()-RF
  647.                             if TimeSince >= Length then
  648.                                 Animation.RecoverFade[Pose[1].Name] = nil
  649.                             else
  650.                                 FadeIn = Animation.OFadeIn
  651.                             end
  652.                         end
  653.                         TCF = JointC0[Pose[1]] * TCF
  654.                         if StartFade then
  655.                             TCF = Pose[1].C0:Lerp(TCF, TimeSince / StartFade)
  656.                         elseif FadeIn and TimeSince < FadeIn then
  657.                             TCF = Pose[1].C0:Lerp(TCF, TimeSince / FadeIn)
  658.                         end
  659.                         Pose[1].C0 = TCF
  660.                     end
  661.                 end
  662.  
  663.                 Animation.TimePosition = TimeSince
  664.             end
  665.         end
  666.         total_playing = tp
  667.     end
  668.  
  669.     function Animator.GetPlaying()
  670.         return total_playing
  671.     end
  672.  
  673.     local con
  674.     if game:GetService("RunService"):IsClient() then
  675.         con = game:GetService("RunService").RenderStepped:Connect(UpdatePlaying)
  676.     else
  677.         con = game:GetService("RunService").Stepped:Connect(UpdatePlaying)
  678.     end
  679.  
  680.     return Animator,con
  681. end
  682.  
  683. -- anims
  684.  
  685. local default_anims = game:GetService("HttpService"):GetAsync('https://pastebin.com/raw/0JSVJpVB')
  686. default_anims = game:GetService("HttpService"):JSONDecode(default_anims)
  687.  
  688. -- anims
  689.  
  690. local anims = {}
  691.  
  692. local function add_anim(...)
  693.     local list = {...}
  694.     local str = ''
  695.     for i = 1,#list do
  696.         local v = list[i]
  697.         local a = game:GetService("HttpService"):GetAsync(v)
  698.         if a then
  699.             str = str .. a
  700.         end
  701.     end
  702.     str = string.gsub(str, "%c", "")
  703.     str = game:GetService("HttpService"):JSONDecode(str)
  704.     for i,v in pairs(str) do
  705.         anims[i] = v
  706.     end
  707. end
  708.  
  709. add_anim('https://pastebin.com/raw/78CctHLP','https://pastebin.com/raw/Gy91BraJ','https://pastebin.com/raw/7JQBFC2L')
  710.  
  711. -- starter
  712.  
  713. local st = os.clock()
  714.  
  715. local plr = owner
  716. local char = plr.Character
  717. local hum = char:FindFirstChildOfClass("Humanoid")
  718. local root = char:FindFirstChild("HumanoidRootPart")
  719.  
  720. --
  721.  
  722. local animator,con = init()
  723.  
  724. animator.create_welds(char)
  725. animator.toggle_anim(false,char)
  726.  
  727. for i,v in pairs(anims) do
  728.     animator.Preload(v)
  729. end
  730. for i,v in pairs(default_anims) do
  731.     animator.Preload(v)
  732. end
  733.  
  734. function get_anim(s)
  735.     for i,v in pairs(anims) do
  736.         if string.lower(i) == string.lower(s) then
  737.             return v
  738.         end
  739.     end
  740. end
  741. function load(anim,targchar)
  742.     targchar = targchar or char
  743.     return animator.LoadAnimation(anim,targchar)
  744. end
  745.  
  746. local move_anims = {
  747.     fall = {
  748.         anim = default_anims.fall,
  749.         fade = 0.3,
  750.     },
  751.     climb = {
  752.         anim = default_anims.climb,
  753.         fade = 0.2,
  754.     },
  755.     jump = {
  756.         anim = default_anims.jump,
  757.         fade = 0.2,
  758.     },
  759.     walk = {
  760.         anim = default_anims.walk,
  761.         fade = 0.2,
  762.     },
  763.     idle = {
  764.         anim = default_anims.idle,
  765.         fade = 0.3,
  766.     },
  767.     sit = {
  768.         anim = default_anims.sit,
  769.         fade = 0.5,
  770.     },
  771. }
  772.  
  773. local jumped = false
  774. local paused_default = false
  775. local current_move = nil
  776.  
  777. function play_move_anim(cid)
  778.     if not cid then
  779.         for id,data in pairs(move_anims) do
  780.             local anim = load(data.anim)
  781.             if anim.Playing then
  782.                 anim:Stop()
  783.             end
  784.         end
  785.         return
  786.     end
  787.     local data = move_anims[cid]
  788.     local anim = load(data.anim)
  789.     if cid == 'walk' then
  790.         --data.anim:AdjustSpeed(hum.WalkSpeed/16)
  791.     end
  792.     if not anim.Playing then
  793.         if current_move then
  794.             local data = move_anims[current_move]
  795.             local anim = load(data.anim)
  796.             anim:Stop()
  797.         end
  798.         current_move = cid
  799.         anim:Play(data.fade, nil, true)
  800.     end
  801. end
  802.  
  803. --
  804.  
  805. function sleep(n)
  806.     return task.wait(n or 0)
  807. end
  808.  
  809. local function wrap(func)
  810.     coroutine.resume(coroutine.create(func))
  811. end
  812.  
  813. function play_sound(par,id,vol,speed,loop,perm)
  814.     local s = Instance.new("Sound")
  815.     s.SoundId = 'rbxassetid://' .. id
  816.     s.Volume = vol or 0.5
  817.     s.PlaybackSpeed = speed or 1
  818.     s.Looped = loop or false
  819.     s.Parent = par or root
  820.     if not perm then
  821.         s:Play()
  822.     end
  823.     if not loop and not perm then
  824.         s.Ended:Connect(function()
  825.             sleep()
  826.             s:Destroy()
  827.         end)
  828.     end
  829.     return s
  830. end
  831.  
  832. --
  833. local dance_anim = nil
  834.  
  835. plr.Chatted:Connect(function(msg)
  836.     msg = string.lower(msg)
  837.     if string.sub(msg,1,3) == '/e ' then
  838.         msg = string.sub(msg,4)
  839.     end
  840.     local dance = get_anim(msg)
  841.     if dance then
  842.         if dance_anim then
  843.             dance_anim:Stop()
  844.             dance_anim = nil
  845.         end
  846.         dance_anim = load(dance)
  847.         dance_anim:Play()
  848.     end
  849. end)
  850. --
  851.  
  852. local t = [[
  853. /e [emote]
  854. ]]
  855.  
  856. for i,v in pairs(anims) do
  857.     t = t .. '\n' .. i
  858. end
  859.  
  860. print(t)
  861.  
  862. local c
  863. c = game:GetService("RunService").Heartbeat:Connect(function()
  864.     if not char or not char.Parent or 0 >= hum.Health then
  865.         --c:Disconnect()
  866.         return
  867.     end
  868.     local dir = root.Velocity
  869.     local params = RaycastParams.new()
  870.     params.FilterType = Enum.RaycastFilterType.Blacklist
  871.     params.FilterDescendantsInstances = {char}
  872.     params.IgnoreWater = false
  873.     local ground = workspace:Raycast(root.Position,root.CFrame.UpVector*-1*5,params)
  874.     local jumpvel = dir.Y
  875.     local walkvel = (dir*Vector3.new(1,0,1)).Magnitude
  876.     local movevel = dir.Magnitude
  877.     local faceDir = root.CFrame.lookVector.Unit
  878.     local moveDir = dir.Unit
  879.     local dot = faceDir:Dot(moveDir)
  880.  
  881.     local moving,air_state
  882.  
  883.     if walkvel > 0.01 then
  884.         moving = true
  885.        
  886.         if dance_anim then
  887.             dance_anim:Play()
  888.             dance_anim = nil
  889.         end
  890.     else
  891.         moving = false
  892.     end
  893.  
  894.     local state = hum:GetState()
  895.  
  896.     if state == Enum.HumanoidStateType.Freefall then
  897.         air_state = 1
  898.     elseif state == Enum.HumanoidStateType.Jumping then
  899.         air_state = 2
  900.     else
  901.         air_state = 0
  902.     end
  903.  
  904.     if state == Enum.HumanoidStateType.Jumping then
  905.         jumped = true
  906.     else
  907.         jumped = false
  908.     end
  909.    
  910.     if dance_anim then
  911.         animator.toggle_anim(true,char)
  912.     else
  913.         animator.toggle_anim(false,char)
  914.     end
  915.    
  916.     if not paused_default then
  917.         if state == Enum.HumanoidStateType.Climbing then
  918.             play_move_anim('climb')
  919.         elseif hum.Sit then
  920.             play_move_anim('sit')
  921.         elseif air_state == 1 then
  922.             play_move_anim('fall')
  923.         elseif air_state == 2 then
  924.             play_move_anim('jump')
  925.         elseif moving then
  926.             play_move_anim('walk')
  927.         else
  928.             play_move_anim('idle')
  929.         end
  930.     else
  931.         play_move_anim()
  932.     end
  933. end)
  934.  
  935. print('run: ' .. os.clock()-st)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement