Solved Destroying timers? (C#)

Discussion in 'Rust Development' started by PaiN, Jul 3, 2015.

  1. So .. again some small issues.

    Issue nr1.
    In my function with a line of the timer look like:
    Code:
    var timerrepeat = timer.Repeat(1, 0, () => test);
    
    I want to destroy it in "void Unload" so i dont know how to do it in C#..
     
  2. store timer variable in the field of the script.
    Code:
    using Oxide.Plugins;namespace MyPlugin
    {
        [Info("MyPlugin", "ZakBelg", 0.1, ResourceId = 714)]
        [Description("Awesome timer workout")]
        public class TestPlugin : RustPlugin
        {
            private Timer _timer;        void Init()
            {
                var timerInstance = new Oxide.Core.Libraries.Timer.TimerInstance(1000, 1000, null, this);
                _timer = new Timer(timerInstance);
            }        void Unload()
            {
                if (!_timer.Destroyed)
                    _timer.Destroy();
            }
        }
    }
     
  3. Done it worked.. now One last question..
    So for example lets say that i want activate a timer to display them a message to TWO targets.
    Then i want to stop it from the one of them and the other's one timer will keep going.
    Is it possible to "assign" the timer to a player? for ex /repeathim "Hello"
     
  4. Either you need two timers or filter unwanted player in a callback of single timer by checking some expression.
     
  5. If it's the same message you send to everyone, simply have a of targets (List<BasePlayer>()) (global) that you add/remove players to/from. In the timer function loop through them and send the msg.
     
  6. is there any difference using this type of timer (other than i think u can pass parameters through oxides one) or using c#'s one ?

    void Unload()
    {
    timer.Stop();
    }

    void Loaded()
    {
    timer = new System.Timers.Timer(600000);
    timer.Interval = 600000;
    timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    timer.Start();
    }
     
  7. Wulf

    Wulf Community Admin

    A lot less code with Oxide?