mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2016
Posts: 2
D
Bowl of petunias
OP Offline
Bowl of petunias
D
Joined: Dec 2016
Posts: 2
I'm trying to figure out toggling an event without using 2 commands. In this example, I'm trying to start and stop a timed announcer with just the command !anno.

I check first if the user isop, then I want to check if the timer is already running(which I'm trying to do with a variable). If the timer is off, then start it, and vice versa.

Code:
on *:TEXT:!anno:#: {
  if ($nick isop #) && (%annoOn == $null) {
    var %annoOn = 1
    .timerAnno 0 5 /play # C:\Users\user\Desktop\announcement.txt
    msg $chan Announcer On
  }
  elseif ($nick isop #) && (%annoOn == 1) {
    set %annoOn = 0
    .timerAnno off
    msg $chan Announcer Off
  }
}


I'm not getting any format errors, but nothing is running.

Any help/advice appreciated. This is a twitch bot, but the code isn't directly related to twitch.

Joined: Dec 2016
Posts: 2
D
Bowl of petunias
OP Offline
Bowl of petunias
D
Joined: Dec 2016
Posts: 2
I figured out a workaround using $ltimer. If anyone has a similar problem with a timer, here is my workaround.

When you run the command, check if $ltimer = $null. This should be true as long as a timer hasn't run on the script yet. Then have an elseif statement that checks if $ltimer = Anno (my timer's name is Anno). When this is true, it will turn the timer off. The problem is when you try to run the command a second time, $ltimer = Anno, so it will just run the off commands. The fix for this is when you turn the timer off, make a dummy timer that turns off after 2 seconds. This will set(in my case)$ltimer = Dummy. So add another elseif statement to check if $ltimer = Dummy to turn on the timer.
Code:
on *:TEXT:!anno:#: {
  if ($nick isop # && $ltimer = $null) {
    .timerAnno 0 5 /play # C:\Users\user\Desktop\announcements.txt
    msg $chan Announcer On
  }
  elseif ($nick isop # && $ltimer = Dummy) {
    .timerAnno 0 5 /play # C:\Users\user\Desktop\announcements.txt
    msg $chan Announcer On
  }  

  elseif ($nick isop # && $ltimer = Anno) {
    .timerAnno off
    msg $chan Announcer Off
    .timerDummy 0 2 .timerDummy off
  }
}  

on *:TEXT:!resetanno:#: {
  .timerDummy 1 2 .timerDummy off
  msg $chan Announcer Reset 
}

I also added a reset command called !resetanno. This command just turns the Dummy timer on and off quickly so that $ltimer = Dummy. This is helpful in case $ltimer gets stuck returning the name of your original timer, and wont turn off.

Last edited by DeBrates; 21/12/16 02:04 PM.
Joined: Oct 2015
Posts: 112
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
A simple edit of your original code will do the trick. You can check to see if a timer exists or doesn't exist in mIRC using the $timer function.

Code:
on *:TEXT:!anno:#: {
  if (($nick isop #) && (!$timer(Anno))) {
    .timerAnno 0 5 /play # C:\Users\user\Desktop\announcement.txt
    msg $chan Announcer On
  }
  elseif (($nick isop #) && ($timer(Anno))) {
    .timerAnno off
    msg $chan Announcer Off
  }
}


Link Copied to Clipboard