Advertisement
KrYn0MoRe

execution anims

Sep 6th, 2022 (edited)
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.65 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.         else
  117.             run()
  118.         end
  119.  
  120.         return cid
  121.     end
  122.  
  123.     function Animator.get_aid(targchar)
  124.         local welds = global_welds[targchar]
  125.         return welds.taid
  126.     end
  127.  
  128.     local function Play(self, FadeIn, Speed, Looped)
  129.         self.TimePosition = 0
  130.         self.StartInternal = os.clock()
  131.  
  132.         self.FadeIn = FadeIn or 0
  133.         self.Speed = Speed or self.Speed
  134.         self.Looped = Looped or self.Looped
  135.         self.LastPlayed = os.clock()
  136.         self.fired = {}
  137.         self.RecoverFade = {}
  138.  
  139.         local StopEvent = Instance.new("BindableEvent")
  140.         self.Stopped = StopEvent.Event
  141.         self.StopEvent = StopEvent
  142.  
  143.         local LoopedEvent = Instance.new("BindableEvent")
  144.         self.OnLooped = LoopedEvent.Event
  145.         self.LoopedEvent = LoopedEvent
  146.  
  147.         local KeyframeReachedEvent = Instance.new("BindableEvent")
  148.         self.KeyframeReached = KeyframeReachedEvent.Event
  149.         self.KeyframeReachedEvent = KeyframeReachedEvent
  150.  
  151.         local MarkerReachedEvent = Instance.new("BindableEvent")
  152.         self.MarkerReached = MarkerReachedEvent.Event
  153.         self.MarkerReachedEvent = MarkerReachedEvent
  154.  
  155.         local I = Playing[self.Model]
  156.         if I then else
  157.             return
  158.         end
  159.         self.Playing = true
  160.         I[self] = true
  161.     end
  162.  
  163.     local function Stop(self,fire)
  164.         local I = Playing[self.Model]
  165.         if I then
  166.             if fire then
  167.                 self.StopEvent:Fire()
  168.             end
  169.         end
  170.  
  171.         self.LastPlayed = 0
  172.         self.Playing = false
  173.         I[self] = nil
  174.  
  175.         self.Stopped = nil
  176.         if self.StopEvent then
  177.             self.StopEvent:Destroy()
  178.         end
  179.         self.StopEvent = nil
  180.  
  181.         self.OnLooped = nil
  182.         if self.StopEvent then
  183.             self.LoopedEvent:Destroy()
  184.         end
  185.         self.LoopedEvent = nil
  186.  
  187.         self.KeyframeReached = nil
  188.         if self.StopEvent then
  189.             self.KeyframeReachedEvent:Destroy()
  190.         end
  191.         self.KeyframeReachedEvent = nil
  192.  
  193.         self.MarkerReached = nil
  194.         if self.StopEvent then
  195.             self.MarkerReachedEvent:Destroy()
  196.         end
  197.         self.MarkerReachedEvent = nil
  198.  
  199.         self.FadeIn = nil
  200.     end
  201.  
  202.     local function Resume(self)
  203.         if self.PauseInternal then
  204.             self.StartInternal = os.clock() - self.PauseInternal
  205.         end
  206.         local I = Playing[self.Model]
  207.         self.Playing = true
  208.         I[self] = true
  209.     end
  210.  
  211.     local function Pause(self)
  212.         local TimeSince = os.clock() - self.StartInternal
  213.         self.PauseInternal = TimeSince
  214.         local I = Playing[self.Model]
  215.         self.Playing = false
  216.         I[self] = nil
  217.     end
  218.  
  219.     local function SetTime(self, Time)
  220.         self.StartInternal = os.clock() - Time
  221.     end
  222.  
  223.     local function AdjustSpeed(self, NewSpeed)
  224.         self.Speed = NewSpeed
  225.     end
  226.  
  227.     local function ft(t,c)
  228.         for i,v in pairs(t) do
  229.             --if i == 'Parent' or i == 'Name' or i == 'Marker' or i == 'Time' or i == 'CF' then continue end
  230.             if typeof(v) == 'table' then
  231.                 ft(v,true)
  232.                 local name = v.Name
  233.                 v.Name = nil
  234.                 local index_t = {
  235.                     Parent = t,
  236.                     Name = name or i,
  237.                 }
  238.                 if v.Marker then
  239.                     index_t.Marker = v.Marker
  240.                     v.Marker = nil
  241.                 end
  242.                 if v.Time then
  243.                     index_t.Time = v.Time
  244.                     v.Time = nil
  245.                 end
  246.                 if v.CF then
  247.                     index_t.CF = v.CF
  248.                     v.CF = nil
  249.                 end
  250.                 if tonumber(i) and not v.CF then
  251.                     index_t.Time = tonumber(i)
  252.                 end
  253.                 v = setmetatable(v,{
  254.                     __index = index_t
  255.                 })
  256.             end
  257.         end
  258.         return t
  259.     end
  260.  
  261.     local function iter(t)
  262.         local new_t = {}
  263.         for i,v in pairs(t) do
  264.             --if i == 'Parent' or i == 'Name' or i == 'Marker' or i == 'Time' or i == 'CF' then continue end
  265.             table.insert(new_t,v)
  266.             if typeof(v) == 'table' then
  267.                 for ii,vv in pairs(iter(v)) do
  268.                     table.insert(new_t,vv)
  269.                 end
  270.             end
  271.         end
  272.         return new_t
  273.     end
  274.  
  275.     local ModelAnimations = {}
  276.     local hasloaded = {}
  277.     local TrackKeyframes = {}
  278.  
  279.     function Animator.Preload(Track)
  280.         if TrackKeyframes[Track] then
  281.             return TrackKeyframes[Track]
  282.         end
  283.  
  284.         Track.Keyframes = ft(Track.Keyframes)
  285.         local kf = Track.Keyframes
  286.         table.sort(kf, function(a, b) return a.Time < b.Time end)
  287.  
  288.         local Keyframes = {}
  289.         local jdata = {}
  290.         local largest_time = 0
  291.  
  292.         do
  293.             for STime, SKeyframe in next, kf do
  294.                 STime = tonumber(STime)
  295.                 if STime > largest_time then
  296.                     largest_time = STime
  297.                 end
  298.                 local descendants = iter(SKeyframe)
  299.  
  300.                 local function set_marker(name)
  301.                     if not Keyframes['_null'] then
  302.                         Keyframes['_null'] = {}
  303.                     end
  304.                     Keyframes['_null'][#Keyframes['_null'] + 1] = {Time = STime, Name = name, Marker = 1, ["Info"] = nil}
  305.                 end
  306.  
  307.                 if 0 >= #descendants then
  308.                     set_marker(SKeyframe.Name)
  309.                 end
  310.                 for _,Pose in next, descendants do
  311.                     if typeof(Pose) ~= 'table' then continue end
  312.                     if Pose.Name == 'HumanoidRootPart' then continue end
  313.  
  314.                     if Pose.Marker then
  315.                         set_marker(Pose.Name)
  316.                     end
  317.  
  318.                     local P0 = Pose.Parent.Name
  319.                     local P1 = Pose.Name
  320.  
  321.                     local JT = Keyframes[P0..'KEyjtsep'..P1]
  322.                     if not JT then
  323.                         JT = {}
  324.                         Keyframes[P0..'KEyjtsep'..P1] = JT
  325.                         jdata[P0..'KEyjtsep'..P1] = 1
  326.                     end
  327.  
  328.                     local Style = Pose.ES or 'Linear'
  329.                     local Direction = Pose.ED or 'In'
  330.                     local Weight = Pose.Weight or 1
  331.                     local PCF = Pose.CF
  332.  
  333.                     if not PCF then continue end
  334.  
  335.                     local CF
  336.                     for i,v in pairs(PCF) do
  337.                         PCF[i] = tonumber(v)
  338.                     end
  339.  
  340.                     if PCF[1] then
  341.                         CF = CFrame.new(PCF[1],PCF[2],PCF[3])
  342.                     else
  343.                         CF = CFrame.new()
  344.                     end
  345.                     if PCF[4] then
  346.                         CF = CF*CFrame.Angles(math.rad(PCF[4]),math.rad(PCF[5]),math.rad(PCF[6]))
  347.                     end
  348.  
  349.                     local Info = {EasingStyle = Style, EasingDirection = Direction, Weight = Weight, CFrame = CF}
  350.  
  351.                     JT[#JT+1] = {Time = STime, Name = SKeyframe.Name, ["Info"] = Info}
  352.                 end
  353.             end
  354.  
  355.             for Joint,Poses in pairs(Keyframes) do
  356.                 table.sort(Poses, function(a, b) return a.Time < b.Time end)
  357.             end
  358.  
  359.             TrackKeyframes[Track] = {
  360.                 Keyframes,
  361.                 jdata,
  362.                 largest_time
  363.             }
  364.  
  365.             return TrackKeyframes[Track]
  366.         end
  367.     end
  368.  
  369.     function Animator.LoadAnimation(Track, Model)
  370.         assert(Track,'No track.')
  371.         assert(Model,'No model.')
  372.         local notmodel
  373.         if not ModelAnimations[Model] then
  374.             notmodel = true
  375.             ModelAnimations[Model] = {}
  376.             ModelAnimations[Model].Joints = {}
  377.         elseif ModelAnimations[Model][Track] then
  378.             return ModelAnimations[Model][Track]
  379.         end
  380.         local Animation = {}
  381.         ModelAnimations[Model][Track] = Animation
  382.  
  383.         if not hasloaded[Track] then
  384.             Track.Properties.Priority = Enum.AnimationPriority[Track.Properties.Priority]
  385.         end
  386.  
  387.         local set_model = Ver(Model)
  388.  
  389.         local largest_time = 0
  390.  
  391.         if not GlobalPlaying[Model][Animation] then
  392.             GlobalPlaying[Model][Animation] = {}
  393.         end
  394.  
  395.         if notmodel then
  396.             local function new_joint(Obj)
  397.                 if Obj:IsA("Weld") then
  398.                     local P0 = Obj.Part0
  399.                     local P1 = Obj.Part1
  400.                     if not P0 or not P1 then return end
  401.  
  402.                     local jd = JointData[Obj.Name]
  403.                     if jd then
  404.                         Obj.C0 = jd
  405.                         JointC0[Obj] = jd
  406.                     else
  407.                         JointC0[Obj] = Obj.C0
  408.                     end
  409.  
  410.                     local T = ModelAnimations[Model].Joints[P0.Name]
  411.                     if not T then
  412.                         T = {}
  413.                         ModelAnimations[Model].Joints[P0.Name] = T
  414.                     end
  415.                     if not T[P1.Name] then
  416.                         T[P1.Name] = Obj
  417.                     end
  418.                 end
  419.             end
  420.  
  421.             for _,v in ipairs(Model:GetDescendants()) do
  422.                 new_joint(v)
  423.             end
  424.             Model.DescendantAdded:Connect(new_joint)
  425.         end
  426.  
  427.         local track_data = Animator.Preload(Track)
  428.         if track_data then
  429.             local Keyframes,jdata,lt = unpack(track_data)
  430.             Animation.Keyframes = Keyframes
  431.             GlobalPlaying[Model][Animation] = jdata
  432.             largest_time = lt
  433.         else
  434.             error('No track preloaded.')
  435.         end
  436.  
  437.         Animation.TimePosition = 0
  438.         Animation.TimeLength = largest_time
  439.         Animation.Track = Track
  440.         Animation.Model = Model
  441.         Animation.TimeScale = 1
  442.         Animation.GeneralWeight = 1
  443.         Animation.Play = Play
  444.         Animation.Stop = Stop
  445.         Animation.Resume = Resume
  446.         Animation.Pause = Pause
  447.         Animation.SetTime = SetTime
  448.         Animation.AdjustSpeed = AdjustSpeed
  449.         Animation.Looped = Track.Properties.Looping or false
  450.         Animation.Speed = 1
  451.         Animation.FadeIn = 0
  452.         Animation.LastPlayed = 0
  453.         Animation.i = 0
  454.         Animation.Playing = false
  455.         Animation.fired = {}
  456.         Animation.RecoverFade = {}
  457.  
  458.         if Track.Properties.Priority == Enum.AnimationPriority.Idle then
  459.             Animation.Priority = 1
  460.         elseif Track.Properties.Priority == Enum.AnimationPriority.Movement then
  461.             Animation.Priority = 2
  462.         elseif Track.Properties.Priority == Enum.AnimationPriority.Action then
  463.             Animation.Priority = 3
  464.         else--if Track.Properties.Priority == Enum.AnimationPriority.Core then
  465.             Animation.Priority = 0
  466.         end
  467.  
  468.         Animation.StartInternal = 0
  469.         Animation.PauseInternal = 0
  470.  
  471.         Animation.GetTimeOfKeyframe = function(name)
  472.             for Time,v in ipairs(Animation.Keyframes) do
  473.                 if v.Name == name then
  474.                     return Time
  475.                 end
  476.             end
  477.         end
  478.  
  479.         hasloaded[Track] = true
  480.  
  481.         return Animation
  482.     end
  483.  
  484.     local CF = CFrame.new()
  485.     local function GetPose(TimeSince, Poses, Joint, Animation)
  486.         for i = 1,#Poses do
  487.             local Keyframe = Poses[i]
  488.             local NextKeyframe = Poses[i+1]
  489.             local Time = Keyframe.Time
  490.  
  491.             --local JT = Joint.Transform
  492.  
  493.             if TimeSince >= Time then
  494.                 if not Animation.fired[Keyframe.Name .. Time] and Keyframe.Name ~= 'Keyframe' then
  495.                     Animation.fired[Keyframe.Name .. Time] = 1
  496.                     if Keyframe.Marker then -- keymarker
  497.                         Animation.MarkerReachedEvent:Fire(Keyframe.Name)
  498.                     else -- keyframe
  499.                         Animation.KeyframeReachedEvent:Fire(Keyframe.Name)
  500.                     end
  501.                 end
  502.             end
  503.  
  504.             if (TimeSince >= Time) or Poses[1].Time > TimeSince then
  505.                 if NextKeyframe then
  506.                     local NextTime = NextKeyframe.Time
  507.                     if TimeSince < NextTime then
  508.                         if Keyframe.Marker then
  509.                             return {nil, nil, Keyframe.Name, Time, Keyframe.Marker}
  510.                         end
  511.                         local Info1 = Keyframe.Info
  512.                         local Info2 = NextKeyframe.Info
  513.  
  514.                         local Alpha = (TimeSince - Time) / (NextTime - Time)
  515.  
  516.                         local CFA = CF:Lerp(Info1.CFrame, Info1.Weight)
  517.                         local CFB = CF:Lerp(Info2.CFrame, Info2.Weight)
  518.  
  519.                         local Pose
  520.                         if Info2.EasingStyle == 'Constant' then
  521.                             Pose = CFA
  522.                         else
  523.                             Pose = CFA:Lerp(CFB, TS:GetValue(Alpha, Enum.EasingStyle[Info2.EasingStyle], Enum.EasingDirection[Info2.EasingDirection]))
  524.                         end
  525.  
  526.                         return {Joint, Pose, Keyframe.Name, Time}
  527.                     end
  528.                 else
  529.                     if Keyframe.Marker then
  530.                         return {nil, nil, Keyframe.Name, Time, Keyframe.Marker}
  531.                     end
  532.                     return {Joint, Keyframe.Info.CFrame, Keyframe.Name, Time}
  533.                 end
  534.             end
  535.         end
  536.     end
  537.  
  538.     local total_playing = 0
  539.  
  540.     local function UpdatePlaying()
  541.         local tp = 0
  542.         for Model, Animations in next, Playing do
  543.             for Animation,_ in next, Animations do
  544.                 if not Animation.Playing then
  545.                     continue
  546.                 end
  547.                 if not Model or not Model.Parent then
  548.                     Playing[Model] = nil
  549.                     Animation.FadeIn = nil
  550.                     Animation.fired = {}
  551.                     Animation.Playing = false
  552.  
  553.                     continue
  554.                 end
  555.  
  556.                 local TimeSince = Animation.StartInternal
  557.                 TimeSince = os.clock() - ((os.clock() - TimeSince) * Animation.Speed)
  558.                 TimeSince = os.clock() - TimeSince
  559.  
  560.                 --local TimeSince = os.clock() - Animation.StartInternal
  561.                 --TimeSince = TimeSince * Animation.Speed
  562.  
  563.                 if Animation.FadeIn then
  564.                     Animation.OFadeIn = Animation.FadeIn
  565.                 end
  566.  
  567.                 local Length = Animation.TimeLength
  568.  
  569.                 if TimeSince > Length then
  570.                     Animation.FadeIn = nil
  571.                     Animation.fired = {}
  572.                     if Animation.Looped then
  573.                         Animation.LoopedEvent:Fire()
  574.                         if 0 >= Length then
  575.                             TimeSince = 0
  576.                         else
  577.                             TimeSince = TimeSince%Length
  578.                         end
  579.                         --Animation.StartInternal += Length-TimeSince
  580.                     else
  581.                         Animation.TimePosition = 0
  582.                         Playing[Model][Animation] = nil
  583.                         Animation.Playing = false
  584.                         Animation.StopEvent:Fire()
  585.                         continue
  586.                     end
  587.                 end
  588.  
  589.                 local Keyframes = Animation.Keyframes
  590.  
  591.                 if Keyframes then else continue end
  592.                 tp += 1
  593.                 local ToAnimate = {}
  594.                 local StartFade = nil
  595.                 for Joint, Poses in pairs(Keyframes) do
  596.                     local strjoint = Joint
  597.                     local jd = string.split(strjoint,'KEyjtsep')
  598.                     local Joint
  599.                     if jd[1] and jd[2] then
  600.                         Joint = ModelAnimations[Model].Joints[jd[1]]
  601.                         if not Joint then
  602.                             continue
  603.                         end
  604.                         Joint = Joint[jd[2]]
  605.                         if not Joint then
  606.                             continue
  607.                         end
  608.                     end
  609.                     if not Poses[1] or not Poses[1].Marker then
  610.                         local f,fade
  611.                         for i,using in pairs(GlobalPlaying[Model]) do
  612.                             if i ~= Animation then else
  613.                                 continue
  614.                             end
  615.                             if i.Playing then else
  616.                                 continue
  617.                             end
  618.                             if using[strjoint] then else
  619.                                 continue
  620.                             end
  621.                             if i.Priority > Animation.Priority or (i.Priority == Animation.Priority and i.LastPlayed > Animation.LastPlayed) then else
  622.                                 continue
  623.                             end
  624.                             f = true
  625.                         end
  626.                         if f then
  627.                             Animation.RecoverFade[Joint.Name] = os.clock()
  628.                             continue
  629.                         end
  630.                     end
  631.                     if Poses[1] and Poses[1].Time > TimeSince then
  632.                         --StartFade = Poses[1].Time * Animation.Speed
  633.                     end
  634.  
  635.                     ToAnimate[#ToAnimate+1] = GetPose(TimeSince, Poses, Joint, Animation)
  636.                 end
  637.                 for i = 1,#ToAnimate do
  638.                     local Pose = ToAnimate[i]
  639.                     if not Pose[5] then
  640.                         local TCF = Pose[2]
  641.                         local FadeIn = Animation.FadeIn
  642.                         local RF = Animation.RecoverFade[Pose[1].Name]
  643.                         local TimeSince = TimeSince
  644.                         if RF then
  645.                             TimeSince = os.clock()-RF
  646.                             if TimeSince >= Length then
  647.                                 Animation.RecoverFade[Pose[1].Name] = nil
  648.                             else
  649.                                 FadeIn = Animation.OFadeIn
  650.                             end
  651.                         end
  652.                         TCF = JointC0[Pose[1]] * TCF
  653.                         if StartFade then
  654.                             TCF = Pose[1].C0:Lerp(TCF, TimeSince / StartFade)
  655.                         elseif FadeIn and TimeSince < FadeIn then
  656.                             TCF = Pose[1].C0:Lerp(TCF, TimeSince / FadeIn)
  657.                         end
  658.                         Pose[1].C0 = TCF
  659.                     end
  660.                 end
  661.  
  662.                 Animation.TimePosition = TimeSince
  663.             end
  664.         end
  665.         total_playing = tp
  666.     end
  667.  
  668.     function Animator.GetPlaying()
  669.         return total_playing
  670.     end
  671.  
  672.     local con
  673.     if game:GetService("RunService"):IsClient() then
  674.         con = game:GetService("RunService").RenderStepped:Connect(UpdatePlaying)
  675.     else
  676.         con = game:GetService("RunService").Stepped:Connect(UpdatePlaying)
  677.     end
  678.  
  679.     return Animator,con
  680. end
  681.  
  682. -- anims
  683.  
  684. local default_anims = game:GetService("HttpService"):GetAsync('https://pastebin.com/raw/0JSVJpVB')
  685. default_anims = game:GetService("HttpService"):JSONDecode(default_anims)
  686.  
  687. -- anims
  688.  
  689. local anims = {}
  690.  
  691. local function add_anim(li)
  692.     local a = game:GetService("HttpService"):GetAsync(li)
  693.     a = game:GetService("HttpService"):JSONDecode(a)
  694.     if a then
  695.         for i,v in pairs(a) do
  696.             anims[i] = v
  697.         end
  698.     end
  699. end
  700.  
  701. add_anim('https://pastebin.com/raw/y7FW92wz')
  702.  
  703. -- starter
  704.  
  705. local st = os.clock()
  706.  
  707. local plr = owner
  708. local char = plr.Character
  709. local hum = char:FindFirstChildOfClass("Humanoid")
  710. local root = char:FindFirstChild("HumanoidRootPart")
  711.  
  712. if hum.RigType == Enum.HumanoidRigType.R6 then else
  713.     warn('Humanoid is not R6')
  714.     return
  715. end
  716.  
  717. --
  718.  
  719. local animator,con = init()
  720.  
  721. animator.create_welds(char)
  722. animator.toggle_anim(false,char)
  723.  
  724. for i,v in pairs(anims) do
  725.     animator.Preload(v)
  726. end
  727. for i,v in pairs(default_anims) do
  728.     animator.Preload(v)
  729. end
  730.  
  731. function load(anim,targchar)
  732.     targchar = targchar or char
  733.     return animator.LoadAnimation(anim,targchar)
  734. end
  735.  
  736. local move_anims = {
  737.     fall = {
  738.         anim = default_anims.fall,
  739.         fade = 0.3,
  740.     },
  741.     climb = {
  742.         anim = default_anims.climb,
  743.         fade = 0.2,
  744.     },
  745.     jump = {
  746.         anim = default_anims.jump,
  747.         fade = 0.2,
  748.     },
  749.     walk = {
  750.         anim = default_anims.walk,
  751.         fade = 0.2,
  752.     },
  753.     idle = {
  754.         anim = default_anims.idle,
  755.         fade = 0.3,
  756.     },
  757.     sit = {
  758.         anim = default_anims.sit,
  759.         fade = 0.5,
  760.     },
  761. }
  762.  
  763. local jumped = false
  764. local paused_default = false
  765. local current_move = nil
  766.  
  767. function play_move_anim(cid)
  768.     if not cid then
  769.         for id,data in pairs(move_anims) do
  770.             local anim = load(data.anim)
  771.             if anim.Playing then
  772.                 anim:Stop()
  773.             end
  774.         end
  775.         return
  776.     end
  777.     local data = move_anims[cid]
  778.     local anim = load(data.anim)
  779.     if cid == 'walk' then
  780.         --data.anim:AdjustSpeed(hum.WalkSpeed/16)
  781.     end
  782.     if not anim.Playing then
  783.         if current_move then
  784.             local data = move_anims[current_move]
  785.             local anim = load(data.anim)
  786.             anim:Stop()
  787.         end
  788.         current_move = cid
  789.         anim:Play(data.fade, nil, true)
  790.     end
  791. end
  792.  
  793. --
  794.  
  795. function sleep(n)
  796.     return task.wait(n or 0)
  797. end
  798.  
  799. local function wrap(func)
  800.     coroutine.resume(coroutine.create(func))
  801. end
  802.  
  803. function play_sound(par,id,vol,speed,loop,perm)
  804.     local s = Instance.new("Sound")
  805.     s.SoundId = 'rbxassetid://' .. id
  806.     s.Volume = vol or 0.5
  807.     s.PlaybackSpeed = speed or 1
  808.     s.Looped = loop or false
  809.     s.Parent = par or root
  810.     if not perm then
  811.         s:Play()
  812.     end
  813.     if not loop and not perm then
  814.         s.Ended:Connect(function()
  815.             sleep()
  816.             s:Destroy()
  817.         end)
  818.     end
  819.     return s
  820. end
  821.  
  822. --
  823.  
  824. local cs = game:GetService("CollectionService")
  825.  
  826. local using = false
  827.  
  828. local cooldowns = {}
  829. function set_cooldown(id,n)
  830.     cooldowns[id] = {os.clock(),n}
  831. end
  832. function is_cooldown(id)
  833.     local cd = cooldowns[id]
  834.     if cd and cd[2] >= os.clock()-cd[1] then
  835.         return true
  836.     end
  837. end
  838.  
  839. function hitbox(hb,ignore,func)
  840.     local hit = {}
  841.  
  842.     local params = OverlapParams.new()
  843.     params.FilterDescendantsInstances = ignore or {char}
  844.     params.FilterType = Enum.RaycastFilterType.Blacklist
  845.     params.MaxParts = 100
  846.  
  847.     for _,box in ipairs(hb) do
  848.         for i,obj in ipairs(workspace:GetPartsInPart(box,params)) do
  849.             local targchar = obj.Parent
  850.             local targhum
  851.             pcall(function()
  852.                 targhum = targchar:FindFirstChildOfClass("Humanoid")
  853.             end)
  854.             local targroot
  855.             pcall(function()
  856.                 targroot = targchar:FindFirstChild("HumanoidRootPart") or targchar:FindFirstChild("Torso")
  857.             end)
  858.             if targchar and not hit[targchar] and targhum and targroot then
  859.                 hit[targchar] = {targchar,targroot,obj}
  860.                 func(targchar,targroot,targhum)
  861.             end
  862.         end
  863.     end
  864. end
  865.  
  866. function sp7(input)
  867.     if not input.press then
  868.         return
  869.     end
  870.     if using then
  871.         return
  872.     end
  873.     if is_cooldown('sp7') then
  874.         return
  875.     end
  876.  
  877.     using = true
  878.     animator.toggle_anim(true,char)
  879.  
  880.     local start = load(anims.sp7_start,char)
  881.     start:Play()
  882.  
  883.     local box = Instance.new("Part")
  884.     box.Transparency = 1
  885.     box.Size = Vector3.new(4,4,2)
  886.     box.CanCollide = false
  887.     box.Massless = true
  888.     box.Locked = true
  889.     box.Parent = workspace
  890.  
  891.     local w = Instance.new("Motor6D")
  892.     w.Part0 = root
  893.     w.Part1 = box
  894.     w.C1 = CFrame.new(0,0,1)
  895.     w.Parent = box
  896.  
  897.     local ws = hum.WalkSpeed
  898.     hum.WalkSpeed = 0
  899.  
  900.     local Vel = Instance.new("BodyVelocity")
  901.     Vel.MaxForce = Vector3.new(1/0,0,1/0)
  902.  
  903.     play_sound(root,3355840382,0.5)
  904.  
  905.     task.delay(0.767,function()
  906.         if Vel then else return end
  907.         Vel.Velocity = root.CFrame.LookVector*25
  908.         Vel.Parent = root
  909.  
  910.         play_sound(root,2923163432,0.5)
  911.     end)
  912.  
  913.     task.delay(1,function()
  914.         paused_default = true
  915.         start:Pause()
  916.  
  917.         local st = os.clock()
  918.  
  919.         local targchar,targroot,targhum
  920.         repeat
  921.             hitbox({box},nil,function(a,b,c)
  922.                 if not targchar and c.Health > 0 then
  923.                     targchar = a
  924.                     targroot = b
  925.                     targhum = c
  926.                 end
  927.             end)
  928.             Vel.Velocity = root.CFrame.LookVector*35
  929.             task.wait()
  930.         until targchar or os.clock()-st >= 1.5
  931.  
  932.         hum.AutoRotate = false
  933.  
  934.         Vel:Destroy()
  935.         box:Destroy()
  936.  
  937.         local function run()
  938.             if targchar then
  939.                 animator.create_welds(targchar) -- (creating Welds instead of Motor6Ds lags)
  940.                 animator.toggle_anim(true,targchar)
  941.  
  942.                 local ws = targhum.WalkSpeed
  943.                 targhum.WalkSpeed = 0
  944.                 targhum.AutoRotate = false
  945.  
  946.                 root.Anchored = true
  947.                 targroot.Anchored = true
  948.  
  949.                 task.spawn(function()
  950.                     for i = 1,5 do
  951.                         root.CFrame = targroot.CFrame*CFrame.new(0,0,-15)*CFrame.Angles(0,math.rad(180),0)
  952.                         task.wait(0.2)
  953.                     end
  954.                 end)
  955.  
  956.                 play_sound(root,2923153182,0.5)
  957.  
  958.                 if targchar and targchar.Parent then else
  959.                     return
  960.                 end
  961.  
  962.                 local exe_self = load(anims.sp7_self,char)
  963.                 local exe_targ = load(anims.sp7_targ,targchar)
  964.  
  965.                 if targchar and targchar.Parent then else
  966.                     return
  967.                 end
  968.  
  969.                 exe_self:Play()
  970.                 exe_targ:Play()
  971.  
  972.                 targhum.BreakJointsOnDeath = false
  973.  
  974.                 exe_self.KeyframeReached:Connect(function(name)
  975.                     if name == 'ImpactR' or name == 'impactL' then
  976.                         if targroot and targhum then else
  977.                             return
  978.                         end
  979.                         play_sound(targroot,200633837,0.5,1.5)
  980.                         play_sound(targroot,2374032821,0.5,math.random(95,105)/100)
  981.                         --targhum:TakeDamage(311/20)
  982.                         targhum:TakeDamage(90/20)
  983.                     end
  984.                 end)
  985.  
  986.                 task.wait(3.817)
  987.  
  988.                 start:Stop()
  989.  
  990.                 if targroot then
  991.                     root.CFrame = targroot.CFrame*CFrame.new(0,0,-7)*CFrame.Angles(0,math.rad(180),0)
  992.                 end
  993.  
  994.                 task.wait(2.35)
  995.  
  996.                 if targhum and targchar then
  997.                     targhum.BreakJointsOnDeath = true
  998.                     targhum:TakeDamage(20)
  999.                     play_sound(targroot,2295409845,0.5,1.5)
  1000.                     animator.toggle_anim(false,targchar)
  1001.                 end
  1002.  
  1003.                 if targroot then
  1004.                     targroot.Anchored = false
  1005.                 end
  1006.                 root.Anchored = false
  1007.  
  1008.                 targhum.WalkSpeed = ws
  1009.                 targhum.AutoRotate = true
  1010.             else
  1011.                 --start:Resume()
  1012.                 local miss = load(anims.sp7_miss,char)
  1013.                 miss:Play()
  1014.                 task.wait(1.733)
  1015.                 miss:Stop()
  1016.                 start:Stop()
  1017.                 paused_default = false
  1018.             end
  1019.         end
  1020.  
  1021.         run()
  1022.  
  1023.         hum.WalkSpeed = ws
  1024.         hum.AutoRotate = true
  1025.  
  1026.         set_cooldown('sp7',1)
  1027.         animator.toggle_anim(false,char)
  1028.         using = false
  1029.     end)
  1030. end
  1031.  
  1032. do
  1033.     local holding = {}
  1034.  
  1035.     local keys = {
  1036.         [Enum.KeyCode.E] = sp7,
  1037.     }
  1038.  
  1039.     local remote = Instance.new("RemoteEvent")
  1040.     remote.Parent = root
  1041.  
  1042.     remote.OnServerEvent:Connect(function(lplr,mode,key)
  1043.         if plr == lplr and key then
  1044.             if not holding[key] then
  1045.                 holding[key] = 0
  1046.             end
  1047.             holding[key] += 1
  1048.             local f = keys[key]
  1049.             if f then
  1050.                 f({
  1051.                     press = mode,
  1052.                     key = key,
  1053.                 })
  1054.             end
  1055.         end
  1056.     end)
  1057.  
  1058.     NLS([[
  1059.     local remote = script.Parent
  1060.     local uis = game:GetService("UserInputService")
  1061.  
  1062.     uis.InputBegan:Connect(function(input,press)
  1063.         if not press then else return end
  1064.         local key
  1065.         if input.UserInputType == Enum.UserInputType.Keyboard then
  1066.             key = input.KeyCode
  1067.         elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
  1068.             key = Enum.UserInputType.MouseButton1
  1069.         elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
  1070.             key = Enum.UserInputType.MouseButton2
  1071.         end
  1072.         if key then
  1073.             remote:FireServer(true,key)
  1074.         end
  1075.     end)
  1076.  
  1077.     uis.InputEnded:Connect(function(input,press)
  1078.         local key
  1079.         if input.UserInputType == Enum.UserInputType.Keyboard then
  1080.             key = input.KeyCode
  1081.         elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
  1082.             key = Enum.UserInputType.MouseButton1
  1083.         elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
  1084.             key = Enum.UserInputType.MouseButton2
  1085.         end
  1086.         if key then
  1087.             remote:FireServer(false,key)
  1088.         end
  1089.     end)
  1090.     ]],remote)
  1091. end
  1092.  
  1093. --
  1094.  
  1095. print([[
  1096. Executions
  1097. e = sp7
  1098. ]])
  1099.  
  1100. local c
  1101. c = game:GetService("RunService").Heartbeat:Connect(function()
  1102.     if not char or not char.Parent or 0 >= hum.Health then
  1103.         --c:Disconnect()
  1104.         return
  1105.     end
  1106.     local dir = root.Velocity
  1107.     local params = RaycastParams.new()
  1108.     params.FilterType = Enum.RaycastFilterType.Blacklist
  1109.     params.FilterDescendantsInstances = {char}
  1110.     params.IgnoreWater = false
  1111.     local ground = workspace:Raycast(root.Position,root.CFrame.UpVector*-1*5,params)
  1112.     local jumpvel = dir.Y
  1113.     local walkvel = (dir*Vector3.new(1,0,1)).Magnitude
  1114.     local movevel = dir.Magnitude
  1115.     local faceDir = root.CFrame.lookVector.Unit
  1116.     local moveDir = dir.Unit
  1117.     local dot = faceDir:Dot(moveDir)
  1118.  
  1119.     local moving,air_state
  1120.  
  1121.     if walkvel > 0.01 then
  1122.         moving = true
  1123.     else
  1124.         moving = false
  1125.     end
  1126.  
  1127.     local state = hum:GetState()
  1128.  
  1129.     if state == Enum.HumanoidStateType.Freefall then
  1130.         air_state = 1
  1131.     elseif state == Enum.HumanoidStateType.Jumping then
  1132.         air_state = 2
  1133.     else
  1134.         air_state = 0
  1135.     end
  1136.  
  1137.     if state == Enum.HumanoidStateType.Jumping then
  1138.         jumped = true
  1139.     else
  1140.         jumped = false
  1141.     end
  1142.  
  1143.     if not paused_default then
  1144.         if state == Enum.HumanoidStateType.Climbing then
  1145.             play_move_anim('climb')
  1146.         elseif hum.Sit then
  1147.             play_move_anim('sit')
  1148.         elseif air_state == 1 then
  1149.             play_move_anim('fall')
  1150.         elseif air_state == 2 then
  1151.             play_move_anim('jump')
  1152.         elseif moving then
  1153.             play_move_anim('walk')
  1154.         else
  1155.             play_move_anim('idle')
  1156.         end
  1157.     else
  1158.         play_move_anim()
  1159.     end
  1160. end)
  1161.  
  1162. print('run: ' .. os.clock()-st)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement