Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- BORING BORING GERMAN BORING
- What is this file? -This file is the actual shoot-em-up file. It spawns
- projectiles and registers damage.
- ]]
- -- imported variables
- local tool = script.Parent
- local variablesFile = tool:WaitForChild("Properties")
- local damageValue = variablesFile:WaitForChild("damageValue")
- print(damageValue, damageValue.Value)
- local fireEvent = tool.fireEvent
- local muzzlePoint = tool.Muzzle.muzzlePoint
- local FastCast = require(game.ReplicatedStorage.Dependencies.FastCastRedux)
- local PartCache = require(game.ReplicatedStorage.Dependencies.PartCache)
- local bulletsFolder = tool.Bullets
- local bulletTemplate = bulletsFolder.gen1Bullet
- -- Getting data from "properties"
- -- FastCast.VisualizeCasts = true
- local caster = FastCast.new()
- local castParams = RaycastParams.new()
- castParams.FilterType = Enum.RaycastFilterType.Exclude
- castParams.IgnoreWater = false
- local bulletCache = PartCache.new(bulletTemplate, 100, bulletsFolder)
- local castBehaviour = FastCast.newBehavior()
- castBehaviour.RaycastParams = castParams
- castBehaviour.Acceleration = Vector3.new(0, -workspace.Gravity, 0) -- gravity bullet drop
- castBehaviour.AutoIgnoreContainer = true
- castBehaviour.CosmeticBulletContainer = bulletsFolder
- castBehaviour.CosmeticBulletProvider = bulletCache
- local function onEquipped()
- castParams.FilterDescendantsInstances = {tool.Parent, bulletsFolder}
- end
- local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
- if bullet then
- local bulletLength = bullet.Size.Z/2
- local offset = CFrame.new(0, 0, -(length - bulletLength))
- bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
- end
- end
- local function onHit(cast, result, velocity, bullet)
- local hit = result.Instance
- local damage = damageValue.Value
- local character = hit:FindFirstAncestorWhichIsA("Model")
- local humanoid = character:FindFirstChild("Humanoid")
- print(script.Parent)
- print(script.Parent.Parent)
- print(damage)
- print(hit) --prints the part which the bullet hitted.
- if humanoid and hit.Name == "Head" then
- character.Humanoid:TakeDamage(damage)
- elseif humanoid and hit.Name == "LowerTorso" or humanoid and hit.Name == "UpperTorso" or humanoid and hit.Name == "HumanoidRootPart" then
- character.Humanoid:TakeDamage(damage)
- elseif humanoid then
- character.Humanoid:TakeDamage(damage)
- end
- bulletCache:ReturnPart(bullet)
- end
- local function fire(player, mousePosition)
- local origin = muzzlePoint.WorldPosition
- local direction = (mousePosition - origin).Unit
- caster:Fire(origin, direction, 1000, castBehaviour) -- 3rd argument's velocity
- end
- fireEvent.OnServerEvent:Connect(fire)
- tool.Equipped:Connect(onEquipped)
- caster.LengthChanged:Connect(onLengthChanged)
- caster.RayHit:Connect(onHit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement