Помогите скрипт ноу ворк

cloused2

Активный
Автор темы
310
91
Версия SA-MP
  1. Любая
  2. Другая
Lua:
local smoke = false
local drugs = false

local name1 = "[AutoHeal]" -- Тег AutoSmoke
local name2 = "[AutoDrugs]" -- Тег AutoDrugs
local yellow = "{ff8c00}" -- Желтый цвет
local white = "{ffffff}" -- Белый цвет

local tag1 = yellow .. name1 .. white
local tag2 = yellow .. name2 .. white


function main()
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(tag1 .. " Успешно загружен! Активация: /autosmoke // /autodrugs", -1)
    sampRegisterChatCommand('autosmoke', asmoke)
    sampRegisterChatCommand('autodrugs', adrugs)
end
    

function asmoke()
smoke = not smoke
    if smoke then
        sampAddChatMessage(tag1 .. " Включен!", -1)
        printStringNow('AutoSmoke ~g~ON', 3000)
        while true do
            wait(0)       
            local health = getCharHealth(PLAYER_PED)
                if health < 25 then
                    wait(1500)
                    sampSendChat("/smoke")
                end
            end       
    else
        sampAddChatMessage(tag1 .. " Выключен!", -1)
        printStringNow('AutoSmoke ~r~OFF', 3000)
    end
end

function adrugs()

    adrugs = not adrugs
        if adrugs then
            sampAddChatMessage(tag2 .. " Включен!", -1)
            printStringNow('AutoDrugs ~g~ON', 3000)
            while true do
                wait(0)       
                local health = getCharHealth(PLAYER_PED)
                    if health < 25 then
                        wait(1500)
                        sampSendChat("/usedrugs 3")
                    end
                end
        else
            sampAddChatMessage(tag2 .. " Выключен!", -1)
            printStringNow('AutoDrugs ~r~OFF', 3000)
        end
    end
 

Tensay

Активный
169
51
Нельзя в функции while true do создавать, создай отдельный поток в main, ну либо в самой функции поток создавать и с ним работать

Попробуй, писал на телефоне, поэтому может не заработать, если что кидай мунлог


123123:
local smoke = false
local drugs = false

local name1 = "[AutoHeal]" -- Тег AutoSmoke
local name2 = "[AutoDrugs]" -- Тег AutoDrugs
local yellow = "{ff8c00}" -- Желтый цвет
local white = "{ffffff}" -- Белый цвет

local tag1 = yellow .. name1 .. white
local tag2 = yellow .. name2 .. white


function main()
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(tag1 .. " Успешно загружен! Активация: /autosmoke // /autodrugs", -1)
    sampRegisterChatCommand('autosmoke', asmoke)
    sampRegisterChatCommand('autodrugs', adrugs)
end
    

function asmoke()
smoke = not smoke
    if smoke then
        sampAddChatMessage(tag1 .. " Включен!", -1)
        printStringNow('AutoSmoke ~g~ON', 3000)
        lua_thread.create(function()
        while true do
            wait(0)       
            local health = getCharHealth(PLAYER_PED)
                if health < 25 then
                    wait(1500)
                    sampSendChat("/smoke")
                end
            end
        end)     
    else
        sampAddChatMessage(tag1 .. " Выключен!", -1)
        printStringNow('AutoSmoke ~r~OFF', 3000)
    end
end

function adrugs()

    adrugs = not adrugs
        if adrugs then
            sampAddChatMessage(tag2 .. " Включен!", -1)
            printStringNow('AutoDrugs ~g~ON', 3000)
            lua_thread.create(function()
            while true do
                wait(0)       
                local health = getCharHealth(PLAYER_PED)
                    if health < 25 then
                        wait(1500)
                        sampSendChat("/usedrugs 3")
                    end
                end
            end)
        else
            sampAddChatMessage(tag2 .. " Выключен!", -1)
            printStringNow('AutoDrugs ~r~OFF', 3000)
        end
    end
 

Tensay

Активный
169
51
Попробуй
123123:
local smoke = false
local drugs = false

local name1 = "[AutoHeal]" -- Тег AutoSmoke
local name2 = "[AutoDrugs]" -- Тег AutoDrugs
local yellow = "{ff8c00}" -- Желтый цвет
local white = "{ffffff}" -- Белый цвет

local tag1 = yellow .. name1 .. white
local tag2 = yellow .. name2 .. white


function main()
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(tag1 .. " Успешно загружен! Активация: /autosmoke // /autodrugs", -1)
    sampRegisterChatCommand('autosmoke', asmoke)
    sampRegisterChatCommand('autodrugs', adrugs)
    lua_thread.create(tsmoke)
    lua_thread.create(tdrugs)
end
   

function asmoke()
    if !smoke then
        smoke = true
        sampAddChatMessage(tag1 .. " Включен!", -1)
        printStringNow('AutoSmoke ~g~ON', 3000)
    else
        smoke = false
        sampAddChatMessage(tag1 .. " Выключен!", -1)
        printStringNow('AutoSmoke ~g~OFF', 3000)
    end
end
   

function tsmoke()
    while true do wait(0)
        if smoke then    
            local health = getCharHealth(PLAYER_PED)
            if health < 25 then
                wait(1500)
                 sampSendChat("/smoke")
            end
        end
    end
end

function asmoke()
    if !drugs then
        drugs = true
        sampAddChatMessage(tag1 .. " Включен!", -1)
        printStringNow('AutoDrugs ~g~ON', 3000)
    else
        drugs = false
        sampAddChatMessage(tag1 .. " Выключен!", -1)
        printStringNow('AutoDrugs ~g~OFF', 3000)
    end
end


function tsmoke()
    while true do wait(0)
        if smoke then    
            local health = getCharHealth(PLAYER_PED)
            if health < 25 then
                wait(1500)
                sampSendChat("/smoke")
            end
        end
    end
end

Я там ON OFF перепутал слегка, сейчас подправил