Advertisement
KrYn0MoRe

dynasty blade

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