SA:MP Arizona математика smooth aim на lua

midar

Участник
Автор темы
15
2
Версия SA-MP
  1. 0.3.7-R3
Всем привет, пытаюсь сделать мультичит, но не могу сделать нормально смуч на lua. Проблема в его математике. Часто бывают проблемы с растягом экрана, с разностью фова у разных оружий, отклонений в зависимости от дистанций и относительной высоты. Всё приводит к тому, что чтобы пользоваться смучом нужно настраивать персональные оффсеты. Тестил только на аризоне, только там мне и нужно.
То, как оно должно выглядеть (на видео клео смуч): Опирался на:
Буду признателен если поможете с формулой или же дадите какой-либо рабочий универсальный образец

То что использовал по итогу (red: упростил скрипт до полноценного рабочего):
aimbot:
local vkeys = require 'vkeys'


local smooth = 1
local fov = 15.0
local maxDist = 300.0
local targetBone = 2

local aimActive = false
local currentTarget = nil

function main()
    while not isSampAvailable() do wait(100) end
    
    sampRegisterChatCommand("aim", function()
        aimActive = not aimActive
        sampAddChatMessage(aimActive and "{00FF00}[Aim]: ON" or "{FF0000}[Aim]: OFF", -1)
    end)

    while true do
        wait(0)
        
        if aimActive and isKeyDown(vkeys.VK_RBUTTON) and not sampIsChatInputActive() and not isPauseMenuActive() then
            local cx, cy, cz = getActiveCameraCoordinates()
            
            if currentTarget == nil then
                local nearestId, minDistance = -1, fov
                for i = 0, sampGetMaxPlayerId() do
                    if sampIsPlayerConnected(i) and sampGetPlayerHealth(i) > 0 then
                        local r, p = sampGetCharHandleBySampPlayerId(i)
                        if r and p ~= PLAYER_PED and not isCharDead(p) and isCharOnScreen(p) then
                            local bx, by, bz = getBonePos(p, targetBone)
                            local dist = getDistanceBetweenCoords3d(cx, cy, cz, bx, by, bz)
                            
                            if dist <= maxDist then
                                -- Математика векторов
                                local dx, dy, dz = cx - bx, cy - by, cz - bz
                                local coZ = isWidescreenOnInOptions() and 0.0778 or 0.103
                                local tH = math.atan2(dy, dx) + 0.04253
                                local tV = math.atan2(math.sqrt(dx*dx + dy*dy), dz) - 1.570796 - coZ
                                
                                local ch = fixAngle(representIntAsFloat(readMemory(0xB6F258, 4, false)))
                                local cv = representIntAsFloat(readMemory(0xB6F248, 4, false))
                                
                                local distFOV = math.sqrt((fixAngle(tH - ch))^2 + (tV - cv)^2) * 57.29
                                if distFOV < minDistance then
                                    minDistance = distFOV
                                    nearestId = i
                                end
                            end
                        end
                    end
                end
                if nearestId ~= -1 then currentTarget = nearestId end
            end

            if currentTarget ~= nil then
                local r, p = sampGetCharHandleBySampPlayerId(currentTarget)
                if r and doesCharExist(p) and not isCharDead(p) and isCharOnScreen(p) then
                    local bx, by, bz = getBonePos(p, targetBone)
                    local dx, dy, dz = cx - bx, cy - by, cz - bz
                    
                    local coZ = isWidescreenOnInOptions() and 0.0778 or 0.103
                    local tH = math.atan2(dy, dx) + 0.04253
                    local tV = math.atan2(math.sqrt(dx*dx + dy*dy), dz) - 1.570796 - coZ
                    
                    local ch = fixAngle(representIntAsFloat(readMemory(0xB6F258, 4, false)))
                    local cv = representIntAsFloat(readMemory(0xB6F248, 4, false))
                    
                    local diffH = fixAngle(tH - ch)
                    local diffV = tV - cv
                    
                    setCameraPositionUnfixed(cv + (diffV / smooth), ch + (diffH / smooth))
                else
                    currentTarget = nil
                end
            end
        else
            currentTarget = nil
        end
    end
end

function fixAngle(angle)
    while angle > math.pi do angle = angle - (math.pi * 2) end
    while angle < -math.pi do angle = angle + (math.pi * 2) end
    return angle
end

function getBonePos(handle, bone)
    local ffi = require('ffi')
    ffi.cdef[[
        int __thiscall getBonePosition(void* self, float* pos, int boneId, bool update)
    ]]
    local pos = ffi.new("float[3]")
    local pedptr = getCharPointer(handle)
    local func = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)
    func(ffi.cast("void*", pedptr), pos, bone, true)
    return pos[0], pos[1], pos[2]
end
 
Последнее редактирование: