Почему не работает подгрузка файла?

Lill_Chich

Участник
Автор темы
73
5
Версия MoonLoader
.026-beta
Lua:
require 'lib.moonloader'
local dlstatus = require('moonloader').download_status
local vk = require 'vkeys'

function download_handler(id, status, p1, p2)
  if stop_downloading then
    stop_downloading = false
    download_id = nil
    return false -- прервать загрузку
  end
  if status == dlstatus.STATUS_DOWNLOADINGDATA then
    print(string.format(' %d/%d.', p1, p2))
  elseif status == dlstatus.STATUS_ENDDOWNLOADDATA then
    print('Stop')
   end
end

function main()
  while not isSampAvailable() do wait(0) end
  print('Press J')
  while true do
    wait(0)
    if wasKeyPressed(VK_J) and not download_id then
      local url = 'https://raw.githubusercontent.com/DeDsEk0/settings_gh/main/toast_notf.lua'
      local file_path = getWorkingDirectory() .. '/lib/toast_notf.lua'
      download_id = downloadUrlToFile(url, file_path, download_handler)
      print('Press F2')
    elseif wasKeyPressed(VK_F2) and download_id then
      stop_downloading = true
    end
  end
end

Почему не работает?
 
Решение
Lua:
local dlstatus = require('moonloader').download_status
local vk = require 'vkeys'
 
function download_handler(id, status, p1, p2)
    if stop_downloading then
        stop_downloading = false
        download_id = nil
        print('Загрузка отменена.')
    return false -- прервать загрузку
    end
    if status == dlstatus.STATUS_DOWNLOADINGDATA then
        print(string.format('Загружено %d из %d.', p1, p2))
    elseif status == dlstatus.STATUS_ENDDOWNLOADDATA then
        print('Загрузка завершена.')
    end
end
 
function main()
    print('Нажмите J, чтобы начать загрузку файла.')
    while true do wait(0)
        if wasKeyPressed(vk.VK_J) and not download_id then
            local url =...

qdIbp

Автор темы
Проверенный
1,386
1,141
Lua:
local dlstatus = require('moonloader').download_status
local vk = require 'vkeys'
 
function download_handler(id, status, p1, p2)
    if stop_downloading then
        stop_downloading = false
        download_id = nil
        print('Загрузка отменена.')
    return false -- прервать загрузку
    end
    if status == dlstatus.STATUS_DOWNLOADINGDATA then
        print(string.format('Загружено %d из %d.', p1, p2))
    elseif status == dlstatus.STATUS_ENDDOWNLOADDATA then
        print('Загрузка завершена.')
    end
end
 
function main()
    print('Нажмите J, чтобы начать загрузку файла.')
    while true do wait(0)
        if wasKeyPressed(vk.VK_J) and not download_id then
            local url = 'https://raw.githubusercontent.com/DeDsEk0/settings_gh/main/toast_notf.lua'
            local file_path = getWorkingDirectory() .. '/toast_notf.lua'
            download_id = downloadUrlToFile(url, file_path, download_handler)
            print('Загрузка начата. Нажмите F2, чтобы отменить её.')
        elseif wasKeyPressed(vk.VK_F2) and download_id then
                stop_downloading = true
        end
    end
end
 
  • Нравится
Реакции: Lill_Chich