mIRC Homepage
Posted By: Brolaire Disable X command when Y command is active? - 11/03/15 11:08 AM
Hey,
really new to mIRC, I'm using it to run a bot for my Twitch.tv Channel.
Current script:
Click to reveal..
Quote:
on *:text:!startuptime:#: {
if ((%floodstartuptime) || ($($+(%,floodstartuptime.,$nick),2))) { return }
set -u600 %floodstartuptime On
set -u600 %floodstartuptime. $+ $nick On
msg # Stopping Downtime. Starting uptime.
set -e %uptime. [ $+ [ # ] ] $ctime
unset %downtime. [ $+ [ # ] ] $+
}

on *:text:!uptime:#: {
if ((%flooduptime) || ($($+(%,flooduptime.,$nick),2))) { return }
set -u300 %flooduptime On
set -u300 %flooduptime. $+ $nick On

msg # /me Uptime: $duration($calc($ctime - %uptime. [ $+ [ # ] ] )) $+
}

on *:text:!stopuptime:#: {
if ((%floodstopuptime) || ($($+(%,floodstopuptime.,$nick),2))) { return }
set -u600 %floodstopuptime On
set -u600 %floodstopuptime. $+ $nick On
msg # Stopping uptime. Starting downtime.
unset %uptime. [ $+ [ # ] ] $+
set -e %downtime. [ $+ [ # ] ] $ctime
}

on *:text:!downtime:#: {
if ((%flooddowntime) || ($($+(%,flooddowntime.,$nick),2))) { return }
set -u300 %flooddowntime On
set -u300 %flooddowntime. $+ $nick On

msg # /me Downtime: $duration($calc($ctime - %downtime. [ $+ [ # ] ] )) $+
}


How can I disable a command (!downtime) after a different command has been activated (!startuptime)?
Is there an alternative way of doing this?
Thank you
You can do that by setting a variable which turns on whenever staruptime is used, and turned off when stopuptime is typed.

Code:
on *:TEXT:!startuptime:#: {
  set %uptimeon On 
  REST OF SCRIPT...
}

on *:TEXT:!stoptime:#: {
  unset %uptimeon
  REST OF SCRIPT...
}

on *:TEXT:!downtime:#: {
  if (!%uptimeon) {
     REST OF SCRIPT...
  }
  else {
     msg # I am live so there is no need for downtime. 
  }
}
Thank you so much for the quick response! It's not working though, can't see why.
Am I missing a bracket somewhere?

Click to reveal..
Code:
on *:text:!startuptime:#: {
  set %uptimeon On 
  unset %downtimeon
  if ((%floodstartuptime) || ($($+(%,floodstartuptime.,$nick),2))) { return }
  set -u600 %floodstartuptime On
  set -u600 %floodstartuptime. $+ $nick On
  msg # Stopping Downtime. Starting uptime.
  set -e %uptime. [ $+ [ # ] ] $ctime
  unset %downtime. [ $+ [ # ] ] $+
}

on *:text:!uptime:#: { 
  if (!%downtimeon) {
    unset %uptimeon
    if ((%flooduptime) || ($($+(%,flooduptime.,$nick),2))) { return }
    set -u300 %flooduptime On
    set -u300 %flooduptime. $+ $nick On
    msg # /me Uptime: $duration($calc($ctime - %uptime. [ $+ [ # ] ] )) $+
  }
  else {
    msg # I am currently offline. Duh
    }
}

on *:text:!stopuptime:#: { 
  set %downtimeon On
  unset %uptimeon
  if ((%floodstopuptime) || ($($+(%,floodstopuptime.,$nick),2))) { return }
  set -u600 %floodstopuptime On
  set -u600 %floodstopuptime. $+ $nick On
  msg # Stopping uptime. Starting downtime.
  unset %uptime. [ $+ [ # ] ] $+
  set -e %downtime. [ $+ [ # ] ] $ctime 
}

on *:text:!downtime:#: { 
  if (!%uptimeon) {
    if ((%flooddowntime) || ($($+(%,flooddowntime.,$nick),2))) { return }
    set -u300 %flooddowntime On
    set -u300 %flooddowntime. $+ $nick On

    msg # /me Downtime: $duration($calc($ctime - %downtime. [ $+ [ # ] ] )) $+
  }
  else {
    msg # I am currently live. Duh  }
}

Alternately, with your style of event triggers, you can simply wrap each one in a #group directive, and use the /.enable and /.disable commands.
I think your problem comes from the fact that you unset the variable when you type !uptime. Also, is there any particular reason why you also need a downtime variable? Since uptimeon is active only when you're live, I don't think you really need a downtime variable.

Code:
on *:text:!startuptime:#: {
  set %uptimeon On 
  if ((%floodstartuptime) || ($($+(%,floodstartuptime.,$nick),2))) { return }
  set -u600 %floodstartuptime On
  set -u600 %floodstartuptime. $+ $nick On
  msg # Stopping Downtime. Starting uptime.
  set -e %uptime. [ $+ [ # ] ] $ctime
  unset %downtime. [ $+ [ # ] ] $+
}
on *:text:!uptime:#: { 
  if (!%uptime) {
    msg # I am currently offline
  }
  else {
    if ((%flooduptime) || ($($+(%,flooduptime.,$nick),2))) { return }
    set -u300 %flooduptime On
    set -u300 %flooduptime. $+ $nick On
    msg # /me Uptime: $duration($calc($ctime - %uptime. [ $+ [ # ] ] )) $+
  }
    }
}
on *:text:!stopuptime:#: { 
  unset %uptimeon
  if ((%floodstopuptime) || ($($+(%,floodstopuptime.,$nick),2))) { return }
  set -u600 %floodstopuptime On
  set -u600 %floodstopuptime. $+ $nick On
  msg # Stopping uptime. Starting downtime.
  unset %uptime. [ $+ [ # ] ] $+
  set -e %downtime. [ $+ [ # ] ] $ctime 
}
on *:text:!downtime:#: { 
  if (!%uptimeon) {
    if ((%flooddowntime) || ($($+(%,flooddowntime.,$nick),2))) { return }
    set -u300 %flooddowntime On
    set -u300 %flooddowntime. $+ $nick On

    msg # /me Downtime: $duration($calc($ctime - %downtime. [ $+ [ # ] ] )) $+
  }
  else {
    msg # I am currently live. Duh  }
}


I might have accidently added a bracket or two but this in theory should work. Sorry, I'm not on my computer right now so I can't physically test it.
Or just use /.enable and /.disable like I said. That's exactly what they were added for.
© mIRC Discussion Forums