local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Gun = require(ReplicatedStorage.Modules.Client.Controllers.GunController)
local BulletController = require(ReplicatedStorage.Modules.Client.Controllers.BulletController)
local SpreadUtil = require(ReplicatedStorage.Modules.Shared.SpreadUtil)
local LocalPlayer = Players.LocalPlayer
local fov = 120
local maxDist = 2000
local wallcheck = true
local target, targetPart
local sg = LocalPlayer.PlayerGui:FindFirstChild("ScreenGui")
if sg and sg:FindFirstChild("LocalScript") then sg.LocalScript:Destroy() end
local CameraPOV
pcall(function()
CameraPOV = require(ReplicatedStorage.Modules.Client.CameraPOV)
end)
local fovCircle = Drawing.new("Circle")
fovCircle.Filled = false
fovCircle.Thickness = 1
fovCircle.Color = Color3.new(1, 1, 1)
local wallParams = RaycastParams.new()
wallParams.FilterType = Enum.RaycastFilterType.Exclude
wallParams.IgnoreWater = true
local discharge = BulletController.Discharge
BulletController.Discharge = function(self, weapon, eyePos, fireDir, muzzleCf, ...)
if Gun.FireHeld and target then
local origin = muzzleCf and muzzleCf.Position or eyePos or Gun:GetMuzzleWorldCFrame().Position
fireDir = (target - origin).Unit
local ret = { discharge(self, weapon, eyePos, fireDir, muzzleCf, ...) }
return table.unpack(ret)
end
return discharge(self, weapon, eyePos, fireDir, muzzleCf, ...)
end
local randomCone = SpreadUtil.RandomConeDirection
SpreadUtil.RandomConeDirection = function(dir, ...)
if Gun.FireHeld and target then return dir end
return randomCone(dir, ...)
end
RunService.PreRender:Connect(function()
target, targetPart = nil, nil
local camera = workspace.CurrentCamera
local center = camera.ViewportSize / 2
fovCircle.Position = center
fovCircle.Radius = fov
fovCircle.Visible = true
local eyePos = CameraPOV and CameraPOV.GetEyePosition and CameraPOV.GetEyePosition() or camera.CFrame.Position
local mercs = workspace:FindFirstChild("MercPlayers")
if not mercs then return end
local bestHead, bestDist = nil, fov
for _, player in Players:GetPlayers() do
if player ~= LocalPlayer then
local hitboxes = mercs:FindFirstChild("MercHitboxes_" .. player.Name)
if hitboxes and not hitboxes:GetAttribute("Dead") then
local head = hitboxes:FindFirstChild("Head")
if head and (head.Position - eyePos).Magnitude <= maxDist then
local aim = head.Position + Vector3.new(0, head.Size.Y * 0.15, 0)
local clear = true
if wallcheck then
wallParams.FilterDescendantsInstances = { LocalPlayer.Character, camera, mercs }
clear = workspace:Raycast(eyePos, aim - eyePos, wallParams) == nil
end
if clear then
local scr, vis = camera:WorldToViewportPoint(head.Position)
if vis and scr.Z > 0 then
local px = (Vector2.new(scr.X, scr.Y) - center).Magnitude
if px < bestDist then
bestDist = px
bestHead = head
end
end
end
end
end
end
end
if bestHead then
targetPart = bestHead
target = bestHead.Position + Vector3.new(0, bestHead.Size.Y * 0.15, 0)
end
end)
Comments
No comments yet
Be the first to share your thoughts!