xhookLua
Game

Timers & saving

Count kills across game restarts without writing to disk every kill.

local kills = db.get("kills", 0)

callbacks.register("on_player_death", function(e)
    local me = engine.local_player()
    if me and e.attacker == me then kills = kills + 1 end
end)

-- Save every 30 seconds, and once more on unload.
task.interval(30, function() db.set("kills", kills) end)
callbacks.register("on_script_unload", function() db.set("kills", kills) end)

callbacks.register("on_paint", function()
    draw.text(20, 100, draw.color(255, 255, 255), "kills: " .. kills)
end)
Timers & saving ยท Lua API ยท xhook