mIRC Homepage

Delaying an If Elseif statement

Posted By: Ecf1

Delaying an If Elseif statement - 28/03/11 08:47 PM

What I'm trying to do is on join, have a script examine whether that person was voiced, halfoped or oped, and then proceed with the if elseif statements. In order to properly use the command, I need the script to be delayed about 5 seconds so Chanserv can properly voice or op someone. So far I have managed this.

on *:join:# {
if ($nick isop $chan) {
/mode $chan +o $nick
}
elseif ($nick isvoice $chan) {
/mode $chan +v $nick
}
else {
/mode $chan +h $nick
}
}

So I want it to half anyone who doesn't have autoaccess. How can I cause a delay before the if is read?
Posted By: Riamus2

Re: Delaying an If Elseif statement - 28/03/11 09:31 PM

Put the IF/ELSEIF/ELSE into an alias and call the alias with a timer.

Code:
on *:join:#: {
  .timer 1 5 MyAlias
}
alias MyAlias {
  if (whatever) { }
  elseif (whatever) { }
  else { }
}


Btw, in the future, please use CODE tags when posting code to the forum. You can use iether the # button above your post or manually type [ code ] before the code and [/code] after the code (no spaces around the word code). It makes it much easier to read.

In addition, you don't need to use / inside a script. /mode can be written as mode .
Posted By: Ecf1

Re: Delaying an If Elseif statement - 28/03/11 10:09 PM

I'm sorry but I cannot seem to get it to work. Here is my entire script.
Code:

on *:join:# { 
  /msg $chan Welcome to $read C:\Users\Owner\Documents\places.txt
  .timer 1 5 MyAlias
}
alias MyAlias {
  if ($nick isop $chan) { 
    /mode $chan +o $nick 
  }
  elseif ($nick isvoice $chan) { 
    /mode $chan +v $nick 
  }
  else { 
    /mode $chan +h $nick 
  }
}
Posted By: Riamus2

Re: Delaying an If Elseif statement - 28/03/11 10:21 PM

Consider what you have in your IF/ELSEIF/ELSE statements...

You are checking if the person is already opped and then if they are, you are opping them. The same for voice/halfop. I have a feeling you don't mean it that way.

Decide what exactly you want to happen. You don't need to op someone who is already opped, but you aren't going to op everyone who comes in. How do you know whether to op someone? You will need some kind of check in there to determine who should be opped, who voiced, etc.
Posted By: Ecf1

Re: Delaying an If Elseif statement - 29/03/11 01:35 AM

If I could, I would just put nothing in the if and elseif field. I just want to halfop everyone who comes in that doesn't already have autovoice or autoop.
Posted By: Riamus2

Re: Delaying an If Elseif statement - 29/03/11 01:41 AM

So just have an IF instead of the if/elseif/else...

Code:
if ($nick isreg $chan) { mode $chan +h $nick }

Posted By: Ecf1

Re: Delaying an If Elseif statement - 29/03/11 01:47 AM

So I could tack on that IF statement to the end of the .timer?
Code:
on *:join:# { 
  /msg $chan Welcome to $read C:\Users\Owner\Documents\places.txt
  .timer 1 5 { if ($nick isreg $chan) { mode $chan +h $nick
  }
 }
}


That should implement the timer into the IF statement, yes?
Posted By: Riamus2

Re: Delaying an If Elseif statement - 29/03/11 02:39 AM

Two problems. First, your brackets are messed up some there. And second, putting the IF directly in the timer will check the status immediately rather than when the timer triggers. You'd need to prevent the evaluation.

Code:
.timer 1 5 if ($($nick isreg $chan,0)) { mode $chan +h $nick }


*** That *might* work. Normally, you can prevent the pre-evaluation this way, but I've never tried with an isreg type of check and can't test it right now to find out. Try it out and see. Have someone join and then you op them immediately (or voice) and see if it triggers. Then try without opping/voicing them and see if it triggers. If it doesn't work, use the alias or someone else can show the right way to handle this.
Posted By: Ecf1

Re: Delaying an If Elseif statement - 29/03/11 03:19 AM

I appreciate the effort, but it did not work. I'll try the alias method, perhaps you could point me to good teaching material?
Posted By: jaytea

Re: Delaying an If Elseif statement - 29/03/11 04:23 AM

Originally Posted By: Riamus2
You'd need to prevent the evaluation.

Code:
.timer 1 5 if ($($nick isreg $chan,0)) { mode $chan +h $nick }



the easiest way to think about this is by asking the question "how will that look after a single evaluation?". mIRC evaluates the .timer line once initially, just as it would the arguments to any other command (well, it also handles variable related commands in a special way, but that's not important at the moment :P). that's why we can use //echo to see what the timer is likely to perform, if our instinct fails us:

Code:
//echo -a if ($($nick isreg $chan,0)) { mode $chan +h $nick }


= if ($($nick isreg mode +h

not really what we want :P

this is because '($($nick' fails to evaluate due to '(' touching '$nick'. then '$chan,0))' gets evaluated as an identifier in full, and { } get chomped away (which is ok since there's just a single command).

if we can recognize that what we want produced is:

Quote:

if (<value of nick> isreg <value of $chan> ) mode <value of $chan> +h <value of $nick>


then we can can quite easily see that the solution is:

Code:
.timer 1 5 if ( $+ $nick isreg $chan ) mode $chan +h $nick


we must be careful though, $nick / $chan may contain characters that could interfere with the code later when the timer executes its command ($nick = '{' or '}', $chan containing unbalanced parentheses, or beginning with '#$' which is evaluated as an identifier). setting variables or sticking information in the timer name and using $ctimer is generally advised. there's also a $safe_eval() snippet lying around if someone wants to share it.
Posted By: genius_at_work

Re: Delaying an If Elseif statement - 29/03/11 04:29 AM

Your timer/alias did not work mainly due to the fact that $nick and $chan are only valid within the onJOIN event. Even though you started the timer inside the onJOIN event, when it actually fires 5 seconds later, those identifiers are no longer valid. In order to use those $nick and $chan in an alias when called by a timer, you need to either pass them as arguments to the alias, or save them in a variable. In this case, the easiest way is to pass them as arguments. Example:

Code:

on *:JOIN:#: { 
  .timer 1 5 MyJoin $nick $chan
}
alias MyJoin {
  ;; $1=nick, $2=chan

  echo -at Nick is $1
  echo -at Chan is $2
}



The $nick is passed as the first argument, and $chan is passed as the second argument, so inside the alias, you need to use $1 for nick, and $2 for chan. Using those two values, you should be able to create the rest of your script.

-genius_at_work
Posted By: Riamus2

Re: Delaying an If Elseif statement - 29/03/11 10:19 AM

Oops. I forgot that timer prevents $chan and $nick from passing to an alias even though they normally will pass to an alias. Sorry about that.

@jaytea: doesn't your timer in the last code block evaluate the isreg immediately?
Posted By: jaytea

Re: Delaying an If Elseif statement - 29/03/11 11:19 AM

no, in the same way nothing out of the ordinary happens with //echo -a if (a isreg b) command
Posted By: Ecf1

Re: Delaying an If Elseif statement - 29/03/11 04:00 PM

Thanks a bunch everyone. It works! You guys are a great help and taught me some valuable stuff. I appreciate it! laugh
© 2022 mIRC Discussion Forums