script_name('CaptchaPRO')
script_authors('Cosmo')
require "moonloader"
local inicfg = require 'inicfg'
local vkeys = require 'vkeys'
local status = false
local cfg = inicfg.load({
main = {
key = 113,
record = nil
}
}, "Captcha")
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
if not doesFileExist(getWorkingDirectory()..'\\config\\Captcha.ini') then inicfg.save(cfg, 'Captcha.ini') end
sampRegisterChatCommand('keycap', function(keyId)
if tonumber(keyId) then
cfg.main.key = tonumber(keyId)
addOneOffSound(0, 0, 0, 1054)
if inicfg.save(cfg, 'Captcha.ini') then
sampfuncsLog('{AFAFAF}[Captcha] {FFFFFF}Клавиша активации изменена на: {AFAFAF}'..keyId)
end
end
end)
sampfuncsLog('{FFC900}[Captcha] {FFFFFF}Скрипт загружен! Автор: {FFC900}Сosmo. {FFFFFF}Рекорд ввода: {FFC900}'..(cfg.main.record ~= nil and cfg.main.record..' сек!' or 'Отсутвует!'))
while true do wait(0)
if isKeyJustPressed(cfg.main.key) and not sampIsCursorActive() then getDialog() end
local result, button, list, input = sampHasDialogRespond(22222)
if result and status then
if button == 1 then
input = input:gsub('%s', '')
local timer = ("%.2f sec"):format(os.clock() - startTime)
if tostring(input) == tostring(captcha) then
addOneOffSound(0.0, 0.0, 0.0, 1054)
if cfg.main.record == nil or (os.clock() - startTime) < cfg.main.record then
sampfuncsLog('{FFC900}[Captcha] {FFFFFF}Введена верно: {FFC900}( '..input..'{FFFFFF} / {FFC900}'..captcha..' ) {FFFFFF}за{FFC900} '..timer..' ( Рекорд! ). {FFFFFF}Первая цифра введена за: {FFC900}'..firstKeyTime..' sec')
printStyledString('~y~'..timer, 3000, 4)
cfg.main.record = floorStep(os.clock() - startTime, 0.01)
inicfg.save(cfg, 'Captcha.ini')
else
sampfuncsLog('{50FF50}[Captcha] {FFFFFF}Введена верно: {50FF50}( '..input..'{FFFFFF} / {50FF50}'..captcha..' ) {FFFFFF}за{50FF50} '..timer..'.{FFFFFF} Первая цифра введена за: {50FF50}'..firstKeyTime..' sec')
printStyledString('~w~'..timer, 3000, 4)
end
else
addOneOffSound(0.0, 0.0, 0.0, 1057)
printStyledString('~r~Miss!', 3000, 4)
if input == '' then input = 'ничего' end
sampfuncsLog('{FF5050}[Captcha] {FFFFFF}Введена не верно: {FF5050}( '..input..'{FFFFFF} / {FF5050}'..captcha..' ) {FFFFFF}за{FF5050} '..timer)
end
else
sampfuncsLog('{AFAFAF}[Captcha] {FFFFFF}Отказались от ввода капчи: {AFAFAF}'..captcha)
end
status = false
end
if sampGetCurrentDialogId() == 22222 and sampIsDialogActive() and status then
local sw, sh = getScreenResolution()
renderDrawBoxWithBorder((sw - 380) / 2, (sh - 150) / 3, 380, 100, 0xFF76A4AB, 7, 0xFF121624)
tCaptcha = {}
for k in tostring(captcha):gmatch('%d') do table.insert(tCaptcha, k) end
local x = (sw - 340) / 2
local y = (sh - 110) / 3
for k, num in pairs(tCaptcha) do
drawCaptchaNum(tonumber(num), x, y, rth[k], 0xFF121624)
x = x + 70
end
end
end
end
function floorStep(num, step)
return num - num % step
end
function onWindowMessage(msg, wparam, lparam)
if sampGetCurrentDialogId() == 22222 and sampIsDialogActive() and not firstKey then
for _, key in pairs(tKeys) do
if wparam == key and isKeyDown(key) then
firstKey = true
firstKeyTime = floorStep(os.clock() - startTime, 0.01)
end
end
end
end
tKeys = {
0x60, 0x30, 0x61, 0x31,
0x62, 0x32, 0x63, 0x33,
0x64, 0x34, 0x65, 0x35,
0x66, 0x36, 0x67, 0x37,
0x68, 0x38, 0x69, 0x39
}
function getDialog()
status = true
startTime = os.clock()
firstKey = false
math.randomseed(os.clock())
-- generate captcha
captcha = tostring(math.random(1000, 9999)) -- first four nums
captcha = captcha:gsub(captcha, (math.random(1, 10) <= 6 and captcha..'0' or captcha..tostring(math.random(1, 9)))) -- 60% chance that the last num is zero
captcha = tonumber(captcha) -- tostring in tonumber
-- generate thickness
rth = {
[1] = math.random(8, 15),
[2] = math.random(8, 15),
[3] = math.random(8, 15),
[4] = math.random(8, 15),
[5] = math.random(8, 15)
}
-- offset digit 1 by x
oneOffset = math.random(0, 45)
sampShowDialog(22222, "{FF8B7A}Проверка на робота", "{ffffff}Введите {6CFF92}5{FFFFFF} символов, которые\nвидно на {6CFF92}вашем{FFFFFF} экране", "Принять", "Отмена", 1)
end
function drawCaptchaNum(num, posX, posY, thickness, color)
if num == 1 then
renderDrawBox(posX + oneOffset, posY, thickness, 70, color)
end
if num == 2 then
renderDrawBox(posX, posY, 50, thickness, color)
renderDrawBox(posX + 50, posY, thickness, 30, color)
renderDrawBox(posX, posY + 30, 50 + thickness, thickness, color)
renderDrawBox(posX, posY + 30, thickness, 30, color)
renderDrawBox(posX, posY + 60, 50 + thickness, thickness, color)
end
if num == 3 then
renderDrawBox(posX, posY, 50, thickness, color)
renderDrawBox(posX, posY + 30, 50, thickness, color)
renderDrawBox(posX, posY + 60, 50, thickness, color)
renderDrawBox(posX + 50, posY, thickness, 60 + thickness, color)
end
if num == 4 then
renderDrawBox(posX, posY, thickness, 30, color)
renderDrawBox(posX, posY + 30, 50, thickness, color)
renderDrawBox(posX + 50, posY, thickness, 70, color)
end
if num == 5 then
renderDrawBox(posX, posY, 50 + thickness, thickness, color)
renderDrawBox(posX, posY, thickness, 30, color)
renderDrawBox(posX, posY + 30, 50 + thickness, thickness, color)
renderDrawBox(posX + 50, posY + 30, thickness, 30, color)
renderDrawBox(posX, posY + 60, 50 + thickness, thickness, color)
end
if num == 6 then
renderDrawBox(posX, posY, 50 + thickness, thickness, color)
renderDrawBox(posX, posY, thickness, 60, color)
renderDrawBox(posX, posY + 30, 50 + thickness, thickness, color)
renderDrawBox(posX + 50, posY + 30, thickness, 30, color)
renderDrawBox(posX, posY + 60, 50 + thickness, thickness, color)
end
if num == 7 then
renderDrawBox(posX + 40, posY, thickness, 70, color)
renderDrawBox(posX, posY, 40, thickness, color)
end
if num == 8 then
renderDrawBox(posX, posY, 50 + thickness, thickness, color)
renderDrawBox(posX, posY, thickness, 60, color)
renderDrawBox(posX, posY + 30, 50 + thickness, thickness, color)
renderDrawBox(posX + 50, posY, thickness, 60, color)
renderDrawBox(posX, posY + 60, 50 + thickness, thickness, color)
end
if num == 9 then
renderDrawBox(posX, posY, 50 + thickness, thickness, color)
renderDrawBox(posX, posY, thickness, 30, color)
renderDrawBox(posX, posY + 30, 50 + thickness, thickness, color)
renderDrawBox(posX + 50, posY, thickness, 60, color)
renderDrawBox(posX, posY + 60, 50 + thickness, thickness, color)
end
if num == 0 then
renderDrawBox(posX, posY, 50 + thickness, thickness, color)
renderDrawBox(posX, posY, thickness, 60, color)
renderDrawBox(posX + 50, posY, thickness, 60, color)
renderDrawBox(posX, posY + 60, 50 + thickness, thickness, color)
end
end