Storage, timers, and tasks
Private storage
With plugin.storage, a plugin can store bounded boolean, number, or string values in its private data area.
lua
local enabled = samp.storage.get("enabled", true)
samp.storage.set("enabled", not enabled)
samp.storage.remove("obsolete_key")Use stable keys and provide defaults. Storage writes are atomic, but they still perform I/O; do not write every frame.
One-shot timers
samp.timer.after(milliseconds, callback) schedules a protected callback. Keep the returned handle if cancellation is needed.
Managed tasks
samp.task.spawn() creates a managed Lua task. Only samp.task.sleep() may yield it. A zero delay yields until at least the next frame.
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()Tasks are cancelled when their plugin unloads or the session ends. Each resume receives the same instruction and callback-time protections as a normal callback.