mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2011
Posts: 6
E
Ecf1 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
E
Joined: Mar 2011
Posts: 6
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?

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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 .

Last edited by Riamus2; 28/03/11 09:34 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Mar 2011
Posts: 6
E
Ecf1 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
E
Joined: Mar 2011
Posts: 6
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 
  }
}

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.

Last edited by Riamus2; 28/03/11 10:24 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Mar 2011
Posts: 6
E
Ecf1 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
E
Joined: Mar 2011
Posts: 6
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.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
So just have an IF instead of the if/elseif/else...

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


Last edited by Riamus2; 29/03/11 01:41 AM.

Invision Support
#Invision on irc.irchighway.net
Joined: Mar 2011
Posts: 6
E
Ecf1 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
E
Joined: Mar 2011
Posts: 6
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?

Last edited by Ecf1; 29/03/11 01:48 AM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Joined: Mar 2011
Posts: 6
E
Ecf1 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
E
Joined: Mar 2011
Posts: 6
I appreciate the effort, but it did not work. I'll try the alias method, perhaps you could point me to good teaching material?

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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?


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
no, in the same way nothing out of the ordinary happens with //echo -a if (a isreg b) command


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Mar 2011
Posts: 6
E
Ecf1 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
E
Joined: Mar 2011
Posts: 6
Thanks a bunch everyone. It works! You guys are a great help and taught me some valuable stuff. I appreciate it! laugh


Link Copied to Clipboard