Advertisement
mach10

Untitled

Apr 8th, 2025
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.31 KB | None | 0 0
  1. --// Main
  2. local ReplicatedStorage = game:GetService('ReplicatedStorage');
  3. local Resources = require(ReplicatedStorage:WaitForChild('Resources'));
  4.  
  5. --// Services
  6. local Debris = game:GetService('Debris')
  7. local Players = game:GetService('Players')
  8. local LocalPlayer = Players.LocalPlayer
  9.  
  10. --// Player Instances
  11. local PlayerGUI = LocalPlayer:FindFirstChildOfClass('PlayerGui')
  12. local PlayerScripts = LocalPlayer:FindFirstChildOfClass('PlayerScripts')
  13.  
  14. -- GUI
  15. local ToolsGUI = PlayerGUI:WaitForChild('Tools', 5)
  16. local InterfaceGUI = PlayerGUI:WaitForChild('Interface', 5)
  17.  
  18. --// Modules
  19. local Mechanics = {}
  20. local Callbacks = {};
  21. local SecondTouches = {
  22.     ['Default'] = 0.4;
  23.     ['Dribble'] = 0.5;
  24.     ['Shoot'] = 0.2;
  25.     ['Aero'] = 0.4;
  26.     ['Fake'] = 0.3;
  27. };
  28.  
  29. local AnimateModule = require(PlayerScripts:WaitForChild('Management', 5).Animate)
  30. Mechanics.Animations = require(PlayerScripts:WaitForChild('Management', 5).Animate.Animations)
  31.  
  32. --// Tweens
  33. local TweensModule = require(Resources['Modules'].Tweens)
  34. TweensModule = TweensModule:Setup({
  35.     ['Foot Indicators'] = {};
  36.     ['Powerbar'] = {}
  37. })
  38.  
  39. TweensModule:Insert({
  40.     ['R'] = TweensModule.Service:Create(ToolsGUI['R'], TweenInfo.new(0.6, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {TextTransparency = 1});
  41.     ['L'] = TweensModule.Service:Create(ToolsGUI['L'], TweenInfo.new(0.6, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {TextTransparency = 1});
  42. }, 'Foot Indicators')
  43.  
  44. --// Functions
  45. function Mechanics:AddCallback(Topic, Name, Function) -- Reset for fouls / ankles
  46.     if (Topic and Name and Function) == nil then
  47.         return false
  48.     end
  49.    
  50.     if (string.lower(typeof(Function)) ~= 'function') then
  51.         return false
  52.     end
  53.    
  54.     if (Callbacks[Topic] == nil) then
  55.         return false
  56.     end
  57.    
  58.     Topic = Callbacks[Topic]
  59.     Topic[Name] = Function
  60.     return true
  61. end
  62.  
  63. function Mechanics:TriggerCallback(Topic)
  64.     if (Topic == nil or Callbacks[Topic] == nil) then
  65.         return false
  66.     end
  67.    
  68.     Topic = Callbacks[Topic]
  69.     for i, Callback in Topic do
  70.         if (string.lower(typeof(Callback)) == 'function') then
  71.             Callback()
  72.         end
  73.     end
  74.     return true
  75. end
  76.  
  77. function Mechanics:Coroutine(Function)
  78.     if (Function == nil or string.lower(typeof(Function)) ~= 'function') then
  79.         return false
  80.     end
  81.    
  82.     local Task = task.spawn(function()
  83.         coroutine.wrap(Function)()
  84.     end)
  85.    
  86.     return function()
  87.         task.cancel(Task)
  88.     end
  89. end
  90.  
  91. -- Player Animating
  92. function Mechanics:Animate(Info, CFrames)
  93.     coroutine.wrap(function()
  94.         AnimateModule:Animate(LocalPlayer, Info, CFrames)
  95.         return Resources['Remotes']:FindFirstChild('Edit Welds'):FireServer('Animate', Info, CFrames)
  96.     end)()
  97.     return true
  98. end
  99.  
  100. function Mechanics:ResetAnimations()
  101.     coroutine.wrap(function()
  102.         AnimateModule:ResetAnimations(LocalPlayer)
  103.         return Resources['Remotes']:FindFirstChild('Edit Welds'):FireServer('Reset')
  104.     end)()
  105.     return true
  106. end
  107.  
  108. -- Basic Variables
  109. function Mechanics:Reset()
  110.     --// Variables
  111.     Mechanics.Variables = {
  112.         -- Booleans
  113.         Debounce = false;
  114.         Ragdoll = false;
  115.         Getup = false;
  116.         Dive = false;
  117.         Catch = false;
  118.         Reflex = false;
  119.         Camera = false;
  120.         Foul = false;
  121.        
  122.         -- Others
  123.         Held = nil;
  124.         Leg = 'Right';
  125.     };
  126.    
  127.     Callbacks = {
  128.         ['Reset'] = {}
  129.     };
  130.    
  131.     --// Functions
  132. end
  133.  
  134. function Mechanics:SetVariable(Name, Bool)
  135.     if (Name) == nil then
  136.         return false
  137.     end
  138.    
  139.     for i, v in Mechanics.Variables do
  140.         if (string.lower(i) == string.lower(Name)) then
  141.             Mechanics.Variables[i] = Bool
  142.             return true
  143.         end
  144.     end
  145.    
  146.     warn('[MECHANICS]; Variable; ' .. Name .. ' wasnt found (:SetVariable)')
  147.     return 0;
  148. end
  149.  
  150. function Mechanics:GetVariable(Name)
  151.     if (Name) == nil then
  152.         return false
  153.     end
  154.  
  155.     for i, v in Mechanics.Variables do
  156.         if (string.lower(i) == string.lower(Name)) then
  157.             return v
  158.         end
  159.     end
  160.    
  161.     warn('[MECHANICS]; Variable; ' .. Name .. ' wasnt found (:GetVariable)')
  162.     return 0;
  163. end
  164.  
  165. -- Client Actions
  166. function Mechanics:SwitchFoot()
  167.     if (Mechanics:GetVariable('Leg') == 'Right') then
  168.         Mechanics:SetVariable('Leg', 'Left')
  169.         return true, Mechanics:SwitchFootUIToggle('L')
  170.     end
  171.    
  172.     Mechanics:SetVariable('Leg', 'Right')
  173.     return true, Mechanics:SwitchFootUIToggle('R')
  174. end
  175.  
  176. function Mechanics:SwitchFootUIToggle(Leg)
  177.     Resources.Functions['PlaySound']('Hover', 'Squirm', nil, Resources['_G']["Tool Sound FX"])
  178.     TweensModule:Pause('Foot Indicators', string.upper(Leg))
  179.     InterfaceGUI:FindFirstChild('Buttons').Main.Foot.Text = string.upper(Leg)
  180.     --ToolsGUI['L'].TextTransparency = 1
  181.     --ToolsGUI['R'].TextTransparency = 1
  182.     ToolsGUI[string.upper(Leg)].TextTransparency = 0
  183.     TweensModule:Play('Foot Indicators', string.upper(Leg))
  184.     return true
  185. end
  186.  
  187. -- Proper Catch Checks
  188. -- Debug Prints
  189. function Mechanics.TestDebugPrint(s)
  190.     if (Resources['_G']['Test Print Debug']) then
  191.         return warn(s)
  192.     end
  193.     return false
  194. end
  195.  
  196. function Mechanics.DebugPrints(s)
  197.     if (Resources['_G']['Print Debug']) then
  198.         return print(s)
  199.     end
  200.     return false
  201. end
  202.  
  203. -- React Check
  204. function Mechanics.IsSecondTouch(Ball : Part)
  205.     if (Ball == nil) then
  206.         return true -- basically true = second touching, ball is nil so return true so the game doesnt process
  207.     elseif (Ball:FindFirstChild('Second Touch')) and (Ball['Second Touch'].Value ~= LocalPlayer) then
  208.         Mechanics.TestDebugPrint('[MECHANICS]; Second touch detected')
  209.         return true
  210.     end
  211.     return false
  212. end
  213.  
  214. function Mechanics.IsReach(Ball :Part)
  215.     if (Ball == nil) then
  216.         return true -- basically true = is reaching, ball is nil so return true so the game doesnt process
  217.     end
  218.    
  219.     if (LocalPlayer.Character == nil) then
  220.         return true
  221.     end
  222.    
  223.     local Character = LocalPlayer.Character
  224.     local HRP = Character:FindFirstChild('HumanoidRootPart')
  225.    
  226.     if (HRP == nil) then
  227.         return true
  228.     end
  229.    
  230.     local Velocity = (Ball.AssemblyLinearVelocity.Magnitude)
  231.     Velocity = math.abs(Velocity)
  232.    
  233.     local Distance = (Ball.Position - HRP.Position).Magnitude
  234.     Distance = math.abs(Distance)
  235.    
  236.     if (Distance > 5.3 and Velocity < 28) then
  237.         Mechanics.TestDebugPrint('[MECHANICS]; Reach detected due to high distance')
  238.         return true
  239.     end
  240.     return false
  241. end
  242.  
  243. function Mechanics.CanReact(Ball : Part)
  244.     if (Ball == nil) then
  245.         return false
  246.     elseif (LocalPlayer.Character == nil) then
  247.         return false
  248.     end
  249.    
  250.     local Anchored = Ball:GetAttribute('Anchored')
  251.     local Held = Ball:GetAttribute('Held')
  252.    
  253.     if (Anchored == true) then
  254.         Mechanics.TestDebugPrint('[MECHANICS]; Ball is attributed as anchored (CanReact)')
  255.         return false
  256.     end
  257.    
  258.     if (Held ~= 0) then
  259.         Mechanics.TestDebugPrint('[MECHANICS]; Ball is attributed as held (CanReact)')
  260.         return false
  261.     end
  262.     return true
  263. end
  264.  
  265. -- React Functions
  266. function Mechanics:Rainbow(Bind, Instances, Package, Magnus)
  267.     if (Bind and Instances and Package) == nil then
  268.         return false
  269.     end
  270.  
  271.     local Ball, Limb, CDPreset = unpack(Instances)
  272.     local MaxForce, Direction, Power, Height = unpack(Package)
  273.  
  274.     if (Ball and MaxForce and Power and Height) == nil then
  275.         return false
  276.     end
  277.    
  278.     if not (Mechanics.CanReact(Ball)) then
  279.         return false
  280.     end
  281.    
  282.     for _, v in Ball:GetChildren() do
  283.         if (v:IsA('BodyVelocity') or v:IsA('BodyAngularVelocity') or v:IsA('BodyForce')) then
  284.             v:Destroy()
  285.         end
  286.     end
  287.  
  288.     local IsOwner = Ball:GetAttribute('Owner') == LocalPlayer.UserId
  289.     local SecondTouchCD = SecondTouches[CDPreset] or SecondTouches['Default']
  290.  
  291.     local BCFrame = Ball.CFrame
  292.     if not IsOwner then
  293.         if (Mechanics.IsSecondTouch(Ball)) then
  294.             return false
  295.         elseif (Mechanics.IsReach(Ball)) then
  296.             return false
  297.         elseif not Resources['Remotes']:FindFirstChild('Call Network'):InvokeServer(Ball, SecondTouchCD) then
  298.             return false, task.spawn(function()
  299.                 table.clear(Instances)
  300.                 table.clear(Package)
  301.  
  302.                 if (string.lower(typeof(Magnus)) == 'table') then
  303.                     table.clear(Magnus)
  304.                 end
  305.             end)
  306.         end
  307.  
  308.         if (Ball.AssemblyLinearVelocity.Magnitude) > 35 then
  309.             Ball.AssemblyLinearVelocity = Vector3.zero
  310.         end
  311.     end
  312.    
  313.     task.delay(0.12, function()
  314.         if (Direction[1] and Direction[2]) == nil then
  315.             return false
  316.         end
  317.  
  318.         --if not (MaxForce.X == 0 and MaxForce.Z == 0) then
  319.         --  Ball.AssemblyLinearVelocity = Vector3.zero
  320.         --end
  321.  
  322.         local BodyVelocity = Instance.new('BodyVelocity')
  323.         BodyVelocity.MaxForce = MaxForce
  324.         BodyVelocity.Velocity = (Direction[1].CFrame * Direction[2]).LookVector * Power
  325.         BodyVelocity.Velocity = BodyVelocity.Velocity * Vector3.new(1, 0, 1)
  326.         BodyVelocity.Velocity = BodyVelocity.Velocity + Height
  327.         BodyVelocity.Parent = Ball
  328.         Debris:AddItem(BodyVelocity, 0.3)
  329.  
  330.         local Volume = (BodyVelocity.Velocity.Magnitude / 60)
  331.         if Volume < 0.1 then
  332.             Volume = 0.1
  333.         end
  334.  
  335.         if (Resources['_G']['Ball Sound FX']) and (Ball:FindFirstChild('Sounds') and Ball.Sounds:FindFirstChild('Kick')) then
  336.             Ball.Sounds['Kick']:Pause()
  337.             Ball.Sounds['Kick'].TimePosition = 0
  338.             Ball.Sounds['Kick'].Volume = Volume
  339.             Ball.Sounds['Kick']:Play()
  340.         end
  341.  
  342.         Resources['Remotes']:FindFirstChild('Ball Debug'):FireServer('Ball Sounds', Ball, 'Kick', Volume)
  343.         return true
  344.     end)
  345.     return true
  346. end
  347.  
  348. function Mechanics:React(Bind, Instances, Package, Magnus)
  349.     if (Bind and Instances and Package) == nil then
  350.         return false
  351.     end
  352.    
  353.     local Ball, Limb, CDPreset = unpack(Instances)
  354.     local MaxForce, Power, Height = unpack(Package)
  355.      
  356.     if (Ball and MaxForce and Power and Height) == nil then
  357.         return false
  358.     end
  359.  
  360.     if not (Mechanics.CanReact(Ball)) then
  361.         return false
  362.     end
  363.  
  364.     for _, v in Ball:GetChildren() do
  365.         if (v:IsA('BodyVelocity') or v:IsA('BodyAngularVelocity') or v:IsA('BodyForce')) then
  366.             v:Destroy()
  367.         end
  368.     end
  369.  
  370.     local IsOwner = Ball:GetAttribute('Owner') == LocalPlayer.UserId
  371.     local SecondTouchCD = SecondTouches[CDPreset] or SecondTouches['Default']
  372.  
  373.     if not (MaxForce.X == 0 and MaxForce.Z == 0) then
  374.         Ball.AssemblyLinearVelocity = Vector3.zero
  375.     end
  376.    
  377.     local BodyVelocity = Instance.new('BodyVelocity')
  378.     BodyVelocity.MaxForce = MaxForce
  379.     BodyVelocity.Velocity = Power
  380.     BodyVelocity.Velocity = BodyVelocity.Velocity * Vector3.new(1, 0, 1)
  381.     BodyVelocity.Velocity = BodyVelocity.Velocity + Height
  382.     BodyVelocity.Parent = Ball
  383.     Debris:AddItem(BodyVelocity, 0.3)
  384.    
  385.     local BCFrame = Ball.CFrame
  386.     if not IsOwner then
  387.         if (Mechanics.IsSecondTouch(Ball)) then
  388.             return false
  389.         elseif (Mechanics.IsReach(Ball)) then
  390.             return false
  391.         elseif not Resources['Remotes']:FindFirstChild('Call Network'):InvokeServer(Ball, SecondTouchCD) then
  392.             return false, task.spawn(function()
  393.                 BodyVelocity:Destroy()
  394.                 table.clear(Instances)
  395.                 table.clear(Package)
  396.  
  397.                 if (string.lower(typeof(Magnus)) == 'table') then
  398.                     table.clear(Magnus)
  399.                 end
  400.             end)
  401.         end
  402.     end
  403.    
  404.     local Volume = (BodyVelocity.Velocity.Magnitude / 60)
  405.     if Volume < 0.1 then
  406.         Volume = 0.1
  407.     end
  408.    
  409.     if (Resources['_G']['Ball Sound FX']) and (Ball:FindFirstChild('Sounds') and Ball.Sounds:FindFirstChild('Kick')) then
  410.         Ball.Sounds['Kick']:Pause()
  411.         Ball.Sounds['Kick'].TimePosition = 0
  412.         Ball.Sounds['Kick'].Volume = Volume
  413.         Ball.Sounds['Kick']:Play()
  414.     end
  415.    
  416.     Resources['Remotes']:FindFirstChild('Ball Debug'):FireServer('Ball Sounds', Ball, 'Kick', Volume)
  417.    
  418.     if not IsOwner then
  419.         Resources['Remotes']:FindFirstChild('Ball Debug'):FireServer('React Bubble', Ball, BCFrame, 'Player')
  420.     end
  421.     return true
  422. end
  423.  
  424. --// Reset Handler
  425. Resources['Functions'].Wrap_PRINTS(function()
  426.     Mechanics:Reset()
  427.    
  428.     LocalPlayer.CharacterAdded:Connect(function()
  429.         return Mechanics:Reset()
  430.     end)
  431.     return true
  432. end)
  433.  
  434. return Mechanics
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement