Prephy

test animate v2

Oct 21st, 2021 (edited)
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.46 KB | None | 0 0
  1.  
  2. --Complete functional 2008 like Animate script + more old 2008 movement functions!
  3.  
  4. --this includes some old coding from the original classic animation script
  5.  
  6. --originally only works as localscript but had to edit it to work on void sb
  7. --this actually is just a test but you can use it anyway
  8.  
  9. --//.-.\\
  10.  
  11. --Remade by Protofer_S
  12.  
  13. --\\.-.//
  14.  
  15. -- util
  16.  
  17. function waitForChild(parent, childName)
  18.     while true do
  19.         local child = parent:findFirstChild(childName)
  20.         if child then
  21.             return child
  22.         end
  23.         parent.ChildAdded:wait()
  24.     end
  25. end
  26.  
  27.  
  28. function newSound(id,Parent1)
  29.     local sound = Instance.new("Sound")
  30.     sound.SoundId = id
  31.     sound.Parent = Parent1
  32.     return sound
  33. end
  34.  
  35. -- declarations
  36.  
  37. local Figure = owner.Character
  38. local Torso = waitForChild(Figure, "Torso")
  39. local Humanoid = Figure:FindFirstChildOfClass("Humanoid")
  40. Humanoid:ClearAllChildren()
  41. Humanoid.RequiresNeck=false
  42. Instance.new("Animator",Humanoid).Name="Animator"
  43. local oldanim = Figure:FindFirstChild("Animate")
  44. if oldanim then oldanim.Disabled=true end
  45.  
  46. local sDied = newSound("rbxasset://sounds/uuhhh.wav",Torso)
  47. local sFallingDown = newSound("rbxasset://sounds/splat.wav",Torso)
  48. local sFreeFalling = newSound("rbxasset://sounds/button.wav",Torso)
  49. local sGettingUp = newSound("rbxasset://sounds/hit.wav",Torso)
  50. local sJumping = newSound("rbxasset://sounds/button.wav",Torso)
  51. local sRunning = newSound("rbxasset://sounds/bfsl-minifigfoots1.mp3",Torso)
  52. sRunning.Looped = true
  53.  
  54.  
  55.  
  56. -- functions
  57.  
  58. function onDied()
  59.     sDied:play()
  60. end
  61.  
  62. function onState(state, sound)
  63.     if state then
  64.         sound:play()
  65.     else
  66.         sound:pause()
  67.     end
  68. end
  69.  
  70. function onRunning(speed)
  71.     if speed>0 then
  72.         sRunning:play()
  73.     else
  74.         sRunning:pause()
  75.     end
  76. end
  77.  
  78. -- connect up
  79.  
  80. Humanoid.Died:connect(onDied)
  81. Humanoid.Running:connect(onRunning)
  82. Humanoid.Jumping:connect(function(state) onState(state, sJumping) end)
  83. Humanoid.GettingUp:connect(function(state) onState(state, sGettingUp) end)
  84. Humanoid.FreeFalling:connect(function(state) onState(state, sFreeFalling) end)
  85. Humanoid.FallingDown:connect(function(state) onState(state, sFallingDown) end)
  86.  
  87. function makeJoint(limbName, jointName, c0, c1)
  88.     local limb = waitForChild(Figure, limbName)
  89.     if limb.Name=="Head" then
  90.  
  91.     else
  92.         limb:BreakJoints()  
  93.  
  94.     end
  95.     local joint = Instance.new"Motor"
  96.     joint.Name = jointName
  97.  
  98.     joint.Part0 = Torso
  99.     joint.Part1 = limb
  100.     joint.C0 = c0
  101.     joint.C1 = c1
  102.     joint.MaxVelocity = 0.5
  103.     joint.archivable = true
  104.     joint.Parent = Torso
  105.     return joint
  106. end
  107.  
  108.  
  109.  
  110. local Neck = makeJoint("Head","Neck", CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0), CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0))
  111. local RightShoulder = makeJoint("Right Arm", "Right Shoulder", CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), CFrame.new(-0.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0))
  112. local LeftShoulder = makeJoint("Left Arm", "Left Shoulder", CFrame.new(-1, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), CFrame.new(0.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0))
  113. local RightHip = makeJoint("Right Leg", "Right Hip", CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), CFrame.new(0.5, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0))
  114. local LeftHip = makeJoint("Left Leg", "Left Hip", CFrame.new(-1, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), CFrame.new(-0.5, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0))
  115.  
  116. NLS([[
  117.  
  118.  
  119.  
  120.  
  121. function newSound(id,Parent1)
  122.     local sound = Instance.new("Sound")
  123.     sound.SoundId = id
  124.     sound.Parent = Parent1
  125.     return sound
  126. end
  127.  
  128.  
  129. local Player = game:GetService("Players").LocalPlayer
  130. local Figure = Player.Character
  131. local Torso = Figure:WaitForChild("Torso")
  132. local Lefthip = Torso:WaitForChild("Left Hip")
  133. local Righthip = Torso:WaitForChild("Right Hip")
  134. local Humanoid = Figure:FindFirstChildOfClass("Humanoid")
  135. local Rightshoulder = Torso:WaitForChild("Right Shoulder")
  136. local Leftshoulder = Torso:WaitForChild("Left Shoulder")
  137. local walkspeed = Humanoid.WalkSpeed   
  138. local P = game:GetService("PathfindingService")
  139. local movespeed = 1
  140. local jumpMaxLimbVelocity = 0.5
  141. local ANGLE = 10
  142. local FPS = 0.05
  143. local canjump=true
  144. local removing = game.DescendantRemoving
  145. local Mouse = Player:GetMouse()
  146. local MAINDISK = nil
  147. local moveto = nil
  148. local newpath = false
  149. local oldpath
  150. local pathwait
  151. local usingtool = false
  152. local Pose = "standing"
  153.  
  154.  
  155.  
  156. local sDied = newSound("rbxasset://sounds/uuhhh.wav",Torso)
  157. local sFallingDown = newSound("rbxasset://sounds/splat.wav",Torso)
  158. local sFreeFalling = newSound("rbxasset://sounds/button.wav",Torso)
  159. local sGettingUp = newSound("rbxasset://sounds/hit.wav",Torso)
  160. local sJumping = newSound("rbxasset://sounds/button.wav",Torso)
  161. local sRunning = newSound("rbxasset://sounds/bfsl-minifigfoots1.mp3",Torso)
  162. sRunning.Looped = true
  163.  
  164.  
  165.  
  166. function clickmovement(END)
  167.     if usingtool then return end
  168.     if not newpath then
  169.         newpath=true
  170.     END = Mouse.Hit.p
  171.     moveto = createdisk()
  172.     moveto.Position = END
  173.         moveto.Orientation = Vector3.new(0,0,90)
  174.         local path = P:CreatePath()
  175.     path:ComputeAsync(Torso.Position, END)
  176.     local waypoints = path:GetWaypoints()
  177.     if path.Status == Enum.PathStatus.Success then
  178.         for _, waypoint in pairs(waypoints) do
  179.             if waypoint.Action == Enum.PathWaypointAction.Jump then
  180.                 Humanoid.Jump = true
  181.                 end
  182.                 if newpath then
  183.                     Humanoid:MoveTo(waypoint.Position)
  184.                     Humanoid.MoveToFinished:Wait()
  185.                 else
  186.                     Humanoid:MoveTo(Torso.Position)
  187.                 end
  188.             end
  189.         end
  190.         newpath=false
  191.         moveto:Destroy()
  192.     else
  193.         newpath=false
  194.         if moveto~=nil then
  195.             moveto:Destroy()
  196.         end
  197.         Humanoid:MoveTo(Torso.Position)
  198.     end
  199.    
  200. end
  201.  
  202. function diskpos()
  203.     if MAINDISK~=nil then
  204.     MAINDISK.CFrame = Mouse.Hit
  205.         MAINDISK.Orientation = Vector3.new(0, 0, 90)
  206.         local TOOL = 0
  207.         for i,v in pairs(Player.Backpack:children()) do
  208.             if v:IsA'HopperBin' and v.Active==true then
  209.                 TOOL=TOOL+1
  210.                 end
  211.         end
  212.         for i,v in pairs(Player.Character:children()) do
  213.             if v:IsA'Tool' then
  214.                 TOOL=TOOL+1
  215.             end
  216.         end
  217.         if TOOL~=0 then
  218.             usingtool=true
  219.             if MAINDISK.Parent~=nil then
  220.                 MAINDISK.Transparency=1
  221.             end
  222.         else
  223.             if MAINDISK.Parent~=nil then
  224.                 MAINDISK.Transparency=0
  225.             end
  226.             usingtool=false
  227.         end
  228.     end
  229. end
  230.  
  231. function createdisk()
  232.     wait()
  233.     local Disc = Instance.new("Part", Figure)
  234.     if usingtool then
  235.         Disc.Transparency=1
  236.     end
  237.     Disc.Shape = "Cylinder"
  238.     Disc.Size = Vector3.new(0.5, 3.5, 2.5)
  239.     Disc.TopSurface = Enum.SurfaceType.Smooth
  240.     Disc.BottomSurface = Enum.SurfaceType.Smooth
  241.     Disc.Anchored = true
  242.     Disc.CanCollide = false
  243.     Disc.BrickColor = BrickColor.new("Lime green")
  244.     return Disc
  245. end
  246. MAINDISK = createdisk()
  247. local rem = removing:Connect(function(ob)
  248.     if ob==MAINDISK then
  249.         MAINDISK = createdisk()
  250.     end
  251. end)
  252.  
  253.  
  254.  
  255. function jumpcooldown(velocity)
  256.     coroutine.resume(coroutine.create(function()
  257.         if canjump then
  258.     local oldpower = Humanoid.JumpPower
  259.     canjump=false
  260.     while wait() do
  261.         if Pose~="falling" and Pose~="jumping" then
  262.                     break
  263.                 else
  264.                     if not canjump then
  265.                         Humanoid.JumpPower=0
  266.                         end
  267.         end
  268.         end
  269.     wait(.5)
  270.     Humanoid.JumpPower = oldpower
  271.     canjump=true
  272.         end
  273.         end))
  274. end
  275.  
  276. function moveJump()
  277.     Rightshoulder.MaxVelocity = jumpMaxLimbVelocity
  278.     Leftshoulder.MaxVelocity = jumpMaxLimbVelocity
  279.     Rightshoulder:SetDesiredAngle(3.14)
  280.     Leftshoulder:SetDesiredAngle(-3.14)
  281.     Righthip:SetDesiredAngle(0)
  282.     Lefthip:SetDesiredAngle(0)
  283. end
  284.  
  285. function moveFreeFall()
  286.     Rightshoulder.MaxVelocity = jumpMaxLimbVelocity
  287.     Leftshoulder.MaxVelocity = jumpMaxLimbVelocity
  288.     Rightshoulder:SetDesiredAngle(3.14)
  289.     Leftshoulder:SetDesiredAngle(-3.14)
  290.     Righthip:SetDesiredAngle(0)
  291.     Lefthip:SetDesiredAngle(0)
  292. end
  293.  
  294. function moveclimb(desiredangle,climbangle)
  295.     Leftshoulder.MaxVelocity=jumpMaxLimbVelocity
  296.     Rightshoulder.MaxVelocity=jumpMaxLimbVelocity
  297.     Lefthip:SetDesiredAngle(-desiredangle*6.65)
  298.     Righthip:SetDesiredAngle(-desiredangle*6.65)
  299.     Leftshoulder:SetDesiredAngle(desiredangle*6.5-climbangle)
  300.     Rightshoulder:SetDesiredAngle(desiredangle*6.5+climbangle)
  301. end
  302.  
  303. function moveSit()
  304.     Rightshoulder.MaxVelocity = 0.15
  305.     Leftshoulder.MaxVelocity = 0.15
  306.     Rightshoulder:SetDesiredAngle(3.14 /2)
  307.     Leftshoulder:SetDesiredAngle(-3.14 /2)
  308.     Righthip:SetDesiredAngle(3.14 /2)
  309.     Lefthip:SetDesiredAngle(-3.14 /2)
  310. end
  311.  
  312. function getTool() 
  313.     for _, kid in ipairs(Figure:GetChildren()) do
  314.         if kid.className == "Tool" then return kid end
  315.     end
  316.     return nil
  317. end
  318.  
  319. function getToolAnim(tool)
  320.     for _, c in ipairs(tool:GetChildren()) do
  321.         if c.Name == "toolanim" and c.className == "StringValue" then
  322.             return c
  323.         end
  324.     end
  325.     return nil
  326. end
  327.  
  328. function animateTool()
  329.  
  330.     if (toolAnim == "None") then
  331.         Rightshoulder:SetDesiredAngle(1.57)
  332.         return
  333.     end
  334.  
  335.     if (toolAnim == "Slash") then
  336.         Rightshoulder.MaxVelocity = 0.5
  337.         Rightshoulder:SetDesiredAngle(0)
  338.         return
  339.     end
  340.  
  341.     if (toolAnim == "Lunge") then
  342.         Rightshoulder.MaxVelocity = 0.5
  343.         Leftshoulder.MaxVelocity = 0.5
  344.         Righthip.MaxVelocity = 0.5
  345.         Lefthip.MaxVelocity = 0.5
  346.         Rightshoulder:SetDesiredAngle(1.57)
  347.         Leftshoulder:SetDesiredAngle(1.0)
  348.         Righthip:SetDesiredAngle(1.57)
  349.         Lefthip:SetDesiredAngle(1.0)
  350.         return
  351.     end
  352. end
  353.  
  354. function Move(desiredangle,time)
  355.     if Pose=="jumping" then
  356.         moveJump()
  357.         return
  358.     end
  359.    
  360.     if Pose=="falling" then
  361.         moveFreeFall()
  362.         return
  363.     end
  364.    
  365.     if Pose=="climbing" then
  366.         moveclimb(desiredangle,math.rad(180))
  367.         return
  368.     end
  369.    
  370.     if Pose=="sitting" then
  371.         moveSit()
  372.         return
  373.     end
  374.     if Pose=="running" or Pose=="climbing" or Pose=="falling" then
  375.         local anglespeed = 0.2 - walkspeed*0.005
  376.         if anglespeed>0.01 then
  377.             movespeed=anglespeed
  378.             FPS=0.05
  379.         else
  380.             movespeed=0.01
  381.             FPS=0
  382.         end
  383.     end
  384.     if Pose=="running" then
  385.        
  386.         ANGLE=9.5
  387.         Lefthip:SetDesiredAngle(-desiredangle*6.65)
  388.         Righthip:SetDesiredAngle(-desiredangle*6.65)
  389.         Leftshoulder:SetDesiredAngle(desiredangle*6.5+desiredangle)
  390.         Rightshoulder:SetDesiredAngle(desiredangle*6.5+desiredangle)
  391.         --Lefthip.DesiredAngle = -desiredangle*6.65+desiredangle
  392.         --Righthip.DesiredAngle = -desiredangle*6.65+desiredangle
  393.         --Rightshoulder.DesiredAngle = desiredangle*6.5+desiredangle
  394.         --Leftshoulder.DesiredAngle = desiredangle*6.5+desiredangle
  395.         if (Rightshoulder.CurrentAngle > 1.5 or Rightshoulder.CurrentAngle < -1.5) then
  396.             Rightshoulder.MaxVelocity = 0.1
  397.         else           
  398.             if movespeed>-0.01 then
  399.                 Rightshoulder.MaxVelocity = 0.15
  400.                 Righthip.MaxVelocity = 0.2
  401.             else
  402.                 Righthip.MaxVelocity = .7
  403.                 Rightshoulder.MaxVelocity = .7
  404.             end    
  405.         end
  406.         if (Leftshoulder.CurrentAngle > 1.5 or Leftshoulder.CurrentAngle < -1.5) then
  407.             Leftshoulder.MaxVelocity = 0.1
  408.         else           
  409.             if movespeed>-0.01 then
  410.                 Leftshoulder.MaxVelocity = 0.15
  411.                 Lefthip.MaxVelocity = 0.2
  412.             else
  413.                 Lefthip.MaxVelocity = .7
  414.                 Leftshoulder.MaxVelocity = .7
  415.             end
  416.         end
  417.     end
  418.     if Pose=="standing" or Pose=="platformstand" then
  419.         if (Rightshoulder.CurrentAngle > 1.5 or Rightshoulder.CurrentAngle < -1.5) then
  420.             Rightshoulder.MaxVelocity = 0.25
  421.         end
  422.         if (Leftshoulder.CurrentAngle > 1.5 or Leftshoulder.CurrentAngle < -1.5) then
  423.             Leftshoulder.MaxVelocity = 0.25
  424.         end
  425.         ANGLE=10
  426.         movespeed = 1
  427.         Lefthip.DesiredAngle = -desiredangle
  428.         Righthip.DesiredAngle = -desiredangle
  429.         Rightshoulder.DesiredAngle = desiredangle
  430.         Leftshoulder.DesiredAngle = desiredangle
  431.     end
  432.    
  433.    
  434.    
  435.     local tool = getTool()
  436.  
  437.     if tool then
  438.         animStringValueObject = getToolAnim(tool)
  439.  
  440.         if animStringValueObject then
  441.             toolAnim = animStringValueObject.Value
  442.             -- message recieved, delete StringValue
  443.             animStringValueObject.Parent = nil
  444.             toolAnimTime = time+.3
  445.         end
  446.  
  447.         if time > toolAnimTime then
  448.             toolAnimTime = 0
  449.             toolAnim = "None"
  450.         end
  451.  
  452.         animateTool()
  453.  
  454.  
  455.     else
  456.         toolAnim = "None"
  457.         toolAnimTime = 0
  458.     end
  459.    
  460.    
  461. end
  462.  
  463. function onSeated()
  464.     Pose="sitting"
  465. end
  466.  
  467. function onRunning(speed)
  468.     local Torsovelocity = (Torso.Velocity * Vector3.new(1,0,1)).magnitude
  469.     if speed>0 then
  470.         Pose="running"
  471.         --sRunning:play()
  472.     else
  473.         movespeed=1
  474.         Pose="standing"
  475.         --sRunning:pause()
  476.     end
  477. end
  478.  
  479. function onDied()
  480.     Pose="died"
  481.     --sDied:play()
  482. end
  483.  
  484. function onJumping()
  485.     Pose="jumping"
  486. end
  487.  
  488. function onClimbing()
  489.     Pose="climbing"
  490. end
  491.  
  492. function onGettingUp()
  493.     Pose="standingup"
  494. end
  495.  
  496. function onFreeFall()
  497.     Pose="falling"
  498. end
  499.  
  500. function onFallingDown()
  501.     Pose="falling"
  502. end
  503.  
  504. function onPlatformStanding()
  505.     Pose="platformstand"
  506. end
  507.  
  508. function onSwimming()
  509.     Pose="swimming"
  510. end
  511.  
  512.  
  513.  
  514.  
  515.  
  516. Humanoid.Died:connect(onDied)
  517. Humanoid.Running:connect(onRunning)
  518. Humanoid.Jumping:connect(onJumping)
  519. Humanoid.Climbing:connect(onClimbing)
  520. Humanoid.GettingUp:connect(onGettingUp)
  521. Humanoid.FreeFalling:connect(onFreeFall)
  522. Humanoid.FallingDown:connect(onFallingDown)
  523. Humanoid.Seated:connect(onSeated)
  524. Humanoid.PlatformStanding:connect(onPlatformStanding)
  525. Humanoid.Swimming:connect(onSwimming)
  526. Mouse.Button1Down:Connect(clickmovement)
  527.  
  528.  
  529. --sound functions
  530.  
  531.  
  532.  
  533. function onState(state, sound)
  534.     if state then
  535.         sound:play()
  536.     else
  537.         sound:pause()
  538.     end
  539. end
  540.  
  541.  
  542. --Humanoid.Jumping:connect(function(state) onState(state, sJumping) end)
  543. --Humanoid.GettingUp:connect(function(state) onState(state, sGettingUp) end)
  544. --Humanoid.FreeFalling:connect(function(state) onState(state, sFreeFalling) end)
  545. --Humanoid.FallingDown:connect(function(state) onState(state, sFallingDown) end)
  546.  
  547.  
  548. while true do
  549.     local _, time = wait(FPS)
  550.     if Figure.Parent~=nil then else
  551.         rem:Disconnect() break
  552.     end
  553.     local jumpVelocity = Torso.Velocity.y
  554.     walkspeed = Humanoid.WalkSpeed
  555.     local angle = math.sin(-tick()/movespeed)/ANGLE
  556.     Move(angle,time)
  557.     if jumpVelocity>5 then
  558.         jumpcooldown(jumpVelocity)
  559.     end
  560.     diskpos()
  561. end
  562.  
  563. ]],owner.Character)
  564.  
  565.  
  566.  
  567.  
Add Comment
Please, Sign In to add comment