Advertisement
Mr-Nightmare1

Untitled

Apr 29th, 2024
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.89 KB | Source Code | 0 0
  1. --!strict
  2.  
  3. local Combat = {}
  4. Combat.__index = Combat
  5.  
  6. local replicatedStorage = game:GetService("ReplicatedStorage")
  7. local tweenService = game:GetService("TweenService")
  8. local debris = game:GetService("Debris")
  9. local players = game:GetService("Players")
  10.  
  11. local network = replicatedStorage.Network
  12. -- local clientReplicator = network.ClientReplicator
  13. local clickRemote = network.Click
  14. local playSound = network.PlaySound
  15.  
  16. local serverStorage = script.Parent
  17. local packages = require(serverStorage.Packages.CombatPackages)
  18.  
  19. local hitboxesFolder = workspace.Hitboxes
  20. local vfxFolder = workspace.VFX
  21.  
  22. type CombatPackage = {
  23.     idleAnimation: string,
  24.     attackAnimation: string,
  25.     damage: number,
  26.     vfx: Part?,
  27.     hitbox: Part,
  28. }
  29.  
  30. local admins = {
  31.     1303772257,
  32. }
  33.  
  34. local skillTimes = {
  35.     G1 = tick()
  36. }
  37.  
  38. local skillCooldowns = {
  39.     G1 = 3.75
  40. }
  41.  
  42. function Combat.new(player)
  43.  
  44.     local status = ""
  45.     if table.find(admins, player.UserId) then
  46.         status = "Admin"
  47.     else
  48.         status = "Player"
  49.     end
  50.     return setmetatable({
  51.  
  52.         _status = status,
  53.         _user = player,
  54.         _indexAttempts = {},
  55.         _defaultSpeed = 16,
  56.         __call = function(...)
  57.             return {...}
  58.         end,
  59.         __index = function(self, index, value)
  60.             self._indexAttempts[index] = value
  61.         end,
  62.     }, Combat)
  63. end
  64.  
  65. --[[
  66. (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2
  67. --]]
  68.  
  69. function Combat:MovementControl(bool: boolean)
  70.  
  71.     local player = self._user
  72.     local character = player.Character or player.CharacterAdded:Wait()
  73.     local humanoid = character:WaitForChild("Humanoid")
  74.  
  75.     if bool then
  76.         humanoid.WalkSpeed = 0
  77.     else
  78.         humanoid.WalkSpeed = self._defaultSpeed
  79.     end
  80. end
  81.  
  82. function Combat:AddHitbox(position: Vector3, package: CombatPackage)
  83.  
  84.     local hitbox = package.hitbox:Clone()
  85.     hitbox.Position = position
  86.     hitbox.Parent = hitboxesFolder
  87.  
  88.     local taggedHumanoids = {}
  89.     for _, part in workspace:GetPartsInPart(hitbox) do
  90.  
  91.         local character = part.Parent
  92.         local humanoid = character:FindFirstChildOfClass("Humanoid")
  93.         if humanoid then
  94.  
  95.             local player = players:GetPlayerFromCharacter(character)
  96.             if player then
  97.                 if player == self._user then
  98.                     continue
  99.                 end
  100.             end
  101.            
  102.             if not (table.find(taggedHumanoids, humanoid)) then
  103.                
  104.                 table.insert(taggedHumanoids, humanoid)
  105.                 humanoid:TakeDamage(package.damage)
  106.             end
  107.         end
  108.     end
  109. end
  110.  
  111. function Combat:G1()
  112.  
  113.     if tick() - skillTimes.G1 > skillCooldowns.G1 then
  114.  
  115.         local package = packages.G1
  116.         local vfx = package.vfx
  117.        
  118.         local player = self._user
  119.         local character = player.Character or player.CharacterAdded:Wait()
  120.         local humanoid = character:WaitForChild("Humanoid")
  121.         local animator = humanoid.Animator
  122.  
  123.         local animation = Instance.new("Animation")
  124.         animation.AnimationId = package.idleAnimation
  125.  
  126.         local track = animator:LoadAnimation(animation)
  127.         track:Play()
  128.  
  129.         self:MovementControl(true)
  130.  
  131.         local function characterPosition(characterPart: string, other: Part)
  132.            
  133.             local foundPart: Part = character:FindFirstChild(characterPart)
  134.             if foundPart then
  135.                
  136.                 local pos = foundPart.Position + foundPart.CFrame.UpVector*6
  137.                 other.Position = pos
  138.  
  139.                 local constraint = Instance.new("WeldConstraint")
  140.                 constraint.Part0 = other
  141.                 constraint.Part1 = foundPart
  142.  
  143.                 other.Massless = true
  144.                 other.CanCollide = false
  145.                 other.Anchored = true
  146.  
  147.                 other.Parent = foundPart
  148.             end
  149.         end
  150.  
  151.         repeat
  152.             task.wait(.01)
  153.         until
  154.             track.IsPlaying
  155.  
  156.         local red, white = vfx.Red:Clone(), vfx.White:Clone()
  157.         characterPosition("Left Arm", red)
  158.         characterPosition("Right Arm", white)
  159.  
  160.         playSound:FireClient(player, "Fireball")
  161.         task.delay(.15, function()
  162.             playSound:FireClient(player, "Fireball")
  163.         end)
  164.        
  165.         local cooldown = tick()
  166.  
  167.         local firstPosition, secondPosition
  168.         local c = clickRemote.OnServerEvent:Connect(function(playerThatFired, pos1: Vector3, pos2: Vector3)
  169.            
  170.             if tick()-cooldown > .3 then
  171.                 firstPosition = pos1
  172.                 secondPosition = pos2
  173.  
  174.                 if playerThatFired == player then
  175.  
  176.                     print(pos1, pos2)
  177.                     self:MovementControl(true)
  178.  
  179.                     for _, foundTrack in animator:GetPlayingAnimationTracks() do
  180.                         foundTrack:Stop()
  181.                     end
  182.                 end
  183.             end
  184.         end)
  185.  
  186.         track.Ended:Wait()
  187.         c:Disconnect()
  188.  
  189.         local attackAnimation = Instance.new("Animation")
  190.         attackAnimation.AnimationId = package.attackAnimation
  191.  
  192.         -- task.wait()
  193.  
  194.         track = animator:LoadAnimation(attackAnimation)
  195.         track:Play()
  196.  
  197.         local tween1 = tweenService:Create(red, TweenInfo.new(.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Position = firstPosition})
  198.         local tween2 = tweenService:Create(white, TweenInfo.new(.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Position = secondPosition})
  199.  
  200.         local strike = vfx.Strike
  201.         local slam = vfx.Slam
  202.         track:GetMarkerReachedSignal("HitOne"):Connect(function()
  203.            
  204.             tween1:Play()
  205.             playSound:FireClient(player, "Throw")
  206.             tween1.Completed:Wait()
  207.             playSound:FireClient(player, "Explosion")
  208.             local newStrike = strike:Clone()
  209.  
  210.             local goodPosition
  211.             local result = workspace:Raycast(firstPosition, -red.CFrame.UpVector*100)
  212.             if result and result.Instance then
  213.                
  214.                 goodPosition = result.Position
  215.             end
  216.             red:Destroy()
  217.  
  218.             local actualPosition = goodPosition or firstPosition
  219.             newStrike.Position = actualPosition
  220.             newStrike.Parent = vfxFolder
  221.  
  222.             local newSlam = slam:Clone()
  223.             newSlam.Position = actualPosition - Vector3.new(0, newSlam.Size.Y, 0)
  224.             newSlam.Parent = vfxFolder
  225.  
  226.             local riseTween = tweenService:Create(newSlam, TweenInfo.new(.25, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Position = actualPosition})
  227.             riseTween:Play()
  228.  
  229.             debris:AddItem(newStrike, .5)
  230.             debris:AddItem(newSlam, 1)
  231.             self:AddHitbox(actualPosition, package)
  232.         end)
  233.  
  234.         track:GetMarkerReachedSignal("HitTwo"):Connect(function()
  235.            
  236.             task.wait()
  237.             print("tweentwo")
  238.             tween2:Play()
  239.             playSound:FireClient(player, "Throw")
  240.             tween2.Completed:Wait()
  241.             playSound:FireClient(player, "Explosion")
  242.             local newStrike = strike:Clone()
  243.  
  244.             local goodPosition
  245.             local result = workspace:Raycast(secondPosition, -white.CFrame.UpVector*100)
  246.             if result and result.Instance then
  247.                
  248.                 goodPosition = result.Position
  249.             end
  250.             white:Destroy()
  251.  
  252.             local actualPosition = goodPosition or secondPosition
  253.             newStrike.Position = actualPosition
  254.             newStrike.Parent = vfxFolder
  255.  
  256.             local newSlam = slam:Clone()
  257.             newSlam.Position = actualPosition - Vector3.new(0, newSlam.Size.Y, 0)
  258.             newSlam.Parent = vfxFolder
  259.  
  260.             local riseTween = tweenService:Create(newSlam, TweenInfo.new(.25, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Position = actualPosition})
  261.             riseTween:Play()
  262.  
  263.             debris:AddItem(newStrike, .5)
  264.             debris:AddItem(newSlam, 1)
  265.             self:AddHitbox(actualPosition, package)
  266.         end)
  267.  
  268.         track.Ended:Wait()
  269.         self:MovementControl(false)
  270.  
  271.         skillTimes.G1 = tick()
  272.     end
  273. end
  274.  
  275. return Combat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement