Скрипт отказывается работать =(

DedPoet

Участник
Автор темы
98
18
Версия MoonLoader
Другое
Всем ку. Хотел сделать скрипт для проверки iP и вывода дистанции. Но скрипт отказывается работать.
Думал думал, не понял чо такого.
Требую мозговитого челика который руку помощи подаст.

Сурсня:
ТЫК:
local imgui = require("imgui")
local vkeys = require("vkeys")
local imgaddd = require("imgui_addons")
local rkeys = require("rkeys")
local mem = require("memory")
local requests = require("requests")
require "lib.moonloader"
local fa = require("faIcons")
local lse = require("lib.samp.events")
local cjson = require("cjson")
local effil = require("effil")
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

function main()

    if not isSampLoaded() then return end
        
    while not isSampAvailable() do wait(3000) end
        
        sampRegisterChatCommand("myip", checkip)
        sampRegisterChatCommand("ipd", chipd)
        sampRegisterChatCommand("ip", chip)
        sampRegisterChatCommand("chipoff", chipoff)
        
    wait(-1)
end

function xueta()
        if xueta == true then
            sampAddChatMessage("Скрипт активирован. Ожидайте.")
        end
end

function checkip()
local result, response = pcall(requests.get, "http://ip-api.com/json/")
    if result then
    json_data = response.json()
        sampShowDialog(1234, "{ffff01}Ваши данные", "{ffffff}Ваш IP адрес: {00BFFF}"..json_data.query.."\n{ffffff}Ваша страна: {00BFFF}"..json_data.country.."\n{ffffff}Ваш город: {00BFFF}"..json_data.city.."\n{ffffff}Ваш регион/штат: {00BFFF}"..json_data.regionName.."\n{ffffff}Ваш провайдер: {00BFFF}"..json_data.isp.."\n{ffffff}Ваш часовой пояс: {00BFFF}"..json_data.timezone.."\n{ffffff}Мобмльный интернт: {00BFFF}"..json_data.mobile..."", "Закрыть", "", 0)
    end
end

function lse.onServerMessage(color, text)
    if text:find("%{FFFF00%}| %{ffffff%}IP: %d+%p%d+%p%d+%p%d+ || REG: %d+%p%d+%p%d+%p%d+") then
        lip, rip = text:match("%{FFFF00%}| %{ffffff%}IP: (%d+%p%d+%p%d+%p%d+) || REG: (%d+%p%d+%p%d+%p%d+)")

        return false
    end
end
    
function chipoff(text)
local result, response = pcall(requests.get, "http://ip-api.com/json/")
        name = string.match(text, "(%a+_%a+)")
        
    if name == nil or name == "" then
            sampAddChatMessage("/chipoff [Nick_Name]")
        else
            lua_thread.create(function ()
                sampSendChat("/getipsoff " .. name)
                sampAddChatMessage("Ожидаем, происходит проверка...")
                wait(1500)

                if lip then
                    result, response = pcall(requests.get, "http://ip-api.com/json/" .. lip .. "?lang=ru")

                    if result then
                        json_data = response.json()
                        country = json_data.country
                        city = json_data.city
                        org = json_data.as
                        lat1 = json_data.lat
                        lon1 = json_data.lon
                    end
                end

                if rip then
                    result, response = pcall(requests.get, "http://ip-api.com/json/" .. rip .. "?lang=ru")

                    if result then
                        json_data = requests.json()
                        country2 = json_data.country
                        city2 = json_data.city
                        org2 = json_data.as
                        lat2 = json_data.lat
                        lon2 = json_data.lon
                    end
                end

                if lat1 == nil then
                    sampAddChatMessage("Неизвестная ошибка, обратитесь vk.com/nepaluVK")
                else
                    distances = distance_cord(lat1, lon1, lat2, lon2)
                    text = string.format("\n{" .. StyleText .. "}Текущий IP: - {FFFFFF}%s\n{" .. StyleText .. "}Текущая Страна: -{FFFFFF} %s\n{" .. StyleText .. "}Текущий Город: -{FFFFFF} %s\n{" .. StyleText .. "}Текущий Провайдер: -{FFFFFF} %s  \n\n{" .. StyleText .. "}Расстояние между IP: -{FFFFFF} %d\n\n{" .. StyleText .. "}Регистрационный IP: - {FFFFFF}%s\n{" .. StyleText .. "}Регистрационная Страна: -{FFFFFF} %s\n{" .. StyleText .. "}Регистрационный Город: -{FFFFFF} %s\n{" .. StyleText .. "}Регистрационный Провайдер: -{FFFFFF} %s", lip, u8:decode(country), u8:decode(city), u8:decode(org), distances, rip, u8:decode(country2), u8:decode(city2), u8:decode(org2))
                    lip = nil
                    rip = nil
                    lat1 = nil

                    showdialog("{" .. bit.tohex(sampGetPlayerColor(id), 6) .. "}" .. id, text)
                end
            end)
        end
    end

up
 
Последнее редактирование:

DedPoet

Участник
Автор темы
98
18
[23:52:25.115578] (error) chip.lua: C:\Games\GTA\moonloader\chip.lua:81: attempt to call field 'json' (a nil value)
stack traceback:
C:\Games\GTA\moonloader\chip.lua: in function <C:\Games\GTA\moonloader\chip.lua:59>
[23:52:25.115578] (error) chip.lua: Script died due to an error. (08174944)
 

#Northn

Police Helper «Reborn» — уже ШЕСТЬ лет!
Всефорумный модератор
2,634
2,484
[23:52:25.115578] (error) chip.lua: C:\Games\GTA\moonloader\chip.lua:81: attempt to call field 'json' (a nil value)
stack traceback:
C:\Games\GTA\moonloader\chip.lua: in function <C:\Games\GTA\moonloader\chip.lua:59>
[23:52:25.115578] (error) chip.lua: Script died due to an error. (08174944)
response.json()
Если не поможет, то decodeJson(response)