Time counter

This module will count the time it has passed since you joined a world with a new account

local prev_player_name = ""
local time = 0

local time_counter = {
    on_render_screen = function(ctx)
        if (player.name() ~= prev_player_name) then
            time = client.time()
            prev_player_name = player.name()
        end

        local diff = client.time() - time;
        if (diff > 0) then
            local diff_seconds = diff / 1000 % 60;
            local diff_minutes = diff / (60 * 1000) % 60;
            local diff_hours = diff / (60 * 60 * 1000) % 24;

            local string = math.floor(diff_hours) .. "h " .. math.floor(diff_minutes) .. "m " .. math.floor(diff_seconds) .. "s";
            render.string(string, ctx.width / 2 - render.get_string_width(string) / 2, 30, 255, 255, 255, 255)
        end
    end,
}

module_manager.register('TimeCounter', time_counter)

Last updated