Skip to content

Хранилище, таймеры и задачи

С разрешением plugin.storage доступны ограниченные значения boolean, number и string:

lua
local enabled = samp.storage.get("enabled", true)
samp.storage.set("enabled", not enabled)
samp.storage.remove("obsolete_key")

Не записывайте storage каждый кадр.

samp.timer.after() создаёт одноразовый callback. samp.task.spawn() создаёт управляемую задачу; yield разрешён только через samp.task.sleep().

lua
local launches = samp.storage.get("launches", 0) + 1
samp.storage.set("launches", launches)

samp.timer.after(1000, function()
    samp.log.info("one second elapsed")
end)

local task = samp.task.spawn(function()
    samp.task.sleep(500)
    samp.log.info("task resumed")
end)

-- Safe even when the task has already completed.
-- task:cancel()

Задачи отменяются при выгрузке плагина или завершении сеанса.