Доезжает до первой метки и дальше стоит

.KOHTOP.

Активный
Автор темы
219
35
Версия MoonLoader
.027.0-preview
Пытался сделать скрипт, который ищет метки и едет по ним, но что-то пошло не так.
Скрипт доезжает до первой метки и просто останавливается, если прописать команду /bus 1, то пишет, что метка не найдена. Вроде и поиск метки в main стоит, но почему - то останавливается. Возможно дело в том, что часть скрипта, с помощью которой он едет останавливает своё движение, а мне надо, чтобы пока есть метки он ехал.

Lua:
function main()
    while not isSampAvailable() do wait(0) end
        sampRegisterChatCommand('bus', cmd_bot)
    while true do
        wait(0)
        
        function SearchMarker(posX, posY, posZ, radius, isRace)
            local ret_posX = 0.0
            local ret_posY = 0.0
            local ret_posZ = 0.0
            local isFind = false
        
            for id = 0, 31 do
                local MarkerStruct = 0
                if isRace then MarkerStruct = 0xC7F168 + id * 56
                else MarkerStruct = 0xC7DD88 + id * 160 end
                local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
                local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
                local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
        
                if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
                    if getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ) < radius then
                        ret_posX = MarkerPosX
                        ret_posY = MarkerPosY
                        ret_posZ = MarkerPosZ
                        isFind = true
                        radius = getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ)
                    end
                end
            end
        
            return isFind, ret_posX, ret_posY, ret_posZ
        end

    end
end

function cmd_bot(arg)
    if arg == '1' then

        if isPlayerPlaying(playerHandle) then
            local posX, posY, posZ = getCharCoordinates(playerPed)
            local res, x, y, z = SearchMarker(posX, posY, posZ, 50.0, false)
            if res then
                lua_thread.create(function ()
                    if isCharInAnyCar(PLAYER_PED) then
                        taskCarDriveToCoord(PLAYER_PED, storeCarCharIsInNoSave(PLAYER_PED), x, y, z, 50, 2, nil, 7)
                        --начинает ехать на координаты 0, 0, 0 и останавливается если нажата кнопка X
                        while not isKeyJustPressed(VK_X) do wait(0) end
                        --когда игрок нажимает X останавливает движение
                        clearCharTasks(PLAYER_PED)
                        taskWarpCharIntoCarAsDriver(PLAYER_PED, storeCarCharIsInNoSave(PLAYER_PED))
                    end
                end)
            else
                res, x, y, z = SearchMarker(posX, posY, posZ, 50.0, true)
                if res then
                    lua_thread.create(function ()
                        if isCharInAnyCar(PLAYER_PED) then
                            taskCarDriveToCoord(PLAYER_PED, storeCarCharIsInNoSave(PLAYER_PED), x, y, z, 50, 2, nil, 7)
                            --начинает ехать на координаты 0, 0, 0 и останавливается если нажата кнопка X
                            while not isKeyJustPressed(VK_X) do wait(0) end
                            --когда игрок нажимает X останавливает движение
                            clearCharTasks(PLAYER_PED)
                            taskWarpCharIntoCarAsDriver(PLAYER_PED, storeCarCharIsInNoSave(PLAYER_PED))
                        end
                    end)
                else
                    sampAddChatMessage("Маркер не найден", -1)
                end
            end
        end
    elseif arg == '2' then
        sampAddChatMessage('Бот отключен', -1)
    end
end
 

.KOHTOP.

Активный
Автор темы
219
35