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