Skip to content

Commit

Permalink
Add getters + adjust method
Browse files Browse the repository at this point in the history
  • Loading branch information
deltamolfar committed Oct 9, 2024
1 parent 1e9538c commit 871e359
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
40 changes: 40 additions & 0 deletions lua/entities/gmod_wire_expression2/core/timer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ e2function number gtimerSetReps(string name, number repetitions)
timer.Adjust(name, gtimers[self.entity:EntIndex()][name].delay, repetitions)
end

__e2setcost(5)
e2function void gtimerAdjust(string name, number delay, number repetitions)
if not gtimerExists(self, name) then
return self:throw("Timer with name " .. name .. " does not exist", nil)
end

local name = gtimerGetPrefix(name)
gtimers[self.entity:EntIndex()][name].delay = delay
gtimers[self.entity:EntIndex()][name].repetitions = repetitions
timer.Adjust(name, delay, repetitions)
end

__e2setcost(20)
e2function void gtimerSetCallback(string name, function callback)
if not gtimerExists(self, name) then
Expand All @@ -231,6 +243,34 @@ e2function void gtimerSetCallback(string name, function callback)
createGTimer(self, name, gtimer.delay, gtimer.repetitions, callback)
end

__e2setcost(1)
[nodiscard]
e2function number gtimerGetDelay(string name)
if not gtimerExists(self, name) then
return self:throw("Timer with name " .. name .. " does not exist", 0)
end

return gtimers[self.entity:EntIndex()][gtimerGetPrefix(name)].delay
end

[nodiscard]
e2function number gtimerGetReps(string name)
if not gtimerExists(self, name) then
return self:throw("Timer with name " .. name .. " does not exist", 0)
end

return gtimers[self.entity:EntIndex()][gtimerGetPrefix(name)].repetitions
end

[nodiscard]
e2function string gtimerGetCallback(string name)
if not gtimerExists(self, name) then
return self:throw("Timer with name " .. name .. " does not exist", "")
end

return gtimers[self.entity:EntIndex()][gtimerGetPrefix(name)].callback
end

__e2setcost(10)
e2function void gtimerCreate(string name, number delay, number repetitions, function callback)
createGTimer(self, name, delay, repetitions, callback)
Expand Down
10 changes: 7 additions & 3 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,13 @@ E2Helper.Descriptions["runOnTick(n)"] = "DEPRECATED. Use 'event tick()' instead!
E2Helper.Descriptions["timer(sn)"] = "Sets a one-time timer with entered name and delay in milliseconds"
E2Helper.Descriptions["stoptimer(s)"] = "Stops a timer, can stop interval with stoptimer(\"interval\")"
E2Helper.Descriptions["stopAllTimers()"] = "Stops all timers"
E2Helper.Descriptions["gtimerSetDelay(s,n)"] = "Sets the delay of the timer with the name S to N seconds"
E2Helper.Descriptions["gtimerSetReps(s,n)"] = "Sets the number of repetitions of the timer with the name S to N"
E2Helper.Descriptions["gtimerSetCallback(s,f)"] = "Sets the callback function of the timer with the name S to the function F"
E2Helper.Descriptions["gtimerSetDelay(sn)"] = "Sets the delay of the timer with the name S to N seconds"
E2Helper.Descriptions["gtimerSetReps(sn)"] = "Sets the number of repetitions of the timer with the name S to N"
E2Helper.Descriptions["gtimerAdjust(snn)"] = "Sets the delay and repetitions of the timer with the name S to N seconds and N repetitions"
E2Helper.Descriptions["gtimerSetCallback(sf)"] = "Sets the callback function of the timer with the name S to the function F"
E2Helper.Descriptions["gtimerGetDelay(s)"] = "Returns the delay of the timer with the name S"
E2Helper.Descriptions["gtimerGetReps(s)"] = "Returns the number of repetitions of the timer with the name S"
E2Helper.Descriptions["gtimerGetCallback(s)"] = "Returns the callback function of the timer with the name S"
E2Helper.Descriptions["gtimerCreate(snnf)"] = "Creates a callback timer with the name S, delay of N seconds, N repeats and callback function F. NOTE: If the timer finished running, it will not exist (and you won't be able to restart/configure it)"
E2Helper.Descriptions["gtimerCreate(nnf)"] = "Creates a simple callback timer with delay of N seconds, N repeats and callback function F. Returns autogenerated name which you can use. NOTE: If the timer finished running, it will not exist (and you won't be able to restart/configure it)"
E2Helper.Descriptions["gtimerCreate(nf)"] = "Creates a simple callback timer delay of N seconds, 1 repeat(one-time timer) and callback function F. Returns autogenerated name which you can use. NOTE: If the timer finished running, it will not exist (and you won't be able to restart/configure it)"
Expand Down

0 comments on commit 871e359

Please sign in to comment.