Модуль:ServerStatus: различия между версиями

Als (обсуждение | вклад)
Новая страница: «local p = {} function p.getPlayerCount(frame) local http = require('http') -- предположим, что у вас есть доступ к этой библиотеке local json = require('json') -- предположим, что у вас есть доступ к этой библиотеке local url = "http://85.192.49.3:1212/status" local response, err = http.get(url) if not response then return "Ошибка при...»
 
Als (обсуждение | вклад)
Нет описания правки
Строка 1: Строка 1:
local p = {}
fetch('http://85.192.49.3:1212/status')
 
  .then(response => {
function p.getPlayerCount(frame)
     if (!response.ok) {
    local http = require('http') -- предположим, что у вас есть доступ к этой библиотеке
      throw new Error('Ошибка сети');
    local json = require('json') -- предположим, что у вас есть доступ к этой библиотеке
     }
 
     return response.json();
    local url = "http://85.192.49.3:1212/status"
  })
    local response, err = http.get(url)
  .then(data => {
 
     const playerCount = data.players;
     if not response then
    console.log(`Количество игроков на сервере: ${playerCount}`);
        return "Ошибка при получении данных: " .. (err or "неизвестная ошибка")
  })
     end
  .catch(error => {
 
     console.error('Произошла ошибка:', error);
     local data, err = json.decode(response)
  });
 
    if not data then
        return "Ошибка при декодировании JSON: " .. (err or "неизвестная ошибка")
     end
 
    if data.players then
        return data.players
    else
        return "Не удалось найти количество игроков в ответе."
     end
end
 
return p

Версия от 18:31, 3 августа 2025

fetch('http://85.192.49.3:1212/status')

 .then(response => {
   if (!response.ok) {
     throw new Error('Ошибка сети');
   }
   return response.json();
 })
 .then(data => {
   const playerCount = data.players;
   console.log(`Количество игроков на сервере: ${playerCount}`);
 })
 .catch(error => {
   console.error('Произошла ошибка:', error);
 });