help, не работает

luckyshit04

Известный
Автор темы
3
0
Форматирование кода
Lua:
local sampev = require 'lib.samp.events'

local mom = false
local isKeyPressed = false
local keyPressTimer = 0

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(0) end

    sampAddChatMessage("[PIDR] {00FF00}Script loaded. Use /pidr to toggle.", -1)
    sampRegisterChatCommand("pidr", togglePidr)

    while true do
        wait(0)

        -- удерживаем N 100 мс
        if isKeyPressed then
            keyPressTimer = keyPressTimer + 1
            if keyPressTimer == 1 then
                setVirtualKeyDown(0x4E, true) -- Нажать N
            elseif keyPressTimer == 6 then
                setVirtualKeyDown(0x4E, false) -- Отпустить N
                isKeyPressed = false
                keyPressTimer = 0
            end
        end
    end
end

function togglePidr()
    mom = not mom
    local text = mom and "{00FF00}pidr on" or "{FF0000}pidr off"
    sampAddChatMessage("[PIDR] " .. text, -1)
end

function sampev.onServerMessage(color, msg)
    if mom then
        local cleanMsg = msg:gsub("{........}", ""):lower()
        if cleanMsg:find("пидр иди сюда") then
            isKeyPressed = true
            keyPressTimer = 0
        end
    end
end


суть, чтобы при появление нужного текста в чате нажимало на N,

хз в чем ошибка
 
Последнее редактирование модератором:

verdis

Участник
53
4
Lua:
require "lib.moonloader"

local sampev = require('samp.events')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

function sampev.onServerMessage(color, message)
    local decoded_msg = u8(message):lower()
    if decoded_msg:find("Текст") then
        setVirtualKeyDown(VK_N, true)
        wait(100)
        setVirtualKeyDown(VK_N, false)
    end
end