local TargetPart = { HEAD = 1, -- 头部(最高优先级) BODY = 2, -- 躯干(默认) LIMB = 3 -- 四肢(最低优先级) } local TargetData = { targetID = 0, posX = 0, posY = 0, posZ = 0, headPosX = 0, headPosY = 0, headPosZ = 0, health = 100, isEnemy = false, isKnocked = false, moveSpeed = 0, moveDirX = 0, moveDirY = 0 } local PlayerData = { posX = 0, posY = 0, posZ = 0, aimInput = 0.1, isIndoor = false, isMoving = true } -- 2. 自瞄配置(可从外部配置文件读取) local AimBotConfig = { enableAutoAim = true, maxLockDistance = 2000.0, targetLostDelay = 5.0, baseSmoothness = 0.0, lowHpThreshold = 100.0, priorityPart = TargetPart.HEAD, bulletSpeed = 5000.0, aimStrengthMax = 1.5 } -- 3. 自瞄核心工具函数 local function Calculate3DDistance(px, py, pz, tx, ty, tz) local dx = tx - px local dy = ty - py local dz = tz - pz return math.sqrt(dx*dx + dy*dy + dz*dz) end -- 4. 自瞄核心功能函数 local function RunAimBot(player, allTargets, config) -- 步骤1:检查自瞄启用状态 if not config.enableAutoAim then return false, 0, 0, TargetPart.BODY end -- 步骤2:筛选有效目标 local lockedTarget = nil local minDistance = math.huge local foundValidTarget = false local PART_WEIGHT = 1000 -- 部位权重 local LOWHP_WEIGHT = 500 -- 低血权重 local DISTANCE_WEIGHT = 100 -- 距离权重 local maxPriority = 0 local outLockedPart = config.priorityPart for _, target in ipairs(allTargets) do -- 只保留敌方、未倒地目标 if not target.isEnemy or target.isKnocked then goto continue end -- 计算玩家到目标头部的距离 local targetDistance = Calculate3DDistance( player.posX, player.posY, player.posZ, target.headPosX, target.headPosY, target.headPosZ ) if targetDistance > config.maxLockDistance then goto continue end -- 计算目标优先级 local currentPriority = 0 -- 部位优先级 if config.priorityPart == TargetPart.HEAD then currentPriority = currentPriority + PART_WEIGHT elseif config.priorityPart == TargetPart.BODY then currentPriority = currentPriority + PART_WEIGHT / 2 else currentPriority = currentPriority + PART_WEIGHT / 10 end -- 低血优先级 if target.health <= config.lowHpThreshold then currentPriority = currentPriority + LOWHP_WEIGHT end -- 距离优先级 currentPriority = currentPriority + math.floor(DISTANCE_WEIGHT / (targetDistance / 100 + 1)) -- 更新最高优先级目标 if currentPriority > maxPriority or (currentPriority == maxPriority and targetDistance < minDistance) then maxPriority = currentPriority minDistance = targetDistance lockedTarget = target foundValidTarget = true outLockedPart = config.priorityPart end ::continue:: end if not foundValidTarget then return false, 0, 0, TargetPart.BODY end -- 步骤3:瞄准预测 local bulletFlightTime = minDistance / config.bulletSpeed local predictedHeadX = lockedTarget.headPosX + (lockedTarget.moveSpeed * lockedTarget.moveDirX * bulletFlightTime) local predictedHeadY = lockedTarget.headPosY + (lockedTarget.moveSpeed * lockedTarget.moveDirY * bulletFlightTime) local predictedHeadZ = lockedTarget.headPosZ -- 室内场景无削弱 if player.isIndoor then predictedHeadX = lockedTarget.headPosX + (predictedHeadX - lockedTarget.headPosX) * 1.0 predictedHeadY = lockedTarget.headPosY + (predictedHeadY - lockedTarget.headPosY) * 1.0 end -- 步骤4:自瞄强度计算 local aimStrength = config.aimStrengthMax -- 移动时强度增强 if player.isMoving then aimStrength = aimStrength * 1.5 end -- 手动输入强时轻微降低 if player.aimInput > 1.5 then aimStrength = aimStrength * 0.8 end -- 步骤5:计算最终瞄准角度 local dirX = predictedHeadX - player.posX local dirY = predictedHeadY - player.posY local dirZ = predictedHeadZ - player.posZ local targetAngleX = math.atan2(dirY, dirX) * (180.0 / math.pi) local targetAngleY = math.asin(dirZ / minDistance) * (180.0 / math.pi) -- 步骤6:应用瞄准平滑(直接赋值,无平滑延迟) local outAimAngleX = targetAngleX local outAimAngleY = targetAngleY return true, outAimAngleX, outAimAngleY, outLockedPart end -- 5. 配置读取函数(从外部文件读取配置) local function LoadConfigFromFile(filePath) local config = {} local file = io.open(filePath, "r") if file then for line in file:lines() do local key, value = line:match("([^=]+)=([^=]+)") if key and value then key = key:gsub("%s+", "") value = value:gsub("%s+", "") if key == "enableAutoAim" then config.enableAutoAim = (value == "true" or value == "1") elseif key == "maxLockDistance" then config.maxLockDistance = tonumber(value) elseif key == "targetLostDelay" then config.targetLostDelay = tonumber(value) elseif key == "baseSmoothness" then config.baseSmoothness = tonumber(value) elseif key == "lowHpThreshold" then config.lowHpThreshold = tonumber(value) elseif key == "priorityPart" then if value == "HEAD" then config.priorityPart = TargetPart.HEAD elseif value == "BODY" then config.priorityPart = TargetPart.BODY else config.priorityPart = TargetPart.LIMB end elseif key == "bulletSpeed" then config.bulletSpeed = tonumber(value) elseif key == "aimStrengthMax" then config.aimStrengthMax = tonumber(value) end end end file:close() end return config end -- 6. 主函数 local function main() -- 从配置文件加载设置 local config = LoadConfigFromFile("和平精英自瞄配置.txt") or AimBotConfig -- 模拟玩家数据 local player = { posX = 0.0, posY = 0.0, posZ = 0.0, aimInput = 0.1, isIndoor = false, isMoving = true } -- 模拟目标数据 local targets = { { targetID = 101, posX = 1800.0, posY = 1200.0, posZ = 5.0, headPosX = 1800.0, headPosY = 1200.0, headPosZ = 8.0, health = 10.0, isEnemy = true, isKnocked = false, moveSpeed = 15.0, moveDirX = 0.8, moveDirY = 0.6 }, { targetID = 102, posX = 1500.0, posY = 900.0, posZ = 5.0, headPosX = 1500.0, headPosY = 900.0, headPosZ = 8.0, health = 100.0, isEnemy = true, isKnocked = false, moveSpeed = 15.0,