Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Main
- local ReplicatedStorage = game:GetService('ReplicatedStorage');
- local Resources = require(ReplicatedStorage:WaitForChild('Resources'));
- --// Services
- local Debris = game:GetService('Debris')
- local Players = game:GetService('Players')
- local LocalPlayer = Players.LocalPlayer
- --// Player Instances
- local PlayerGUI = LocalPlayer:FindFirstChildOfClass('PlayerGui')
- local PlayerScripts = LocalPlayer:FindFirstChildOfClass('PlayerScripts')
- -- GUI
- local ToolsGUI = PlayerGUI:WaitForChild('Tools', 5)
- local InterfaceGUI = PlayerGUI:WaitForChild('Interface', 5)
- --// Modules
- local Mechanics = {}
- local Callbacks = {};
- local SecondTouches = {
- ['Default'] = 0.4;
- ['Dribble'] = 0.5;
- ['Shoot'] = 0.2;
- ['Aero'] = 0.4;
- ['Fake'] = 0.3;
- };
- local AnimateModule = require(PlayerScripts:WaitForChild('Management', 5).Animate)
- Mechanics.Animations = require(PlayerScripts:WaitForChild('Management', 5).Animate.Animations)
- --// Tweens
- local TweensModule = require(Resources['Modules'].Tweens)
- TweensModule = TweensModule:Setup({
- ['Foot Indicators'] = {};
- ['Powerbar'] = {}
- })
- TweensModule:Insert({
- ['R'] = TweensModule.Service:Create(ToolsGUI['R'], TweenInfo.new(0.6, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {TextTransparency = 1});
- ['L'] = TweensModule.Service:Create(ToolsGUI['L'], TweenInfo.new(0.6, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {TextTransparency = 1});
- }, 'Foot Indicators')
- --// Functions
- function Mechanics:AddCallback(Topic, Name, Function) -- Reset for fouls / ankles
- if (Topic and Name and Function) == nil then
- return false
- end
- if (string.lower(typeof(Function)) ~= 'function') then
- return false
- end
- if (Callbacks[Topic] == nil) then
- return false
- end
- Topic = Callbacks[Topic]
- Topic[Name] = Function
- return true
- end
- function Mechanics:TriggerCallback(Topic)
- if (Topic == nil or Callbacks[Topic] == nil) then
- return false
- end
- Topic = Callbacks[Topic]
- for i, Callback in Topic do
- if (string.lower(typeof(Callback)) == 'function') then
- Callback()
- end
- end
- return true
- end
- function Mechanics:Coroutine(Function)
- if (Function == nil or string.lower(typeof(Function)) ~= 'function') then
- return false
- end
- local Task = task.spawn(function()
- coroutine.wrap(Function)()
- end)
- return function()
- task.cancel(Task)
- end
- end
- -- Player Animating
- function Mechanics:Animate(Info, CFrames)
- coroutine.wrap(function()
- AnimateModule:Animate(LocalPlayer, Info, CFrames)
- return Resources['Remotes']:FindFirstChild('Edit Welds'):FireServer('Animate', Info, CFrames)
- end)()
- return true
- end
- function Mechanics:ResetAnimations()
- coroutine.wrap(function()
- AnimateModule:ResetAnimations(LocalPlayer)
- return Resources['Remotes']:FindFirstChild('Edit Welds'):FireServer('Reset')
- end)()
- return true
- end
- -- Basic Variables
- function Mechanics:Reset()
- --// Variables
- Mechanics.Variables = {
- -- Booleans
- Debounce = false;
- Ragdoll = false;
- Getup = false;
- Dive = false;
- Catch = false;
- Reflex = false;
- Camera = false;
- Foul = false;
- -- Others
- Held = nil;
- Leg = 'Right';
- };
- Callbacks = {
- ['Reset'] = {}
- };
- --// Functions
- end
- function Mechanics:SetVariable(Name, Bool)
- if (Name) == nil then
- return false
- end
- for i, v in Mechanics.Variables do
- if (string.lower(i) == string.lower(Name)) then
- Mechanics.Variables[i] = Bool
- return true
- end
- end
- warn('[MECHANICS]; Variable; ' .. Name .. ' wasnt found (:SetVariable)')
- return 0;
- end
- function Mechanics:GetVariable(Name)
- if (Name) == nil then
- return false
- end
- for i, v in Mechanics.Variables do
- if (string.lower(i) == string.lower(Name)) then
- return v
- end
- end
- warn('[MECHANICS]; Variable; ' .. Name .. ' wasnt found (:GetVariable)')
- return 0;
- end
- -- Client Actions
- function Mechanics:SwitchFoot()
- if (Mechanics:GetVariable('Leg') == 'Right') then
- Mechanics:SetVariable('Leg', 'Left')
- return true, Mechanics:SwitchFootUIToggle('L')
- end
- Mechanics:SetVariable('Leg', 'Right')
- return true, Mechanics:SwitchFootUIToggle('R')
- end
- function Mechanics:SwitchFootUIToggle(Leg)
- Resources.Functions['PlaySound']('Hover', 'Squirm', nil, Resources['_G']["Tool Sound FX"])
- TweensModule:Pause('Foot Indicators', string.upper(Leg))
- InterfaceGUI:FindFirstChild('Buttons').Main.Foot.Text = string.upper(Leg)
- --ToolsGUI['L'].TextTransparency = 1
- --ToolsGUI['R'].TextTransparency = 1
- ToolsGUI[string.upper(Leg)].TextTransparency = 0
- TweensModule:Play('Foot Indicators', string.upper(Leg))
- return true
- end
- -- Proper Catch Checks
- -- Debug Prints
- function Mechanics.TestDebugPrint(s)
- if (Resources['_G']['Test Print Debug']) then
- return warn(s)
- end
- return false
- end
- function Mechanics.DebugPrints(s)
- if (Resources['_G']['Print Debug']) then
- return print(s)
- end
- return false
- end
- -- React Check
- function Mechanics.IsSecondTouch(Ball : Part)
- if (Ball == nil) then
- return true -- basically true = second touching, ball is nil so return true so the game doesnt process
- elseif (Ball:FindFirstChild('Second Touch')) and (Ball['Second Touch'].Value ~= LocalPlayer) then
- Mechanics.TestDebugPrint('[MECHANICS]; Second touch detected')
- return true
- end
- return false
- end
- function Mechanics.IsReach(Ball :Part)
- if (Ball == nil) then
- return true -- basically true = is reaching, ball is nil so return true so the game doesnt process
- end
- if (LocalPlayer.Character == nil) then
- return true
- end
- local Character = LocalPlayer.Character
- local HRP = Character:FindFirstChild('HumanoidRootPart')
- if (HRP == nil) then
- return true
- end
- local Velocity = (Ball.AssemblyLinearVelocity.Magnitude)
- Velocity = math.abs(Velocity)
- local Distance = (Ball.Position - HRP.Position).Magnitude
- Distance = math.abs(Distance)
- if (Distance > 5.3 and Velocity < 28) then
- Mechanics.TestDebugPrint('[MECHANICS]; Reach detected due to high distance')
- return true
- end
- return false
- end
- function Mechanics.CanReact(Ball : Part)
- if (Ball == nil) then
- return false
- elseif (LocalPlayer.Character == nil) then
- return false
- end
- local Anchored = Ball:GetAttribute('Anchored')
- local Held = Ball:GetAttribute('Held')
- if (Anchored == true) then
- Mechanics.TestDebugPrint('[MECHANICS]; Ball is attributed as anchored (CanReact)')
- return false
- end
- if (Held ~= 0) then
- Mechanics.TestDebugPrint('[MECHANICS]; Ball is attributed as held (CanReact)')
- return false
- end
- return true
- end
- -- React Functions
- function Mechanics:Rainbow(Bind, Instances, Package, Magnus)
- if (Bind and Instances and Package) == nil then
- return false
- end
- local Ball, Limb, CDPreset = unpack(Instances)
- local MaxForce, Direction, Power, Height = unpack(Package)
- if (Ball and MaxForce and Power and Height) == nil then
- return false
- end
- if not (Mechanics.CanReact(Ball)) then
- return false
- end
- for _, v in Ball:GetChildren() do
- if (v:IsA('BodyVelocity') or v:IsA('BodyAngularVelocity') or v:IsA('BodyForce')) then
- v:Destroy()
- end
- end
- local IsOwner = Ball:GetAttribute('Owner') == LocalPlayer.UserId
- local SecondTouchCD = SecondTouches[CDPreset] or SecondTouches['Default']
- local BCFrame = Ball.CFrame
- if not IsOwner then
- if (Mechanics.IsSecondTouch(Ball)) then
- return false
- elseif (Mechanics.IsReach(Ball)) then
- return false
- elseif not Resources['Remotes']:FindFirstChild('Call Network'):InvokeServer(Ball, SecondTouchCD) then
- return false, task.spawn(function()
- table.clear(Instances)
- table.clear(Package)
- if (string.lower(typeof(Magnus)) == 'table') then
- table.clear(Magnus)
- end
- end)
- end
- if (Ball.AssemblyLinearVelocity.Magnitude) > 35 then
- Ball.AssemblyLinearVelocity = Vector3.zero
- end
- end
- task.delay(0.12, function()
- if (Direction[1] and Direction[2]) == nil then
- return false
- end
- --if not (MaxForce.X == 0 and MaxForce.Z == 0) then
- -- Ball.AssemblyLinearVelocity = Vector3.zero
- --end
- local BodyVelocity = Instance.new('BodyVelocity')
- BodyVelocity.MaxForce = MaxForce
- BodyVelocity.Velocity = (Direction[1].CFrame * Direction[2]).LookVector * Power
- BodyVelocity.Velocity = BodyVelocity.Velocity * Vector3.new(1, 0, 1)
- BodyVelocity.Velocity = BodyVelocity.Velocity + Height
- BodyVelocity.Parent = Ball
- Debris:AddItem(BodyVelocity, 0.3)
- local Volume = (BodyVelocity.Velocity.Magnitude / 60)
- if Volume < 0.1 then
- Volume = 0.1
- end
- if (Resources['_G']['Ball Sound FX']) and (Ball:FindFirstChild('Sounds') and Ball.Sounds:FindFirstChild('Kick')) then
- Ball.Sounds['Kick']:Pause()
- Ball.Sounds['Kick'].TimePosition = 0
- Ball.Sounds['Kick'].Volume = Volume
- Ball.Sounds['Kick']:Play()
- end
- Resources['Remotes']:FindFirstChild('Ball Debug'):FireServer('Ball Sounds', Ball, 'Kick', Volume)
- return true
- end)
- return true
- end
- function Mechanics:React(Bind, Instances, Package, Magnus)
- if (Bind and Instances and Package) == nil then
- return false
- end
- local Ball, Limb, CDPreset = unpack(Instances)
- local MaxForce, Power, Height = unpack(Package)
- if (Ball and MaxForce and Power and Height) == nil then
- return false
- end
- if not (Mechanics.CanReact(Ball)) then
- return false
- end
- for _, v in Ball:GetChildren() do
- if (v:IsA('BodyVelocity') or v:IsA('BodyAngularVelocity') or v:IsA('BodyForce')) then
- v:Destroy()
- end
- end
- local IsOwner = Ball:GetAttribute('Owner') == LocalPlayer.UserId
- local SecondTouchCD = SecondTouches[CDPreset] or SecondTouches['Default']
- if not (MaxForce.X == 0 and MaxForce.Z == 0) then
- Ball.AssemblyLinearVelocity = Vector3.zero
- end
- local BodyVelocity = Instance.new('BodyVelocity')
- BodyVelocity.MaxForce = MaxForce
- BodyVelocity.Velocity = Power
- BodyVelocity.Velocity = BodyVelocity.Velocity * Vector3.new(1, 0, 1)
- BodyVelocity.Velocity = BodyVelocity.Velocity + Height
- BodyVelocity.Parent = Ball
- Debris:AddItem(BodyVelocity, 0.3)
- local BCFrame = Ball.CFrame
- if not IsOwner then
- if (Mechanics.IsSecondTouch(Ball)) then
- return false
- elseif (Mechanics.IsReach(Ball)) then
- return false
- elseif not Resources['Remotes']:FindFirstChild('Call Network'):InvokeServer(Ball, SecondTouchCD) then
- return false, task.spawn(function()
- BodyVelocity:Destroy()
- table.clear(Instances)
- table.clear(Package)
- if (string.lower(typeof(Magnus)) == 'table') then
- table.clear(Magnus)
- end
- end)
- end
- end
- local Volume = (BodyVelocity.Velocity.Magnitude / 60)
- if Volume < 0.1 then
- Volume = 0.1
- end
- if (Resources['_G']['Ball Sound FX']) and (Ball:FindFirstChild('Sounds') and Ball.Sounds:FindFirstChild('Kick')) then
- Ball.Sounds['Kick']:Pause()
- Ball.Sounds['Kick'].TimePosition = 0
- Ball.Sounds['Kick'].Volume = Volume
- Ball.Sounds['Kick']:Play()
- end
- Resources['Remotes']:FindFirstChild('Ball Debug'):FireServer('Ball Sounds', Ball, 'Kick', Volume)
- if not IsOwner then
- Resources['Remotes']:FindFirstChild('Ball Debug'):FireServer('React Bubble', Ball, BCFrame, 'Player')
- end
- return true
- end
- --// Reset Handler
- Resources['Functions'].Wrap_PRINTS(function()
- Mechanics:Reset()
- LocalPlayer.CharacterAdded:Connect(function()
- return Mechanics:Reset()
- end)
- return true
- end)
- return Mechanics
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement