Помощь в lua коде

Cheese

Потрачен
Автор темы
43
10
Вот простенький код
код:
local sampev = require 'lib.samp.events'

function main()
  if not isSampfuncsLoaded() or not isSampLoaded() then return end
      while not isSampAvailable() do wait(100) end
      sampRegisterChatCommand("cmd", cmd)
      while true do
        wait(0)
      end
    end

  function sampev.onSendChat(message)
      return {'text'}
  end
Мне нужно что-бы при вводе команды /cmd - скрипт активировался ( это уже в коде ), а потом при вводе ещё раз команды /cmd - скрипт дезактивировался, и чтоб так можно было делать, бесконечно..
пример:
/cmd
скрипт активировался и
Код 2:
function sampev.onSendChat(message)
подменивается
/cmd ( ввели ещё раз )
скрипт дезактивировался и
Код 2:
function sampev.onSendChat(message)
не подменивается
лайк + лучший ответ тем кто рял помог
 
Решение
Lua:
local sampev = require 'lib.samp.events'
local active = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('cmd', function()
        active = not active
        sampAddChatMessage(active and 'вкл' or 'выкл', -1)
    end)
    while true do
        wait(0)
        --code
    end
end

function sampev.onServerMessage(color, text)
    if active then
        --code
    end
end

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,228
Lua:
local sampev = require 'lib.samp.events'
local active = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('cmd', function()
        active = not active
        sampAddChatMessage(active and 'вкл' or 'выкл', -1)
    end)
    while true do
        wait(0)
        --code
    end
end

function sampev.onServerMessage(color, text)
    if active then
        --code
    end
end
 
  • Нравится
Реакции: Cheese

Cheese

Потрачен
Автор темы
43
10
Lua:
local sampev = require 'lib.samp.events'
local active = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('cmd', function()
        active = not active
        sampAddChatMessage(active and 'вкл' or 'выкл', -1)
    end)
    while true do
        wait(0)
        --code
    end
end

function sampev.onServerMessage(color, text)
    if active then
        --code
    end
end
Спасибоньки только чтоб скрипт заработал пришлось немного изменить
code3:
local sampev = require 'lib.samp.events'
local active = false

function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('cmd', function()
        active = not active
        sampAddChatMessage(active and 'ON' or 'OFF', -1)
    end)
    while true do
        wait(0)
        --code
    end
end

function sampev.onSendChat(message)
    if active then
    return {'text'}
    end
end
( оставил код кому нада 0_o )
 

wulfandr

Известный
637
260
Спасибоньки только чтоб скрипт заработал пришлось немного изменить
code3:
local sampev = require 'lib.samp.events'
local active = false

function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('cmd', function()
        active = not active
        sampAddChatMessage(active and 'ON' or 'OFF', -1)
    end)
    while true do
        wait(0)
        --code
    end
end

function sampev.onSendChat(message)
    if active then
    return {'text'}
    end
end
( оставил код кому нада 0_o )
боюсь просить а это зачем ? return {'text'}
 

Cheese

Потрачен
Автор темы
43
10
боюсь просить а это зачем ? return {'text'}
я в теме писал уже ._. ну лана скажу ещё раз, это подмена сообщения персонажа, ну ты пишешь в чат а это сообщение подменивается text