Advertisement
HowToRoblox

FireballClient

Nov 15th, 2022
1,793
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.34 KB | None | 0 0
  1. local rs = game.ReplicatedStorage:WaitForChild("FireballReplicatedStorage")
  2.  
  3. local re = rs:WaitForChild("RemoteEvent")
  4. local config = require(rs:WaitForChild("CONFIGURATION"))
  5.  
  6. local cas = game:GetService("ContextActionService")
  7. local mobileButtonDown = false
  8. local mouse = game.Players.LocalPlayer:GetMouse()
  9. local camera = workspace.CurrentCamera
  10.  
  11. local char = script.Parent
  12. local humanoid = char:WaitForChild("Humanoid")
  13.  
  14. local clientStart = tick()
  15. local clientDebounce = false
  16.  
  17. local blurEffect = Instance.new("BlurEffect")
  18. blurEffect.Size = 0
  19. blurEffect.Parent = game.Lighting
  20.  
  21. local cameraTrauma = 0
  22. local shakeSeed = Random.new():NextNumber()
  23. local shakeIterator = 0
  24.  
  25.  
  26. function disableParticles(part)
  27.     for i, child in pairs(part:GetChildren()) do
  28.         if child:IsA("ParticleEmitter") then
  29.             child.Enabled = false
  30.         end
  31.     end
  32. end
  33.  
  34. function cameraShake(epicentre)
  35.    
  36.     if typeof(epicentre) == "Vector3" then
  37.         cameraTrauma = math.clamp(40/(char.HumanoidRootPart.Position - epicentre).Magnitude, 0, 2)
  38.     else
  39.         cameraTrauma = epicentre
  40.     end
  41.  
  42.     shakeIterator = 0
  43.     shakeSeed = Random.new():NextNumber()
  44. end
  45.  
  46.  
  47. function explosion(explosionPos)
  48.     local newExplosion = Instance.new("Part")
  49.     newExplosion.Anchored = true
  50.     newExplosion.Transparency = 1
  51.     newExplosion.Position = explosionPos
  52.  
  53.     newExplosion.Parent = workspace
  54.  
  55.     local explosionPhase1 = rs.FireballParts.Explosion.ExplosionPhase1:Clone()
  56.     explosionPhase1.Parent = newExplosion
  57.  
  58.     task.wait(0.5)
  59.  
  60.     local explosionPhase1Debris = rs.FireballParts.Explosion.ExplosionPhase1Debris:Clone()
  61.     explosionPhase1Debris.Parent = newExplosion
  62.  
  63.     task.wait(0.3)
  64.     disableParticles(explosionPhase1)
  65.     disableParticles(explosionPhase1Debris)
  66.    
  67.     local explosionLight = rs.FireballParts.Explosion.ExplosionLight:Clone()
  68.     explosionLight.Parent = newExplosion
  69.  
  70.     local explosionSound = rs:WaitForChild("Sounds"):WaitForChild("Explosion"):Clone()
  71.     explosionSound.Parent = newExplosion
  72.     explosionSound:Play()
  73.  
  74.     local explosionPhase2 = rs.FireballParts.Explosion.ExplosionPhase2:Clone()
  75.     explosionPhase2.Parent = newExplosion
  76.     local explosionPhase3 = rs.FireballParts.Explosion.ExplosionPhase3:Clone()
  77.     explosionPhase3.Parent = newExplosion
  78.    
  79.     cameraShake(explosionPos)
  80.  
  81.     task.wait(0.1)
  82.     disableParticles(explosionPhase2)
  83.     disableParticles(explosionPhase3)
  84.  
  85.     local explosionPhase3Debris = rs.FireballParts.Explosion.ExplosionPhase3Debris:Clone()
  86.     explosionPhase3Debris.Parent = newExplosion
  87.  
  88.     task.wait(0.3)
  89.     disableParticles(explosionPhase3Debris)
  90.  
  91.     task.wait(0.2)
  92.     newExplosion:Destroy()
  93. end
  94.  
  95.  
  96. function handleInput(actionName, inputState, inputObject)
  97.    
  98.     if actionName ~= "FIREBALL" or inputState ~= Enum.UserInputState.End or clientDebounce then return end
  99.    
  100.     if inputObject.KeyCode == config.hotkey then
  101.         clientDebounce = true
  102.        
  103.         re:FireServer(mouse.Hit)
  104.  
  105.         task.wait(config.cooldown)
  106.         clientDebounce = false
  107.        
  108.     elseif inputObject.UserInputType == Enum.UserInputType.Touch then
  109.         mobileButtonDown = not mobileButtonDown
  110.     end
  111. end
  112.  
  113. function fireMobile(actionName, inputState, inputObject)
  114.    
  115.     if actionName == "FIREBALL MOBILE" and inputState == Enum.UserInputState.End and not clientDebounce then
  116.    
  117.         if mobileButtonDown then
  118.             clientDebounce = true
  119.             mobileButtonDown = false
  120.  
  121.             re:FireServer(mouse.Hit)
  122.  
  123.             task.wait(config.cooldown)
  124.             clientDebounce = false
  125.            
  126.         else
  127.             return Enum.ContextActionResult.Pass
  128.         end
  129.     else
  130.         return Enum.ContextActionResult.Pass
  131.     end
  132. end
  133.  
  134. cas:BindAction("FIREBALL", handleInput, true, config.hotkey)
  135.  
  136. cas:BindAction("FIREBALL MOBILE", fireMobile, false, Enum.UserInputType.Touch)
  137.  
  138. cas:SetImage("FIREBALL", "rbxassetid://11565509890")
  139. cas:SetPosition("FIREBALL", UDim2.new(0.63, 0, 0.12, 0))
  140.  
  141.  
  142. re.OnClientEvent:Connect(function(instruction, data)
  143.    
  144.     if instruction == "camera shake" then
  145.         cameraShake(data[1])
  146.        
  147.        
  148.     elseif instruction == "fireball" then
  149.        
  150.         local charShooting = data[3]
  151.        
  152.         local p0 = data[1]
  153.         local p2 = data[2]
  154.        
  155.         local distance = (p0 - p2).Magnitude
  156.         local travelTime = distance / config.fireballSpeed
  157.        
  158.         local randomX = Random.new():NextNumber(config.minFireballOffset, config.maxFireballOffset) * (distance/100)
  159.         randomX *= Random.new():NextNumber() > 0.5 and -1 or 1
  160.        
  161.         local randomY = Random.new():NextNumber(config.minFireballOffset, config.maxFireballOffset) * (distance/100)
  162.         randomY *= Random.new():NextNumber() > 0.5 and -1 or 1
  163.        
  164.         local randomZ = Random.new():NextNumber(config.minFireballOffset, config.maxFireballOffset) * (distance/100)
  165.         randomZ *= Random.new():NextNumber() > 0.5 and -1 or 1
  166.        
  167.         local p1 = p0:Lerp(p2, 0.5) + Vector3.new(randomX, randomY, randomZ)
  168.        
  169.         local newFireball = rs:WaitForChild("FireballParts"):WaitForChild("Fireball"):Clone()
  170.         newFireball.CanCollide = false
  171.         newFireball.Anchored = true
  172.        
  173.         newFireball.Parent = workspace
  174.        
  175.         local shootSound = rs:WaitForChild("Sounds"):WaitForChild("Shoot"):Clone()
  176.         shootSound.Parent = charShooting.HumanoidRootPart
  177.         shootSound:Play()
  178.        
  179.         shootSound.Ended:Connect(function()
  180.             shootSound:Destroy()
  181.         end)
  182.        
  183.         local increments = travelTime / game:GetService("RunService").Heartbeat:Wait()
  184.        
  185.         for i = 1, increments do
  186.             local p0Pos = p0:Lerp(p1, i/increments)
  187.             local p1Pos = p1:Lerp(p2, i/increments)
  188.                
  189.             local curvePos = p0Pos:Lerp(p1Pos, i/increments)
  190.             newFireball.Position = curvePos
  191.            
  192.             if i == math.floor(increments * 0.56) then
  193.                 task.spawn(explosion, p2)
  194.             end
  195.  
  196.             game:GetService("RunService").Heartbeat:Wait()
  197.         end
  198.        
  199.         newFireball:Destroy()
  200.     end
  201. end)
  202.  
  203.  
  204. game:GetService("RunService").RenderStepped:Connect(function()
  205.    
  206.     if cameraTrauma > 0 then
  207.        
  208.         local now = tick() - clientStart
  209.         shakeIterator += 1
  210.  
  211.         local shake = (cameraTrauma ^ 2)
  212.  
  213.         local noiseX = (math.noise(shakeIterator, now, shakeSeed)) * shake
  214.         local noiseY = (math.noise(shakeIterator + 1, now, shakeSeed)) * shake
  215.         local noiseZ = (math.noise(shakeIterator + 2 + 1, now, shakeSeed)) * shake
  216.  
  217.         humanoid.CameraOffset = Vector3.new(noiseX, noiseY, noiseZ)
  218.         camera.CFrame = camera.CFrame * CFrame.Angles(noiseX / 50, noiseY / 50, noiseZ / 50)
  219.  
  220.         blurEffect.Size = shake * 12
  221.  
  222.         local falloffSpeed = 1.6
  223.         cameraTrauma = math.clamp(cameraTrauma - falloffSpeed * game:GetService("RunService").Heartbeat:Wait(), 0, 3)
  224.        
  225.     else
  226.         humanoid.CameraOffset = Vector3.new(0, 0, 0)
  227.     end
  228. end)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement