Не работает активация и деактивация.

sat0ry

Известный
Автор темы
1,087
289
Версия MoonLoader
.026-beta
Всем здарова, не работает деактивация и активация скрипту абсолютно похуй на проверку он все равно продолжает работать даже если деактивирован.
LUA:
require 'lib.moonloader'
local sampev = require 'lib.samp.events'

local enable = false

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

    sampRegisterChatCommand('fastot', fastot)

    while true do
        wait(0)
    end
end

function fastot()
    enable = not enable
    
    if enable then
        printString('Script activated', 1000)
        function sampev.onServerMessage(color, text)
            if text:find('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:') then
                text:match('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:')
                sampSendChat('/ot')
            end
        end
    else
        printString('Script deactivated', 1000)
    end
end
 

Dmitriy Makarov

25.05.2021
Проверенный
2,481
1,113
Как-то так.
Lua:
require 'lib.moonloader'
local sampev = require 'lib.samp.events'

local enable = false

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('fastot', function()
        enable = not enable
        printString('Script '..(enable and 'activated' or 'deactivated'), 1000)
    end)
    while true do
        wait(0)
    end
end

function sampev.onServerMessage(color, text)
    if text:find('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:') and enable then
        sampSendChat('/ot')
    end
end
 
Последнее редактирование:
  • Влюблен
Реакции: sat0ry и blzlchk

qdIbp

Автор темы
Проверенный
1,387
1,144
Как-то так.
Lua:
require 'lib.moonloader'
local sampev = require 'lib.samp.events'

local enable = false

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('fastot', function()
        enable = not enable
        printString('Script '..(enable and 'activated' or 'deactivated'), 1000)
    end)
    while true do
        wait(0)
    end
end

function sampev.onServerMessage(color, text)
    if text:find('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:') and enable then
        sampSendChat('/ot')
    end
end
Лучше бы поставить
Lua:
wait(-1)
за место
Lua:
    while true do
        wait(0)
т.к никак не используется
 
  • Нравится
  • Влюблен
Реакции: Dmitriy Makarov и sat0ry

W.H.

Участник
25
64
Всем здарова, не работает деактивация и активация скрипту абсолютно похуй на проверку он все равно продолжает работать даже если деактивирован.
LUA:
require 'lib.moonloader'
local sampev = require 'lib.samp.events'

local enable = false

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

    sampRegisterChatCommand('fastot', fastot)

    while true do
        wait(0)
    end
end

function fastot()
    enable = not enable
 
    if enable then
        printString('Script activated', 1000)
        function sampev.onServerMessage(color, text)
            if text:find('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:') then
                text:match('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:')
                sampSendChat('/ot')
            end
        end
    else
        printString('Script deactivated', 1000)
    end
end
Потому что ты сунул функцию samp.events в функцию fastot, а events работает в потоке, из-за чего она работает даже если ты выключил статус работы
Вытащи function sampev.onServerMessage(color, text) и поставь внутри него условие if enable then
Да и код у тебя что ни есть плохой, куча условий и лишняя функция, что мешает нормальному чтению скрипта
В хорошем варианте код у тебя будет выглядеть вот так
Lua:
require 'lib.moonloader'
local sampev = require 'lib.samp.events'

local enable = false

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

    sampRegisterChatCommand('fastot', function()
        enable = not enable
        printString(enable and 'Script activated' or "Script deactivated", 1000)
    end)

    while true do
        wait(0)
    end
end



function sampev.onServerMessage(color, text)
    if text:find('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:') and enable then
        text:match('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:')
        sampSendChat('/ot')
    end
end
 
  • Влюблен
Реакции: sat0ry

sat0ry

Известный
Автор темы
1,087
289
Как-то так.
Lua:
require 'lib.moonloader'
local sampev = require 'lib.samp.events'

local enable = false

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('fastot', function()
        enable = not enable
        printString('Script '..(enable and 'activated' or 'deactivated'), 1000)
    end)
    while true do
        wait(0)
    end
end

function sampev.onServerMessage(color, text)
    if text:find('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:') and enable then
        sampSendChat('/ot')
    end
end
Лучше бы поставить
Lua:
wait(-1)
за место
Lua:
    while true do
        wait(0)
т.к никак не используется
Потому что ты сунул функцию samp.events в функцию fastot, а events работает в потоке, из-за чего она работает даже если ты выключил статус работы
Вытащи function sampev.onServerMessage(color, text) и поставь внутри него условие if enable then
Да и код у тебя что ни есть плохой, куча условий и лишняя функция, что мешает нормальному чтению скрипта
В хорошем варианте код у тебя будет выглядеть вот так
Lua:
require 'lib.moonloader'
local sampev = require 'lib.samp.events'

local enable = false

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

    sampRegisterChatCommand('fastot', function()
        enable = not enable
        printString(enable and 'Script activated' or "Script deactivated", 1000)
    end)

    while true do
        wait(0)
    end
end



function sampev.onServerMessage(color, text)
    if text:find('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:') and enable then
        text:match('%[(%W+)%] от (%w+_%w+)%[(%d+)%]:')
        sampSendChat('/ot')
    end
end
Всем спасибо, учту свои ошибки.