Помогите сделать активацию на кнопку

Статус
В этой теме нельзя размещать новые ответы.

tema.me

Новичок
Автор темы
6
0
Версия MoonLoader
Другое
Скрипт переделал с автоответчика, для ловли репорта. мне просто так нравится.
Не могу переделать его на клавишу Х.
Просьба сделать на клавишу и активацию по команде /fl оставить, буду благодарен.
Lua:
if not doesDirectoryExist("moonloader/config") then createDirectory("moonloader/config") end

script_author("Armadillo-CLD")
script_name("AutoAnswer")
script_description("Automatically answers questions in the chat")

local SE = require 'samp.events'
local question = {"Жалоба]"}
local answer =   {"/ot",   }

local started = false

function notf(text)
    sampAddChatMessage('*'..text,0x63BD4E)
end

function notfi(text)
    sampAddChatMessage('*'..text,0xF04245)
end

function main()
    while not isSampAvailable() do wait(0) end

    wait(0)
    sampRegisterChatCommand("fl", startaa)

   
    while true do
        wait(0)
    end
end

function SE.onServerMessage(color, text)
lua_thread.create(function()
    wait(1)
    if started == true then
        for i=1,#question do
            if string.match(text, question[i]) then
                wait(0)
                sampSendChat(answer[i])
                break
            end
        end
        return
    end
end)
end

function startaa()
    if started == true then
        started = false
        notfi(" {999999}Выключено.", -1)
    else
        started = true
        notf(" {FFFFFF}Включено.", -1)
    end
end
 
  • Bug
Реакции: NikitaUsmanov
Решение
Lua:
--в начало
local vkeys = require "vkeys"
sampRegisterChatCommand('fl', function() started = not started end)
--Это в мейн впихни
if isKeyJustPressed(VK_X) then
    started = not started
end
--писал с телефона если будут ошибки исправь

kyrtion

Известный
661
242
делать нечего, решил написать полностью нормальный скрипт
Lua:
script_author('Armadillo-CLD')
script_name('AutoAnswer')
script_description('Automatically answers questions in the chat')

local sampev = require('samp.events')

local regExpChatReport = '^%[Жалоба%] от (%S+)%[(%d+)%]:%s+(.*)$'
local started = false

local chat = {} do
  chat.log = function(message, ...)
    local fmt = string.format('[AutoAnswer] '..message, ...)
    sampAddChatMessage(fmt, 0xAAAAAA)
  end

  chat.success = function(message, ...)
    local fmt = string.format('[AutoAnswer] '..message, ...)
    sampAddChatMessage(fmt, 0x63BD4E)
  end

  chat.error = function(message, ...)
    local fmt = string.format('[AutoAnswer] '..message, ...)
    sampAddChatMessage(fmt, 0xF04245)
  end

  chat.send = function(message, ...)
    local fmt = string.format(message, ...)
    sampSendChat(fmt)
  end

  chat.asyncSend = function(message, ...)
    local fmt = string.format(message, ...)
    lua_thread.create(function()
      wait(1)
      sampSendChat(fmt)
    end)
  end
end

function main()
  while not isSampAvailable() do wait(0) end

  if not doesDirectoryExist('moonloader/config') then createDirectory('moonloader/config') end

  sampRegisterChatCommand('fl', function()
    started = not started
    chat.log('Ловля репорт - %s', started and '{0011FF}Включено' or '{999999}Выключено')
  end)

  wait(-1)
end

function sampev.onServerMessage(color, text)
  local textNoHex = text:gsub('{%x%x%x%x%x%x}', ''):gsub('^%s+', '')

  if textNoHex:find(regExpChatReport) and started then
    local playerNickname, playerId, messageReport = textNoHex:match(regExpChatReport)
    playerId = tonumber(playerId)
    -- Example: [Жалоба] от Nick_Name[123]: hello world
    -- playerNickname: "Nick_Name"
    -- playerId: "123"
    -- messageReport: "hello world"

    -- ... your code
    -- maybe send async command /ot? => chat.asyncSend('/ot')
  end
end
 
Статус
В этой теме нельзя размещать новые ответы.