автообновление

rebornjk

Новичок
Автор темы
8
0
Версия MoonLoader
.026-beta
Сделал автообновление, но при заходе пишет `Не могу проверить обновление. Смиритесь или проверьте самостоятельно`
Lua:
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    while not isSampAvailable() do wait(100) end
    autoupdate("https://api.jsonbin.io/b/61ef0ddfbd6e744997eb0ff4", '['..string.upper(thisScript().name)..']: ', "https://github.com/Jokos123/adminhelper/blob/main/Admin%20Helper.luac?raw=true")
 
function autoupdate(json_url, prefix, url)
  local dlstatus = require('moonloader').download_status
  local json = getWorkingDirectory() .. '\\'..thisScript().name..'-version.json'
  if doesFileExist(json) then os.remove(json) end
  downloadUrlToFile(json_url, json,
    function(id, status, p1, p2)
      if status == dlstatus.STATUSEX_ENDDOWNLOAD then
        if doesFileExist(json) then
          local f = io.open(json, 'r')
          if f then
            local info = decodeJson(f:read('*a'))
            updatelink = info.updateurl
            updateversion = info.latest
            f:close()
            os.remove(json)
            if updateversion ~= thisScript().version then
              lua_thread.create(function(prefix)
                local dlstatus = require('moonloader').download_status
                local color = -1
                sampAddChatMessage('{ffffff}Найдено обновление!', -1)
                sampAddChatMessage((prefix..'{ffffff}Пытаюсь обновиться c '..thisScript().version..' на '..updateversion), color)
                wait(250)
                downloadUrlToFile(updatelink, thisScript().path,
                  function(id3, status1, p13, p23)
                    if status1 == dlstatus.STATUS_DOWNLOADINGDATA then
                      print(string.format('Загружено %d из %d.', p13, p23))
                    elseif status1 == dlstatus.STATUS_ENDDOWNLOADDATA then
                      sampAddChatMessage((prefix..'{ffffff}Загрузка обновления завершена'), color)
                      goupdatestatus = true
                      lua_thread.create(function() wait(500) thisScript():reload() end)
                    end
                    if status1 == dlstatus.STATUSEX_ENDDOWNLOAD then
                      if goupdatestatus == nil then
                        sampAddChatMessage((prefix..'{ffffff}Обновление прошло неудачно. Запускаю устаревшую версию..'), color)
                        update = false
                      end
                    end
                  end
                )
                end, prefix
              )
            else
              update = false
              sampAddChatMessage('{ffffff}Обновление не требуется.', color)
            end
          end
        else
          print()
          sampAddChatMessage('{ffffff}Не могу проверить обновление. Смиритесь или проверьте самостоятельно', color)
          update = false
        end
      end
    end
  )
  while update ~= false do wait(100) end
end
 
Последнее редактирование:

hinazuki

Потрачен
346
95
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Сделал автообновление, но при заходе пишет `Не могу проверить обновление. Смиритесь или проверьте самостоятельно`
Lua:
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    while not isSampAvailable() do wait(100) end
    autoupdate("https://api.jsonbin.io/b/61ef0ddfbd6e744997eb0ff4", '['..string.upper(thisScript().name)..']: ', "https://github.com/Jokos123/adminhelper/blob/main/Admin%20Helper.luac?raw=true")
 
function autoupdate(json_url, prefix, url)
  local dlstatus = require('moonloader').download_status
  local json = getWorkingDirectory() .. '\\'..thisScript().name..'-version.json'
  if doesFileExist(json) then os.remove(json) end
  downloadUrlToFile(json_url, json,
    function(id, status, p1, p2)
      if status == dlstatus.STATUSEX_ENDDOWNLOAD then
        if doesFileExist(json) then
          local f = io.open(json, 'r')
          if f then
            local info = decodeJson(f:read('*a'))
            updatelink = info.updateurl
            updateversion = info.latest
            f:close()
            os.remove(json)
            if updateversion ~= thisScript().version then
              lua_thread.create(function(prefix)
                local dlstatus = require('moonloader').download_status
                local color = -1
                sampAddChatMessage('{ffffff}Найдено обновление!', -1)
                sampAddChatMessage((prefix..'{ffffff}Пытаюсь обновиться c '..thisScript().version..' на '..updateversion), color)
                wait(250)
                downloadUrlToFile(updatelink, thisScript().path,
                  function(id3, status1, p13, p23)
                    if status1 == dlstatus.STATUS_DOWNLOADINGDATA then
                      print(string.format('Загружено %d из %d.', p13, p23))
                    elseif status1 == dlstatus.STATUS_ENDDOWNLOADDATA then
                      sampAddChatMessage((prefix..'{ffffff}Загрузка обновления завершена'), color)
                      goupdatestatus = true
                      lua_thread.create(function() wait(500) thisScript():reload() end)
                    end
                    if status1 == dlstatus.STATUSEX_ENDDOWNLOAD then
                      if goupdatestatus == nil then
                        sampAddChatMessage((prefix..'{ffffff}Обновление прошло неудачно. Запускаю устаревшую версию..'), color)
                        update = false
                      end
                    end
                  end
                )
                end, prefix
              )
            else
              update = false
              sampAddChatMessage('{ffffff}Обновление не требуется.', color)
            end
          end
        else
          print()
          sampAddChatMessage('{ffffff}Не могу проверить обновление. Смиритесь или проверьте самостоятельно', color)
          update = false
        end
      end
    end
  )
  while update ~= false do wait(100) end
end
Так ты должен отправлять запрос на json файл, а не на luac скрипт.
 
  • Нравится
Реакции: Shepi

hinazuki

Потрачен
346
95
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.