asyncHttpRequest

shadow80962

Известный
Автор темы
127
13
Версия MoonLoader
.026-beta
Никак не хочет выполняться запросы в результате получаю краш скрипта, при этом есть такой же запрос на строчку о регистрации аккаунта и там все работает

Код:
[ML] (script) AScript.lua: # Nick_Name
[ML] (script) AScript.lua: # тест
[ML] (error) AScript.lua: D:\Games\ARIZONA GAMES\bin\Arizona\moonloader\test.lua:737: attempt to index upvalue 'banIP_last' (a nil value)
stack traceback:
    D:\Games\ARIZONA GAMES\bin\Arizona\moonloader\test.lua:737: in function 'callback'
    ...NA GAMES\bin\Arizona\moonloader\lib\samp\events\core.lua:79: in function <...NA GAMES\bin\Arizona\moonloader\lib\samp\events\core.lua:53>
[ML] (error) test.lua: Script died due to an error. (264C6604)

Lua:
if message:find("Забанен%: (.+)%. IP%: (.+)%. REGIP%: (.+)") then
        banned_nickname, banned_lastip, banned_regip = message:match("Забанен%: (.+)%. IP%: (.+)%. REGIP%: (.+)")
            asyncHttpRequest("GET", format("http://ip-api.com/json/%s?fields=17034777", banned_lastip), nil,
            function(response)
                banIP_last = decodeJson(response.text)
                print(response.text)
            end,
            function(err)
                print("ошибка")
            end)
            if banned_lastip ~= banned_regip then
                asyncHttpRequest("GET", format("http://ip-api.com/json/%s?fields=17034777", banned_regip), nil,
                function(response)
                    banIP_reg = decodeJson(response.text)
                    print(response.text)
                end)
            
                print(format("# %s", banned_nickname))
                print(format("# %s", send_banned_reason))
                print(format("# %s", banIP_reg.city))
                print(format("# %s", banIP_last.city))
                print(format("# %s", banIP_reg.as))
                print(format("# %s", banIP_last.as))
                print(format("# %s", banIP_reg.proxy == true or banIP_reg.hosting == true and ("Да") or ("Нет")))
                print(format("# %s", banIP_last.proxy == true or banIP_last.hosting == true and ("Да") or ("Нет")))         
            else
                print(format("# %s", banned_nickname))
                print(format("# %s", send_banned_reason))
                print(format("# %s", banIP_last.query))
                print(format("# %s", banIP_last.city))
                print(format("# %s", banIP_last.as))
                print(format("# %s", banIP_last.proxy == true or banIP_last.hosting == true and ("Да") or ("Нет")))
            end
    end
 

Rice.

https://t.me/riceoff
Модератор
1,681
1,383
Твой первый запрос не успевает получить таблицу banIP_last, поэтому скрипт и крашится. Ошибка: таблица banIP_last является nil. Тебе нужно обрабатывать второй запрос только после успешного выполнения первого, а у тебя второй запрос выполняется одновременно с первым.
 
  • Нравится
Реакции: YarikVL и XRLM