Не работает Random

Kviyx

Новичок
Автор темы
16
5
Версия MoonLoader
.026-beta
Написал скрипт, который сам курит, но временной промежуток, когда именно должна прописываться команда "/smoke", нужен рандомный. Попытался это сделать, однако почему-то идет флуд функциями, хотя вроде все верно. Прошу объяснить, в чем ошибочка. Вот код:
Lua:
act = false

local str_rand = {'1244, 1343, 1588, 1797, 2135'}

function main()
    repeat
        wait(0)
    until isSampAvailable()
        sampAddChatMessage('Autosmoking is {FF0000}started', -1)

    sampRegisterChatCommand("asg",function() act = not act sampAddChatMessage(act and "Autosmoking: {00FF00}ON" or "Autosmoking: {FF0000}OFF", 0xFFFFFF) end)

                function test_random(arg)
                    math.randomseed(os.time())
                    rand = math.random(1, #str_rand)
                end

    while true do
        wait(rand)
        health = getCharHealth(PLAYER_PED)
        if act and health < 80 then
            sampSendChat("/smoke")
        end
    end
end
 
  • Эм
Реакции: qdIbp
Решение
Написал скрипт, который сам курит, но временной промежуток, когда именно должна прописываться команда "/smoke", нужен рандомный. Попытался это сделать, однако почему-то идет флуд функциями, хотя вроде все верно. Прошу объяснить, в чем ошибочка. Вот код:
Lua:
act = false

local str_rand = {'1244, 1343, 1588, 1797, 2135'}

function main()
    repeat
        wait(0)
    until isSampAvailable()
        sampAddChatMessage('Autosmoking is {FF0000}started', -1)

    sampRegisterChatCommand("asg",function() act = not act sampAddChatMessage(act and "Autosmoking: {00FF00}ON" or "Autosmoking: {FF0000}OFF", 0xFFFFFF) end)

                function test_random(arg)
                    math.randomseed(os.time())
                    rand =...

YarikVL

Известный
Проверенный
4,738
1,816
Написал скрипт, который сам курит, но временной промежуток, когда именно должна прописываться команда "/smoke", нужен рандомный. Попытался это сделать, однако почему-то идет флуд функциями, хотя вроде все верно. Прошу объяснить, в чем ошибочка. Вот код:
Lua:
act = false

local str_rand = {'1244, 1343, 1588, 1797, 2135'}

function main()
    repeat
        wait(0)
    until isSampAvailable()
        sampAddChatMessage('Autosmoking is {FF0000}started', -1)

    sampRegisterChatCommand("asg",function() act = not act sampAddChatMessage(act and "Autosmoking: {00FF00}ON" or "Autosmoking: {FF0000}OFF", 0xFFFFFF) end)

                function test_random(arg)
                    math.randomseed(os.time())
                    rand = math.random(1, #str_rand)
                end

    while true do
        wait(rand)
        health = getCharHealth(PLAYER_PED)
        if act and health < 80 then
            sampSendChat("/smoke")
        end
    end
end
Lua:
local str_rand = {'1244, 1343, 1588, 1797, 2135'} --не знаю зачем тебе это

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage('Autosmoking is {FF0000}started', -1)

    sampRegisterChatCommand("asg",function() act = not act sampAddChatMessage(act and "Autosmoking: {00FF00}ON" or "Autosmoking: {FF0000}OFF", 0xFFFFFF) end)
        
    while true do
        math.randomseed(os.time())
        rand = math.random(1244, 2135) -- рандомное количество миллисекунд в пределах от 1244 до 2135
        health = getCharHealth(PLAYER_PED)
        if act and health < 80 then
            sampSendChat("/smoke")
            wait(rand) -- подождет выше найденное рандомное количество миллисекунд и снова проверит if act == true and здоровье персонажа < 80 если да то тогда отправиться в чат еще раз команда smoke и так дальше по кругу
        end
    end
end
Не особо понял что ты хотел, но вот код. Ты можешь посмотреть гайды на ютубе The champ guess и сможешь сам сделать такой скрипт
 
  • Нравится
Реакции: Kviyx

Kviyx

Новичок
Автор темы
16
5
Ты хочешь чтобы он бран случайное число из массива?
И чтобы оно установилось один раз или всегда менялось?
Я хотел, чтобы в wait() брались рандомные числа из str_random.
Lua:
local str_rand = {'1244, 1343, 1588, 1797, 2135'} --не знаю зачем тебе это

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage('Autosmoking is {FF0000}started', -1)

    sampRegisterChatCommand("asg",function() act = not act sampAddChatMessage(act and "Autosmoking: {00FF00}ON" or "Autosmoking: {FF0000}OFF", 0xFFFFFF) end)
       
    while true do
        math.randomseed(os.time())
        rand = math.random(1244, 2135) -- рандомное количество миллисекунд в пределах от 1244 до 2135
        health = getCharHealth(PLAYER_PED)
        if act and health < 80 then
            sampSendChat("/smoke")
            wait(rand) -- подождет выше найденное рандомное количество миллисекунд и снова проверит if act == true and здоровье персонажа < 80 если да то тогда отправиться в чат еще раз команда smoke и так дальше по кругу
        end
    end
end
Не особо понял что ты хотел, но вот код. Ты можешь посмотреть гайды на ютубе The champ guess и сможешь сам сделать такой скрипт
Спасибо за объяснения, часть вашего скрипта помогла. Только полный скрипт почему-то крашил игру, так что я переписал немного, и вот, что получилось
Lua:
act = false

function main()
    repeat
        wait(0)
    until isSampAvailable()
        sampAddChatMessage('Autosmoking is {FF0000}started', -1)

    sampRegisterChatCommand("asg",function() act = not act sampAddChatMessage(act and "Autosmoking: {00FF00}ON" or "Autosmoking: {FF0000}OFF", 0xFFFFFF) end)

        while true do
            wait(rand)
        math.randomseed(os.time())
                rand = math.random(1244, 2135)
                health = getCharHealth(PLAYER_PED)
                if act and health < 80 then
                    sampSendChat("/smoke")
                end
            end
        end
 

qdIbp

Автор темы
Проверенный
1,450
1,190
Я хотел, чтобы в wait() брались рандомные числа из str_random.
у тя так и так бы не получилось бы потому что в str_random содержится один string = строка, а не 5 чисел
Вот почитай с начало это https://www.cronos.ru/kb-1513.html
потом это https://www.cronos.ru/kb-1532.html

Lua:
act = false
local str_rand = {1244, 1343, 1588, 1797, 2135}

function main()
    repeat wait(0) until isSampAvailable()
        sampAddChatMessage('Autosmoking is {FF0000}started', -1)
        sampRegisterChatCommand("asg",function() act = not act sampAddChatMessage('Autosmoking: '..(act and "{00FF00}ON" or "{FF0000}OFF"), 0xFFFFFF) end)
    while true do
        math.randomseed(os.time())
        rand = math.random(1, #str_rand)
    wait(str_rand[rand])
        health = getCharHealth(PLAYER_PED)
        if act and health < 80 then
            sampSendChat("/smoke")
        end
    end
end
 
Последнее редактирование:
  • Нравится
Реакции: Kviyx и YarikVL