Помогите исправить скрипт. Неправильно отображаются никнеймы игроков в логах

Tr1x2er

Участник
Автор темы
102
10
Версия SA-MP
  1. 0.3.7 (R1)
  2. 0.3.7-R2
  3. Любая
  4. Другая
код на луа:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('spr', function()
        window[0] = not window[0]
    end)
end

function hook.onServerMessage(color, text)
    table.insert(chatLines, text)
    if spamActive[0] then
        processChatLines()
    end
end

function processChatLines()
    local command = u8:decode(ffi.string(commandText))
    for i = lastProcessedMessageId + 1, #chatLines do
        local text = chatLines[i]
        for _, word in ipairs(triggerWords) do
            local trigger = u8:decode(ffi.string(word))
            if string.find(text, trigger) then
                local playerName, playerId = extractPlayerInfo(text)
                if playerName and playerId then
                    updatePlayerLogs(playerName, playerId)
                end
                lua_thread.create(function()
                    sampSendChat(command)
                    wait(spamDelay[0])
                end)
                break
            end
        end
        lastProcessedMessageId = i
    end
end

function extractPlayerInfo(text)
    local playerName = string.match(text, "^(%S+)")
    local playerId = string.match(text, "%[ID:(%d+)%]")
    return playerName, playerId
end

function updatePlayerLogs(playerName, playerId)
    local entry = playerName .. " " .. playerId
    if not playerLogEntries[entry] then
        playerLogEntries[entry] = true
        local currentLogs = ffi.string(playerLogs)
        local newLogEntry = string.format("%s\n", entry)
        local updatedLogs = currentLogs .. newLogEntry
        ffi.copy(playerLogs, updatedLogs)
    end
end

main()
sa-mp-089.png
 
  • Клоун
Реакции: MLycoris

976h

Активный
202
57
код на луа:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('spr', function()
        window[0] = not window[0]
    end)
end

function hook.onServerMessage(color, text)
    table.insert(chatLines, text)
    if spamActive[0] then
        processChatLines()
    end
end

function processChatLines()
    local command = u8:decode(ffi.string(commandText))
    for i = lastProcessedMessageId + 1, #chatLines do
        local text = chatLines[i]
        for _, word in ipairs(triggerWords) do
            local trigger = u8:decode(ffi.string(word))
            if string.find(text, trigger) then
                local playerName, playerId = extractPlayerInfo(text)
                if playerName and playerId then
                    updatePlayerLogs(playerName, playerId)
                end
                lua_thread.create(function()
                    sampSendChat(command)
                    wait(spamDelay[0])
                end)
                break
            end
        end
        lastProcessedMessageId = i
    end
end

function extractPlayerInfo(text)
    local playerName = string.match(text, "^(%S+)")
    local playerId = string.match(text, "%[ID:(%d+)%]")
    return playerName, playerId
end

function updatePlayerLogs(playerName, playerId)
    local entry = playerName .. " " .. playerId
    if not playerLogEntries[entry] then
        playerLogEntries[entry] = true
        local currentLogs = ffi.string(playerLogs)
        local newLogEntry = string.format("%s\n", entry)
        local updatedLogs = currentLogs .. newLogEntry
        ffi.copy(playerLogs, updatedLogs)
    end
end

main()
Посмотреть вложение 247232
Конвертировать не пробывал?