-- 子弹追踪脚本 v2.0 -- 支持多种游戏和武器类型 -- 包含可视化设置和性能优化 -- 服务声明 local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local Workspace = game:GetService("Workspace") local HttpService = game:GetService("HttpService") -- 本地玩家 local LocalPlayer = Players.LocalPlayer local Camera = Workspace.CurrentCamera -- 配置设置 local Settings = { Enabled = true, TeamCheck = true, WallCheck = true, MaxDistance = 500, MaxAngle = math.rad(15), -- 最大偏转角 (弧度) Smoothing = 0.3, -- 平滑系数 (0-1) TargetPart = "Head", -- 目标部位 FOV = 60, -- 视野半径 Prediction = true, -- 预测目标移动 PredictionStrength = 0.5, -- 预测强度 Visualize = true, -- 可视化追踪线 VisualColor = Color3.new(1, 0, 0), VisualTransparency = 0.7, VisualThickness = 0.5, VisualLife = 0.5, ExcludedNPCs = {"Drone", "Turret"} -- 排除的NPC类型 } -- 创建UI local Rayfield = loadstring(game:HttpGet('https://raw.githubusercontent.com/shlexware/Rayfield/main/source'))() local Window = Rayfield:CreateWindow({ Name = "子弹追踪脚本", LoadingTitle = "高级子弹追踪系统", LoadingSubtitle = "by 脚本开发者", ConfigurationSaving = { Enabled = true, FolderName = "BulletTracker", FileName = "Settings.json" }, Discord = { Enabled = false, Invite = "noinvitelink", RememberJoins = true } }) -- 主标签 local MainTab = Window:CreateTab("主设置") MainTab:CreateToggle({ Name = "启用子弹追踪", CurrentValue = Settings.Enabled, Flag = "EnableTracker", Callback = function(Value) Settings.Enabled = Value end }) MainTab:CreateToggle({ Name = "队友检测", CurrentValue = Settings.TeamCheck, Flag = "TeamCheck", Callback = function(Value) Settings.TeamCheck = Value end }) MainTab:CreateToggle({ Name = "墙体检测", CurrentValue = Settings.WallCheck, Flag = "WallCheck", Callback = function(Value) Settings.WallCheck = Value end }) MainTab:CreateToggle({ Name = "移动预测", CurrentValue = Settings.Prediction, Flag = "Prediction", Callback = function(Value) Settings.Prediction = Value end }) MainTab:CreateToggle({ Name = "可视化追踪线", CurrentValue = Settings.Visualize, Flag = "Visualize", Callback = function(Value) Settings.Visualize = Value end }) -- 视觉标签 local VisualTab = Window:CreateTab("视觉设置") VisualTab:CreateSlider({ Name = "最大距离", Range = {10, 1000}, Increment = 10, Suffix = "单位", CurrentValue = Settings.MaxDistance, Flag = "MaxDistance", Callback = function(Value) Settings.MaxDistance = Value end }) VisualTab:CreateSlider({ Name = "最大偏转角", Range = {1, 45}, Increment = 1, Suffix = "度", CurrentValue = math.deg(Settings.MaxAngle), Flag = "MaxAngle", Callback = function(Value) Settings.MaxAngle = math.rad(Value) end }) VisualTab:CreateSlider({ Name = "平滑系数", Range = {0, 1}, Increment = 0.01, CurrentValue = Settings.Smoothing, Flag = "Smoothing", Callback = function(Value) Settings.Smoothing = Value end }) VisualTab:CreateSlider({ Name = "预测强度", Range = {0, 1}, Increment = 0.05, CurrentValue = Settings.PredictionStrength, Flag = "PredictionStrength", Callback = function(Value) Settings.PredictionStrength = Value end }) VisualTab:CreateSlider({ Name = "视野半径", Range = {10, 360}, Increment = 5, Suffix = "单位", CurrentValue = Settings.FOV, Flag = "FOV", Callback = function(Value) Settings.FOV = Value end }) VisualTab:CreateColorPicker({ Name = "追踪线颜色", Color = Settings.VisualColor, Flag = "VisualColor", Callback = function(Value) Settings.VisualColor = Value end }) VisualTab:CreateSlider({ Name = "追踪线透明度", Range = {0, 1}, Increment = 0.05, CurrentValue = Settings.VisualTransparency, Flag = "VisualTransparency", Callback = function(Value) Settings.VisualTransparency = Value end }) -- 目标设置标签 local TargetTab = Window:CreateTab("目标设置") TargetTab:CreateDropdown({ Name = "目标部位", Options = {"Head", "Torso", "Random", "Nearest"}, CurrentOption = Settings.TargetPart, Flag = "TargetPart", Callback = function(Option) Settings.TargetPart = Option end }) TargetTab:CreateInput({ Name = "排除NPC类型", PlaceholderText = "逗号分隔, 如: Drone,Turret", RemoveTextAfterFocusLost = false, Callback = function(Text) Settings.ExcludedNPCs = {} for word in Text:gmatch("([^,]+)") do table.insert(Settings.ExcludedNPCs, word:trim()) end end }) -- 功能函数 local function isNPC(character) return character:FindFirstChild("NPC") or not Players:GetPlayerFromCharacter(character) end local function shouldExclude(character) if not isNPC(character) then return false end for _, name in ipairs(Settings.ExcludedNPCs) do if character.Name:find(name) then return true end end return false end local function getTargetPart(character) if Settings.TargetPart == "Random" then local parts = {"Head", "UpperTorso", "LowerTorso", "LeftUpperArm", "RightUpperArm"} return character:FindFirstChild(parts[math.random(#parts)]) elseif Settings.TargetPart == "Nearest" then local parts = {"Head", "UpperTorso", "HumanoidRootPart"} for _, partName in ipairs(parts) do local part = character:FindFirstChild(partName) if part then return part end end else return character:FindFirstChild(Settings.TargetPart) end return character:FindFirstChild("HumanoidRootPart") or character.PrimaryPart end local function isSameTeam(player1, player2) if not Settings.TeamCheck then return false end local team1 = player1.Team local team2 = player2 and player2.Team return team1 and team2 and team1 == team2 end local function isVisible(targetPart, origin) if not Settings.WallCheck then return true end local direction = (targetPart.Position - origin.Position).Unit local ray = Ray.new(origin.Position, direction * Settings.MaxDistance) local hit, position = Workspace:FindPartOnRayWithIgnoreList(ray, {LocalPlayer.Character, Camera}) if hit then local character = hit:FindFirstAncestorOfClass("Model") return character and character == targetPart:FindFirstAncestorOfClass("Model") end return false end local function predictPosition(targetPart, bulletSpeed) if not Settings.Prediction or not bulletSpeed then return targetPart.Position end local character = targetPart:FindFirstAncestorOfClass("Model") local humanoid = character and character:FindFirstChildOfClass("Humanoid") local rootPart = character and character:FindFirstChild("HumanoidRootPart") if not humanoid or not rootPart then return targetPart.Position end -- 计算到达目标所需时间 local distance = (targetPart.Position - Camera.CFrame.Position).Magnitude local timeToTarget = distance / bulletSpeed -- 预测新位置 local velocity = rootPart.Velocity * Settings.PredictionStrength return targetPart.Position + velocity * timeToTarget end local function findBestTarget(bulletSpeed) local bestTarget = nil local bestScore = math.huge local cameraPos = Camera.CFrame.Position local cameraLook = Camera.CFrame.LookVector -- 检查玩家 for _, player in ipairs(Players:GetPlayers()) do if player ~= LocalPlayer and not isSameTeam(LocalPlayer, player) then local character = player.Character if character then local humanoid = character:FindFirstChildOfClass("Humanoid") if humanoid and humanoid.Health > 0 then local targetPart = getTargetPart(character) if targetPart and isVisible(targetPart, Camera) then local position = predictPosition(targetPart, bulletSpeed) local direction = (position - cameraPos).Unit local angle = math.acos(cameraLook:Dot(direction)) local distance = (position - cameraPos).Magnitude if angle <= Settings.MaxAngle and distance <= Settings.MaxDistance then local score = angle * 100 + distance if score < bestScore then bestScore = score bestTarget = { Part = targetPart, Position = position, Character = character } end end end end end end end -- 检查NPC for _, npc in ipairs(Workspace:GetChildren()) do if npc:IsA("Model") and not shouldExclude(npc) then local humanoid = npc:FindFirstChildOfClass("Humanoid") if humanoid and humanoid.Health > 0 then local targetPart = getTargetPart(npc) if targetPart and isVisible(targetPart, Camera) then local position = predictPosition(targetPart, bulletSpeed) local direction = (position - cameraPos).Unit local angle = math.acos(cameraLook:Dot(direction)) local distance = (position - cameraPos).Magnitude if angle <= Settings.MaxAngle and distance <= Settings.MaxDistance then local score = angle * 100 + distance if score < bestScore then bestScore = score bestTarget = { Part = targetPart, Position = position, Character = npc } end end end end end end return bestTarget end -- 可视化追踪线 local function createVisualLine(startPos, endPos) if not Settings.Visualize then return end local line = Instance.new("Part") line.Size = Vector3.new(0.1, 0.1, (startPos - endPos).Magnitude) line.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -line.Size.Z/2) line.Anchored = true line.CanCollide = false line.Transparency = Settings.VisualTransparency line.Color = Settings.VisualColor line.Material = Enum.Material.Neon line.Parent = Workspace -- 添加光束效果 local beam = Instance.new("Beam") beam.Color = ColorSequence.new(Settings.VisualColor) beam.FaceCamera = true beam.Width0 = Settings.VisualThickness beam.Width1 = Settings.VisualThickness beam.Parent = line local attachment0 = Instance.new("Attachment") attachment0.Position = Vector3.new(0, 0, -line.Size.Z/2) attachment0.Parent = line local attachment1 = Instance.new("Attachment") attachment1.Position = Vector3.new(0, 0, line.Size.Z/2) attachment1.Parent = line beam.Attachment0 = attachment0 beam.Attachment1 = attachment1 game:GetService("Debris"):AddItem(line, Settings.VisualLife) end -- 武器检测 local weaponHandlers = { -- 处理射线武器 Raycast = function(params, bulletSpeed) if not Settings.Enabled then return end local bestTarget = findBestTarget(bulletSpeed) if bestTarget then -- 调整射线方向 local newDirection = (bestTarget.Position - params.Origin).Unit local newParams = RaycastParams.new() newParams.FilterDescendantsInstances = params.FilterDescendantsInstances newParams.FilterType = params.FilterType newParams.IgnoreWater = params.IgnoreWater newParams.CollisionGroup = params.CollisionGroup -- 可视化 if Settings.Visualize then createVisualLine(params.Origin, bestTarget.Position) end return newParams, newDirection end end, -- 处理物理子弹 Projectile = function(projectile, bulletSpeed) if not Settings.Enabled then return end local connection connection = RunService.Heartbeat:Connect(function() if not projectile or not projectile.Parent then connection:Disconnect() return end local bestTarget = findBestTarget(bulletSpeed) if bestTarget then -- 计算新方向 local currentVelocity = projectile.Velocity local targetDirection = (bestTarget.Position - projectile.Position).Unit local newVelocity = currentVelocity:Lerp(targetDirection * currentVelocity.Magnitude, Settings.Smoothing) -- 应用新方向 projectile.Velocity = newVelocity -- 可视化 if Settings.Visualize then createVisualLine(projectile.Position, bestTarget.Position) end end end) end } -- 主钩子 local function hookWeapons() -- 钩住射线武器 local oldRaycast = Workspace.Raycast Workspace.Raycast = function(workspace, origin, direction, params, ...) local result, position, normal, material = oldRaycast(workspace, origin, direction, params, ...) -- 检测是否是玩家发射的子弹 if params and params.FilterDescendantsInstances and #params.FilterDescendantsInstances > 0 then local firstFilter = params.FilterDescendantsInstances[1] if firstFilter and firstFilter:IsDescendantOf(LocalPlayer.Character) then local adjustedParams, adjustedDirection = weaponHandlers.Raycast(params, direction.Magnitude) if adjustedParams and adjustedDirection then return oldRaycast(workspace, origin, adjustedDirection, adjustedParams, ...) end end end return result, position, normal, material end -- 钩住物理子弹 local projectileConnections = {} local function trackProjectile(projectile) if projectile:GetAttribute("BulletTracked") then return end projectile:SetAttribute("BulletTracked", true) local creator = projectile:GetAttribute("Creator") if creator and creator == LocalPlayer then local bulletSpeed = projectile.Velocity.Magnitude weaponHandlers.Projectile(projectile, bulletSpeed) end end -- 监听新子弹 Workspace.DescendantAdded:Connect(function(descendant) if descendant:IsA("BasePart") and descendant.Name == "Bullet" then trackProjectile(descendant) end end) -- 检查现有子弹 for _, projectile in ipairs(Workspace:GetChildren()) do if projectile:IsA("BasePart") and projectile.Name == "Bullet" then trackProjectile(projectile) end end end -- 初始化 local function initialize() -- 等待玩家加载 if not LocalPlayer.Character then LocalPlayer.CharacterAdded:Wait() end -- 等待相机加载 while not Camera:IsA("Camera") do Camera = Workspace.CurrentCamera RunService.RenderStepped:Wait() end -- 安装钩子 hookWeapons() -- 创建FOV环 local fovRing = Drawing.new("Circle") fovRing.Visible = Settings.Enabled fovRing.Thickness = 2 fovRing.Color = Settings.VisualColor fovRing.Filled = false fovRing.Radius = Settings.FOV fovRing.Position = Camera.ViewportSize / 2 -- 更新设置 Rayfield:Notify({ Title = "子弹追踪已激活", Content = "成功钩住武器系统", Duration = 3, Image = 0 }) -- 主循环 RunService.RenderStepped:Connect(function() fovRing.Visible = Settings.Enabled fovRing.Radius = Settings.FOV fovRing.Position = Camera.ViewportSize / 2 end) end -- 启动 initialize() Rayfield:LoadConfiguration() -- 加载保存的设置