рандомная задержка wait()

vAsa_huasa

Известный
Автор темы
25
1
Lua:
local hook = require 'samp.events'
local encoding = require 'encoding'
local key = require 'vkeys'

encoding.default = 'CP1251'
u8 = encoding.UTF8

local activ = false

sampRegisterChatCommand("/", function ()
        activ = not activ
        printStringNow(activ and '~g~binder on' or '~r~binder oFF', 2000)
    end)
 
function hook.onServerMessage(color, text)
    if activ then
       if string.find(text, "fish") then
            lua_thread.create(function()
                wait(500)
                sampSendChat('/fishes')
                wait(100)
                sampCloseCurrentDialogWithButton(1)
            end)
        end
    end
 
end

есть скрипт. стоит задержка в 500 миллисекунд. как сделать чтобы это число каждый раз менялась в определенном диапазоне. т.е. нужно чтобы была разная задержка, разные числа. 19 строка
 
Решение
Lua:
local hook = require 'samp.events'
local encoding = require 'encoding'
local key = require 'vkeys'

encoding.default = 'CP1251'
u8 = encoding.UTF8

local activ = false

sampRegisterChatCommand("/", function ()
        activ = not activ
        printStringNow(activ and '~g~binder on' or '~r~binder oFF', 2000)
    end)
 
function hook.onServerMessage(color, text)
    if activ then
       if string.find(text, "fish") then
            lua_thread.create(function()
                wait(500)
                sampSendChat('/fishes')
                wait(100)
                sampCloseCurrentDialogWithButton(1)
            end)
        end
    end
 
end

есть скрипт. стоит задержка в 500 миллисекунд. как сделать чтобы это число каждый...

хуега)

РП игрок
Модератор
2,568
2,265
Lua:
local hook = require 'samp.events'
local encoding = require 'encoding'
local key = require 'vkeys'

encoding.default = 'CP1251'
u8 = encoding.UTF8

local activ = false

sampRegisterChatCommand("/", function ()
        activ = not activ
        printStringNow(activ and '~g~binder on' or '~r~binder oFF', 2000)
    end)
 
function hook.onServerMessage(color, text)
    if activ then
       if string.find(text, "fish") then
            lua_thread.create(function()
                wait(500)
                sampSendChat('/fishes')
                wait(100)
                sampCloseCurrentDialogWithButton(1)
            end)
        end
    end
 
end

есть скрипт. стоит задержка в 500 миллисекунд. как сделать чтобы это число каждый раз менялась в определенном диапазоне. т.е. нужно чтобы была разная задержка, разные числа. 19 строка
Lua:
local hook = require 'samp.events'
local encoding = require 'encoding'
local key = require 'vkeys'

encoding.default = 'CP1251'
u8 = encoding.UTF8

local activ = false

sampRegisterChatCommand("/", function ()
        activ = not activ
        printStringNow(activ and '~g~binder on' or '~r~binder oFF', 2000)
end)
  
function hook.onServerMessage(color, text)
    if activ then
       if string.find(text, "fish") then
            lua_thread.create(function()
                wait(random(1, 1000)) -- диапазон от 1, до 1000 мс
                sampSendChat('/fishes')
                wait(100)
                sampCloseCurrentDialogWithButton(1)
            end)
        end
    end   
end

function random(min, max)
    local kf = math.random(min, max)
    math.randomseed(os.time() * kf)
    local rand = math.random(min, max)
    return tonumber(rand)
end
 
  • Нравится
Реакции: Mintha и vAsa_huasa

vAsa_huasa

Известный
Автор темы
25
1
Lua:
local hook = require 'samp.events'
local encoding = require 'encoding'
local key = require 'vkeys'

encoding.default = 'CP1251'
u8 = encoding.UTF8

local activ = false

sampRegisterChatCommand("/", function ()
        activ = not activ
        printStringNow(activ and '~g~binder on' or '~r~binder oFF', 2000)
end)
 
function hook.onServerMessage(color, text)
    if activ then
       if string.find(text, "fish") then
            lua_thread.create(function()
                wait(random(1, 1000)) -- диапазон от 1, до 1000 мс
                sampSendChat('/fishes')
                wait(100)
                sampCloseCurrentDialogWithButton(1)
            end)
        end
    end  
end

function random(min, max)
    local kf = math.random(min, max)
    math.randomseed(os.time() * kf)
    local rand = math.random(min, max)
    return tonumber(rand)
end
все работает спасибо
 
  • Нравится
Реакции: хуега)