Как брать определенную инфу из txt текста и отправлять ее по очереди в чат сампа?

Mico

Активный
Автор темы
246
46
Версия MoonLoader
.026-beta
Привет! Нужна помощь, никак не пойму, как сделать? Есть скрипт, который создаст сразу файл text.txt, в который мы запишем вот такое:
Первый — Nick_Nick
Второй — Nick_Nick
... и так далее.
После захода в игру, мы запустим сам скрипт и он начнет проверять стату по этим никам. И запишет в другой файл text2.txt:
Первый — Nick_Nick, уровень 5
Второй — Nick_Nick, уровень 7
... и так далее.

Саму инфу по диалогу знаю как взять, надо именно чтобы он брал инфу из файла этого.
 

mooh

Известный
160
45
Lua:
local encoding = require('encoding')
encoding.default = 'CP1251'

local nicknames = {'Sam_Mason', 'Kalcor'}
local playersForCheckFile = getGameDirectory() .. '\\moonloader\\config\\playersForCheck.txt'
local checkedPlayersFile = getGameDirectory() .. '\\moonloader\\config\\checkedPlayers.txt'

function main()
    repeat wait(0) until isSampAvailable()

    if io.open(playersForCheckFile, 'r') == nil then io.open(playersForCheckFile, 'w'):close() end
    
    local file = io.open(playersForCheckFile, 'w')
    for i = 1, #nicknames do
        file:write(nicknames[i] .. '\n')
        file:flush()
    end
    if file ~= nil then file:close() end

    local players = io.open(playersForCheckFile, 'r'):read('*a')
    for line in players:gmatch("[^\n]+") do
        local player_id = getPlayerIdByNickname(line)
        if player_id ~= nil then
            file = io.open(checkedPlayersFile, 'a')
            file:write(line .. ', уровень ' .. sampGetPlayerScore(player_id) .. '\n')
            file:flush()
        end
    end
    if file ~= nil then file:close() end
end

function getPlayerIdByNickname(string)
    for i = 0, 999 do
        if sampIsPlayerConnected(i) or i == select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)) then
            if sampGetPlayerNickname(i):find(string) then
                return i
            end
        end
    end
    return nil
end
 

Mico

Активный
Автор темы
246
46
Lua:
local encoding = require('encoding')
encoding.default = 'CP1251'

local nicknames = {'Sam_Mason', 'Kalcor'}
local playersForCheckFile = getGameDirectory() .. '\\moonloader\\config\\playersForCheck.txt'
local checkedPlayersFile = getGameDirectory() .. '\\moonloader\\config\\checkedPlayers.txt'

function main()
    repeat wait(0) until isSampAvailable()

    if io.open(playersForCheckFile, 'r') == nil then io.open(playersForCheckFile, 'w'):close() end
   
    local file = io.open(playersForCheckFile, 'w')
    for i = 1, #nicknames do
        file:write(nicknames[i] .. '\n')
        file:flush()
    end
    if file ~= nil then file:close() end

    local players = io.open(playersForCheckFile, 'r'):read('*a')
    for line in players:gmatch("[^\n]+") do
        local player_id = getPlayerIdByNickname(line)
        if player_id ~= nil then
            file = io.open(checkedPlayersFile, 'a')
            file:write(line .. ', уровень ' .. sampGetPlayerScore(player_id) .. '\n')
            file:flush()
        end
    end
    if file ~= nil then file:close() end
end

function getPlayerIdByNickname(string)
    for i = 0, 999 do
        if sampIsPlayerConnected(i) or i == select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)) then
            if sampGetPlayerNickname(i):find(string) then
                return i
            end
        end
    end
    return nil
end
А если брать лвл из статы (диалог), надо чтобы по команде он сначала проверял стату одного из записанного человека через /stats nick, потом через диалог получал лвл, вот код:


Код:
function samp.onShowDialog(dialogId, style, title, button1, button2, text)
    if parsim and dialogId == 228 then
        for line in text:gmatch("[^\r\n]+") do
            if line:find("%{FFFFFF%}Административный уровень:%s+%{dfb519%}%d+") then
                adm_level = line:match("%{FFFFFF%}Административный уровень:%s+%{dfb519%}(%d+)")
            end
        end
        parsim = false
        sampSendDialogResponse(228, 1, -1, 'Готово')
        return false
    end
end