Помогите пжпж

clrn1w

Известный
Автор темы
317
146
Крч хотел сделать езду, взял код у ковра, но почему-то машина вместо того, чтобы ехать нормально просто буксует(из массива я вырезал весь маршрут, а оставил для того, чтобы показать как выглядить массив)

Lua:
route = {{1557.7397460938, 1578.1595458984, 0}, {1557.7397460938, 1578.1595458984, 0}}

function main()
    while not isSampfuncsLoaded() or not isSampLoaded() do wait(0) end
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("go", function() active = not acitve end)
    while true do
        wait(0)
        if active then
            for i, value in pairs(route) do
                if not active then break end
                repeat
                    wait(0)
                    if not active then break end
                    if isCharInAnyCar(PLAYER_PED) then
                        local car = storeCarCharIsInNoSave(PLAYER_PED)
                        local carPosX, carPosY, carPosZ = getCarCoordinates(car)
                        turning_mechanism(route[i][1], route[i][2], carPosX, carPosY, car)
                        if getCarSpeed(car) < route[i][3] + 0.2 then
                            press_gas()
                        else
                            press_brake()
                        end
                    end
                until locateCharInCar2d(PLAYER_PED, route[i][1], route[i][2], 5.0, 5.0, false)
            end
        end
    end
end

function turning_mechanism(posX, posY, carPosX, carPosY, car)
    local heading = math.rad(getHeadingFromVector2d(posX - carPosX, posY - carPosY) + math.abs(getCarHeading(car) - 360.0))
    local heading = getHeadingFromVector2d(math.deg(math.sin(heading)), math.deg(math.cos(heading)))
    if heading > 180.0 and 355.0 > heading then -- press left
        setGameKeyState(0, -128)
    else
        if heading > 5.0 and 180.0 >= heading then -- press right
            setGameKeyState(0, 128)
        else
            setGameKeyState(0, 0)
        end
    end
end

function press_gas()
    writeMemory(0xB73458 + 0x20, 1, 255, false)
end

function press_brake()
    writeMemory(0xB73458 + 0xC, 1, 255, false)
end