Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Doom_Kill3R
- Plugin: SqMod by SLC
- */
- CTimers <- [];
- function onServerFrame(elapsedTime) {
- foreach(t_index, t_inst in CTimers) {
- t_inst.Process(time());
- }
- }
- SqCore.On().ServerFrame.Connect(onServerFrame);
- class Timer {
- /* Main */
- callback = null;
- interval = null;
- repeat = null;
- params = [];
- /* Misc */
- startTick = null;
- constructor(callback, interval, repeat, ...) {
- this.callback = callback;
- this.interval = interval;
- this.repeat = repeat == 0 ? -1 : repeat;
- this.params = vargv;
- this.params.insert(0, this);
- this.startTick = ::time();
- ::CTimers.push(this);
- //::SqLog.Inf("Timer:: " + callback.getinfos().name + " - Interval: " + interval + " - repeat: " + repeat);
- }
- }
- function Timer::Destroy() {
- //SqLog.Dbg("Timers::Destroy - " + this);
- if(::CTimers.find(this) != null) {
- ::CTimers.remove(::CTimers.find(this));
- }
- this = null;
- }
- function Timer::Process(currentTime) {
- if(currentTime-this.startTick >= this.interval) {
- if(this.repeat == 0) {
- this.Destroy();
- return true;
- } else {
- this.startTick = currentTime;
- this.Call();
- if(this.repeat == -1) {
- return true;
- }
- }
- this.repeat--;
- if(this.repeat == 0) {
- this.Destroy();
- }
- }
- }
- function Timer::Call() {
- //SqLog.Dbg("Timers::Call - " + this);
- this.callback.acall(this.params);
- }
- function isTimer(inst) {
- if(typeof(inst) == "instance") {
- if(CTimers.find(inst) != null) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
Add Comment
Please, Sign In to add comment