проверка игрока на онлайн

Bene //

Участник
Автор темы
128
6
Версия MoonLoader
.026-beta
Всем привет, есть таблица и из нее нужно вывести игроков онлайн и оффлайн, как такое сделать?
таблица:
local players = {"Jerry_Smoke", "George_Broke", "Brain_Grovsky", "Klaer_York", "Frank_Vace", "Tanke_Hawke"}
 
Решение
Lua:
local players = {}
local font_flag = require('moonloader').font_flag
local my_font = renderCreateFont('Verdana', 12, font_flag.BOLD + font_flag.SHADOW)

function main()
    while not isSampAvailable() do wait(0) end
    while true do
        wait(0)
        local onlinePlayers = {}
        local offlinePlayers = {}
        
        for k, v in ipairs(players) do
            local playerId = sampGetPlayerIdByNickname(v)
            if playerId and sampIsPlayerConnected(playerId) then
                table.insert(onlinePlayers, v)
            else
                table.insert(offlinePlayers, v)
            end
        end
        local onlinePlayersStr = table.concat(onlinePlayers, ', ')
        renderFontDrawText(my_font...

Hinаta

Известный
777
363
Lua:
function sampGetPlayerIdByNickname(nick)
    nick = tostring(nick)
    local _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
    if nick == sampGetPlayerNickname(myid) then return myid end
    for i = 0, 1003 do
      if sampIsPlayerConnected(i) and sampGetPlayerNickname(i) == nick then
        return i
      end
    end
  end

for _, v in ipairs(players) do
    if sampIsPlayerConnected(sampGetPlayerIdByNickname(v)) then
        print(v)
    end
end
 
  • Нравится
Реакции: Bene // и chromiusj

chromiusj

Стань той переменой, которую хочешь увидеть в мире
Модератор
5,737
4,041
Lua:
local players = {}
local font_flag = require('moonloader').font_flag
local my_font = renderCreateFont('Verdana', 12, font_flag.BOLD + font_flag.SHADOW)

function main()
    while not isSampAvailable() do wait(0) end
    while true do
        wait(0)
        local onlinePlayers = {}
        local offlinePlayers = {}
        
        for k, v in ipairs(players) do
            local playerId = sampGetPlayerIdByNickname(v)
            if playerId and sampIsPlayerConnected(playerId) then
                table.insert(onlinePlayers, v)
            else
                table.insert(offlinePlayers, v)
            end
        end
        local onlinePlayersStr = table.concat(onlinePlayers, ', ')
        renderFontDrawText(my_font, '{00ff59}Online: {ffffff} '..onlinePlayersStr, 10, 440, 0xFFFFFFFF)
        local offlinePlayersStr = table.concat(offlinePlayers, ', ')
        renderFontDrawText(my_font, '{f20008}Offline: {ffffff} '..offlinePlayersStr, 10, 420, 0xFFFFFFFF)

    end
end

function sampGetPlayerIdByNickname(nick)
    nick = tostring(nick)
    local _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
    if nick == sampGetPlayerNickname(myid) then return myid end
    for i = 0, 1003 do
        if sampIsPlayerConnected(i) and sampGetPlayerNickname(i) == nick then
            return i
        end
    end
end
 
  • Нравится
Реакции: Bene // и Hinаta