onservermessage

Fasmin

Известный
Автор темы
199
12
Версия MoonLoader
.026-beta
Вот допустип получаю я сообщение из чата привет как ДЕЛА у тебя?
как мне найти все заглавные букты от 3 букв?
Типо если пришло сообщение капсом более 3 символом, то будет true
 

луа передоз

Известный
96
79
Lua:
local sampev = require('lib.samp.events')

local MINIMUM_UPPERCASE = 3

local function isUppercaseByte(byte)
    -- Английские A-Z
    if byte >= 65 and byte <= 90 then
        return true
    end

    -- Русские А-Я и Ё в Windows-1251
    return (byte >= 192 and byte <= 223) or byte == 168
end

local function hasUppercaseSequence(text, minimum)
    if type(text) ~= 'string' then
        return false
    end

    minimum = tonumber(minimum) or 3

    if minimum < 1 then
        minimum = 1
    end

    -- Удаляем цветовые коды SA-MP, чтобы буквы A-F
    -- внутри {FFFFFF} не считались капсом
    text = text:gsub('{%x%x%x%x%x%x}', '')

    local count = 0

    for i = 1, #text do
        if isUppercaseByte(text:byte(i)) then
            count = count + 1

            if count >= minimum then
                return true
            end
        else
            count = 0
        end
    end

    return false
end

function sampev.onServerMessage(color, text)
    if hasUppercaseSequence(text, MINIMUM_UPPERCASE) then
        sampAddChatMessage(
            '{FF9900}[CAPS] {FFFFFF}Обнаружено сообщение с капсом: ' .. text,
            -1
        )
    end
end

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then
        return
    end

    while not isSampAvailable() do
        wait(100)
    end

    sampAddChatMessage(
        '{FF9900}[CAPS] {FFFFFF}Скрипт загружен.',
        -1
    )

    while true do
        wait(0)
    end
end
 

Вложения

  • caps.lua
    1.5 KB · Просмотры: 0
Последнее редактирование:

Joce

Известный
97
34
Lua:
local sampev = require('lib.samp.events')

local function hasCaps(text, min)
    local clean = text:gsub('{%x%x%x%x%x%x}', '')
    local count = 0

    for i = 1, #clean do
        local b = clean:byte(i)
        if (b >= 65 and b <= 90) or (b >= 192 and b <= 223) or b == 168 then
            count = count + 1
            if count >= (min or 3) then return true end
        else
            count = 0
        end
    end
    return false
end

function sampev.onServerMessage(color, text)
    if hasCaps(text, 3) then
        sampAddChatMessage('Обнаружен капс: ' .. text, -1)
    end
end

function main()
    while not isSampAvailable() do wait(100) end
    wait(-1)
end