SA:MP CR:MP Хелп с arg

Ancwork

Участник
Автор темы
67
8
Версия SA-MP
  1. Любая
Я хочу чтобы через arg взялся ID. Допустим я пишу /msm 433 и происходит флуд каждые 2 секунду /setmark 433. Я немного не допёр как сделать.

Lua:
   -- Flood setmark
    sampRegisterChatCommand('msm', msm)
    msm = false
    local thread = lua_thread.create(sampmsm)

-- Flood setmark
    function msm()
    msm = not msm
    if msm then
        sampAddChatMessage("вкл", -1)
    else
        sampAddChatMessage("выкл", -1)
    end
end

function sampmsm()
    while true do
        wait(2000)
        if msm then
            sampSendChat("/setmark")
        end
    end
end
 
Решение
А отдельными функциями... В таком формате у меня у самого есть. Не хочется засорять main
Lua:
local msm = ''
local act = false

function main()
    while not isSampfuncsLoaded() do wait(100) end

    sampRegisterChatCommand('msm', function(arg)
        msm = arg
        if act then
            act = false
            sampAddChatMessage('Выключен', -1)
        else
            if msm:match('%d+') then
                act = true
                sampAddChatMessage('Включен, арг: '..msm, -1)
                
                lua_thread.create(function ()
                    while act do
                        wait(2000)
                        sampSendChat('/setmark '..msm)
                    end
                end)...

yellowakyloff

Новичок
24
2
Если я все правильно понял, то вот:

local msg = false
local id = nil
local thread = nil

sampRegisterChatCommand('msg', function(arg)
if arg and arg:match("^%d+$") then
id = arg
msg = not msg
if msg then
sampAddChatMessage("вкл: " .. id, -1)
thread = lua_thread.create(sampmsg)
else
sampAddChatMessage("выкл", -1)
if thread then
lua_thread.kill(thread)
thread = nil
end
end
end)

function sampmsg()
while true do
wait(2000)
if msg and id then
sampSendChat("/setmark " .. id)
end
end
end
 

Ancwork

Участник
Автор темы
67
8
est.lua:23: unexpected symbol near ')'
[ML] (error) Test.lua: Script died due to an error. (id:6)
Lua:
function main()
repeat wait(0) until isSampAvailable()
sampRegisterChatCommand('msm', msm)
local msg = false
local id = nil
local thread = nil
end

function msm(arg)
if arg and arg:match("^%d+$") then
id = arg
msm = not msm
if msm then
sampAddChatMessage("вкл"..id, -1)
thread = lua_thread.create(sampmsm)
else
sampAddChatMessage("выкл"..id, -1)
if thread then
lua_thread.kill(thread)
thread = nil
        end
    end
end)

function sampmsm()
while true do
wait(2000)
if msm and it then
sampSendChat("/setmark"..id)
        end
    end
end
 
Последнее редактирование:

IlyaFontonov

Активный
187
49
Lua:
local msm = ''
local act = false

function main()
    while not isSampfuncsLoaded() do wait(100) end

    sampRegisterChatCommand('msm', function(arg)
        msm = arg
        if act then
            act = false
            sampAddChatMessage('Выключен', -1)
        else
            if msm:match('%d+') then
                act = true
                sampAddChatMessage('Включен, арг: '..msm, -1)
            else
                sampAddChatMessage('Вы ошиблись с арг в команде! Пример: /msm 123', -1)
            end
        end
    end)

    while true do
        wait(0)

        if act then
            wait(2000)
            sampSendChat('/setmark '..msm)
        end
    end
end
 

Ancwork

Участник
Автор темы
67
8
Lua:
local msm = ''
local act = false

function main()
    while not isSampfuncsLoaded() do wait(100) end

    sampRegisterChatCommand('msm', function(arg)
        msm = arg
        if act then
            act = false
            sampAddChatMessage('Выключен', -1)
        else
            if msm:match('%d+') then
                act = true
                sampAddChatMessage('Включен, арг: '..msm, -1)
            else
                sampAddChatMessage('Вы ошиблись с арг в команде! Пример: /msm 123', -1)
            end
        end
    end)

    while true do
        wait(0)

        if act then
            wait(2000)
            sampSendChat('/setmark '..msm)
        end
    end
end
А отдельными функциями... В таком формате у меня у самого есть. Не хочется засорять main
 

IlyaFontonov

Активный
187
49
А отдельными функциями... В таком формате у меня у самого есть. Не хочется засорять main
Lua:
local msm = ''
local act = false

function main()
    while not isSampfuncsLoaded() do wait(100) end

    sampRegisterChatCommand('msm', function(arg)
        msm = arg
        if act then
            act = false
            sampAddChatMessage('Выключен', -1)
        else
            if msm:match('%d+') then
                act = true
                sampAddChatMessage('Включен, арг: '..msm, -1)
                
                lua_thread.create(function ()
                    while act do
                        wait(2000)
                        sampSendChat('/setmark '..msm)
                    end
                end)
            else
                sampAddChatMessage('Вы ошиблись с арг в команде! Пример: /msm 123', -1)
            end
        end
    end)

    while true do
        wait(0)
    end
end
 

Ancwork

Участник
Автор темы
67
8
Lua:
local msm = ''
local act = false

function main()
    while not isSampfuncsLoaded() do wait(100) end

    sampRegisterChatCommand('msm', function(arg)
        msm = arg
        if act then
            act = false
            sampAddChatMessage('Выключен', -1)
        else
            if msm:match('%d+') then
                act = true
                sampAddChatMessage('Включен, арг: '..msm, -1)
              
                lua_thread.create(function ()
                    while act do
                        wait(2000)
                        sampSendChat('/setmark '..msm)
                    end
                end)
            else
                sampAddChatMessage('Вы ошиблись с арг в команде! Пример: /msm 123', -1)
            end
        end
    end)

    while true do
        wait(0)
    end
end
Спасибо. Взял за основу твой код.
Даю мой ответный код, может кому нужно будет. Получилось так:

Lua:
local msm = ''
local act = false

 function main()
repeat wait(0) until isSampAvailable()
sampRegisterChatCommand('msm', msm)
wait(-1)
end

 function msm(arg)
    msm = arg
    if act then
        act = false
        sampAddChatMessage("выкл", -1)
    else
            if msm:match('%d+') then
                act = true
                sampAddChatMessage('Включен, арг: '..msm, -1)
               
                lua_thread.create(function ()
                    while act do
                        wait(2000)
                        sampSendChat('/setmark '..msm)
                    end
                end)
            else
                sampAddChatMessage('Вы ошиблись с арг в команде! Пример: /msm 123', -1)
            end
        end
    end