LUA Scripts Timer object
Reply
Timer object
This is a lua script alternative to the Macroquest timer datatype. The old datatype does not seem to be supported by the new Macroquest.
PS: It only supports presicion down to nearest second. This is due to os.time() only supporting seconds. For more precision, luasocket or similiar plugin is required.

Lua
More +

---@class Timer
---@field public Duration int
---@field public StartTime int
local Timer = {Duration = 0, StartTime = os.time()}

---@param duration int
---@return Timer
function Timer:new (duration)
  self.__index = self
  local o = setmetatable({}, self)
  o.Duration = duration or 0
  o.StartTime = os.time()
  return o
end

---@return int
function Timer:TimeRemaining()
  return os.difftime(os.time(), self.StartTime);
end

---@return int
function Timer:DelayTime()
  return self:TimeRemaining() * 1000;
end

---@return bool
function Timer:IsComplete()
  return self:TimeRemaining() >= self.Duration;
end

---@return bool
function Timer:IsRunning()
  return self:IsComplete() == false;
end

return Timer
Tue Aug 16, 2022 4:19 am
LUA Scripts Timer object
Reply