Выполнение действия на нажатие кнопки при обнаружении заданного текста в чате

турбодизельный унитаз2012

Участник
Автор темы
127
9
Версия MoonLoader
.026-beta
Привет всем.
Хотелось бы узнать, как работает данная система.
У меня есть такой текст: "[Анти-реклама] *здесь ник*[id]: MQ". При обнаружении данного текста, вылазит sampAddChatMessage, в котом пишет "Нажмите *заданная клавиша*, чтобы выдать блокировку аккаунт *ник из [Анти-реклама]*.". По истечении 10 секунд, функция будет отменена.
При нажатии на кнопку, вводится /ban [id с Анти-Реклама] 1 Упоминание родни.
Пример ниже:
sa-mp-683.png
 

|| sk8ndestroy ||

Участник
38
16
Привет всем.
Хотелось бы узнать, как работает данная система.
У меня есть такой текст: "[Анти-реклама] *здесь ник*[id]: MQ". При обнаружении данного текста, вылазит sampAddChatMessage, в котом пишет "Нажмите *заданная клавиша*, чтобы выдать блокировку аккаунт *ник из [Анти-реклама]*.". По истечении 10 секунд, функция будет отменена.
При нажатии на кнопку, вводится /ban [id с Анти-Реклама] 1 Упоминание родни.
Пример ниже:
Посмотреть вложение 220525
Будет время, сделаю
 

MLycoris

Режим чтения
Проверенный
1,826
1,884
я чот такое однажды писал, попробуй, мб там что то придется изменить
Lua:
local sampev = require('lib.samp.events')
local font = renderCreateFont('TimesNewRoman', 12, 5)
local st = {
    bool = false,
    timer = -1,
    id = -1,
}

function main()
    while true do wait(0)
        if st.bool and st.timer ~= -1 then
            timer = os.clock()-st.timer
            renderFontDrawText(font,'Нажми Y чтоб замутить или N чтоб не мутить\nВремени на раздумья 6 сек, прошло: '..tostring(os.date("!*t", timer).sec), 500, 500, 0xFFFFFFFF)
            if timer>5 or wasKeyPressed(0x59) or wasKeyPressed(0x4E) then
                if wasKeyPressed(0x59) then
                    sampSendChat('/ban '..st.id..' 1 Упом. род')
                end
                st.bool = false
                st.timer = -1
            end
        end
    end
end
function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%]. mq') then
        st.id = text:lower():match('%[(%d+)%]. mq')
        st.bool = true
        st.timer = os.clock()
    end
end
 

турбодизельный унитаз2012

Участник
Автор темы
127
9
я чот такое однажды писал, попробуй, мб там что то придется изменить
Lua:
local sampev = require('lib.samp.events')
local font = renderCreateFont('TimesNewRoman', 12, 5)
local st = {
    bool = false,
    timer = -1,
    id = -1,
}

function main()
    while true do wait(0)
        if st.bool and st.timer ~= -1 then
            timer = os.clock()-st.timer
            renderFontDrawText(font,'Нажми Y чтоб замутить или N чтоб не мутить\nВремени на раздумья 6 сек, прошло: '..tostring(os.date("!*t", timer).sec), 500, 500, 0xFFFFFFFF)
            if timer>5 or wasKeyPressed(0x59) or wasKeyPressed(0x4E) then
                if wasKeyPressed(0x59) then
                    sampSendChat('/ban '..st.id..' 1 Упом. род')
                end
                st.bool = false
                st.timer = -1
            end
        end
    end
end
function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%]. mq') then
        st.id = text:lower():match('%[(%d+)%]. mq')
        st.bool = true
        st.timer = os.clock()
    end
end
+respect
Где можно изменить клавиши? А то я чайник


я чот такое однажды писал, попробуй, мб там что то придется изменить
Lua:
local sampev = require('lib.samp.events')
local font = renderCreateFont('TimesNewRoman', 12, 5)
local st = {
    bool = false,
    timer = -1,
    id = -1,
}

function main()
    while true do wait(0)
        if st.bool and st.timer ~= -1 then
            timer = os.clock()-st.timer
            renderFontDrawText(font,'Нажми Y чтоб замутить или N чтоб не мутить\nВремени на раздумья 6 сек, прошло: '..tostring(os.date("!*t", timer).sec), 500, 500, 0xFFFFFFFF)
            if timer>5 or wasKeyPressed(0x59) or wasKeyPressed(0x4E) then
                if wasKeyPressed(0x59) then
                    sampSendChat('/ban '..st.id..' 1 Упом. род')
                end
                st.bool = false
                st.timer = -1
            end
        end
    end
end
function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%]. mq') then
        st.id = text:lower():match('%[(%d+)%]. mq')
        st.bool = true
        st.timer = os.clock()
    end
end
Где можно изменить клавиши? А то я чайник
 
  • Bug
Реакции: Hinаta

TravkaCode.lover()

Активный
99
26

турбодизельный унитаз2012

Участник
Автор темы
127
9
я чот такое однажды писал, попробуй, мб там что то придется изменить
Lua:
local sampev = require('lib.samp.events')
local font = renderCreateFont('TimesNewRoman', 12, 5)
local st = {
    bool = false,
    timer = -1,
    id = -1,
}

function main()
    while true do wait(0)
        if st.bool and st.timer ~= -1 then
            timer = os.clock()-st.timer
            renderFontDrawText(font,'Нажми Y чтоб замутить или N чтоб не мутить\nВремени на раздумья 6 сек, прошло: '..tostring(os.date("!*t", timer).sec), 500, 500, 0xFFFFFFFF)
            if timer>5 or wasKeyPressed(0x59) or wasKeyPressed(0x4E) then
                if wasKeyPressed(0x59) then
                    sampSendChat('/ban '..st.id..' 1 Упом. род')
                end
                st.bool = false
                st.timer = -1
            end
        end
    end
end
function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%]. mq') then
        st.id = text:lower():match('%[(%d+)%]. mq')
        st.bool = true
        st.timer = os.clock()
    end
end
Lua:
local font = renderCreateFont('TimesNewRoman', 12, 5)
local st = {
    bool = false,
    timer = -1,
    id = -1,
}

function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%]. mq') then
        st.id = text:lower():match('%[(%d+)%]. mq')
        st.bool = true
        st.timer = os.clock()
    end
end




function main()
    while not isSampAvailable() do wait(100) end
        while true do wait(0)
         if st.bool and st.timer ~= -1 then
                timer = os.clock()-st.timer
                renderFontDrawText(font,'Нажми F1 чтоб замутить или X чтоб не мутить\nВремени на раздумья 6 сек, прошло: '..tostring(os.date("!*t", timer).sec), 500, 500, 0xFFFFFFFF)
                if timer>5 or wasKeyPressed(0x70) or wasKeyPressed(    0x58) then
                    if wasKeyPressed(0x59) then
                        sampSendChat('/ban '..st.id..' 1 Упом. род')
                    end
                    st.bool = false
                    st.timer = -1
                end
            end
        end
    sampRegisterChatCommand -- здесь мои команды
    sampAddChatMessage("{FFCC00}Helper {0099CC}Beta: {FFCC00}Скрипт успешно загружен.", 0xFFCC00)
    sampAddChatMessage("{FFCC00}Helper {0099CC}Beta: {FFCC00}Для просмотра функций пропишите /helper.", 0xFFCC00)
end

function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%]. mq') then
        st.id = text:lower():match('%[(%d+)%]. mq')
        st.bool = true
        st.timer = os.clock()
    end
end

Заменил кнопки, вставил в свой основной код. Скрипт загрузился, но функция выдачи бана не работает.
 

MLycoris

Режим чтения
Проверенный
1,826
1,884
Lua:
local font = renderCreateFont('TimesNewRoman', 12, 5)
local st = {
    bool = false,
    timer = -1,
    id = -1,
}

function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%].+ mq') then
        st.id = text:lower():match('%[(%d+)%].+ mq')
        st.bool = true
        st.timer = os.clock()
    end
end




function main()
    while not isSampAvailable() do wait(100) end
        while true do wait(0)
         if st.bool and st.timer ~= -1 then
                timer = os.clock()-st.timer
                renderFontDrawText(font,'Нажми F1 чтоб замутить или X чтоб не мутить\nВремени на раздумья 6 сек, прошло: '..tostring(os.date("!*t", timer).sec), 500, 500, 0xFFFFFFFF)
                if timer>5 or wasKeyPressed(0x70) or wasKeyPressed(    0x58) then
                    if wasKeyPressed(0x59) then
                        sampSendChat('/ban '..st.id..' 1 Упом. род')
                    end
                    st.bool = false
                    st.timer = -1
                end
            end
        end
    sampRegisterChatCommand -- здесь мои команды
    sampAddChatMessage("{FFCC00}Helper {0099CC}Beta: {FFCC00}Скрипт успешно загружен.", 0xFFCC00)
    sampAddChatMessage("{FFCC00}Helper {0099CC}Beta: {FFCC00}Для просмотра функций пропишите /helper.", 0xFFCC00)
end

function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%]. mq') then
        st.id = text:lower():match('%[(%d+)%]. mq')
        st.bool = true
        st.timer = os.clock()
    end
end

Заменил кнопки, вставил в свой основной код. Скрипт загрузился, но функция выдачи бана не работает.
сравни мой и свой код, основные ошибки то что не подключен самп ивентс, 2 функции отлавливающие сообщ и не заменил клавишу в условии перед отправкой в чат, ну а ещё самое странное это текст в чат и кривая попытка зарегать команду в беск цикле
Lua:
local font = renderCreateFont('TimesNewRoman', 12, 5)
local sampev = require('lib.samp.events')
local st = {
    bool = false,
    timer = -1,
    id = -1,
}

function sampev.onServerMessage(color, text)
    if text:lower():find('%[%d+%]. mq') then
        st.id = text:lower():match('%[(%d+)%]. mq')
        st.bool = true
        st.timer = os.clock()
    end
end

function main()
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage("{FFCC00}Helper {0099CC}Beta: {FFCC00}Скрипт успешно загружен.", 0xFFCC00)
    sampAddChatMessage("{FFCC00}Helper {0099CC}Beta: {FFCC00}Для просмотра функций пропишите /helper.", 0xFFCC00)
    sampRegisterChatCommand('helper', function()
        -- код, который будет выполняться при команде выше
    end)
    while true do wait(0)
    if st.bool and st.timer ~= -1 then
            timer = os.clock()-st.timer
            renderFontDrawText(font,'Нажми F1 чтоб замутить или X чтоб не мутить\nВремени на раздумья 10 сек, прошло: '..tostring(os.date("!*t", timer).sec), 500, 500, 0xFFFFFFFF)
            if timer>10 or wasKeyPressed(0x70) or wasKeyPressed(0x58) then
                if wasKeyPressed(0x70) then
                    sampSendChat('/ban '..st.id..' 1 Упом. род')
                end
                st.bool = false
                st.timer = -1
            end
        end
    end
end
1699378850493.png