mIRC Homepage
Posted By: LexRock Auto oping certain nicks. - 06/11/07 05:18 PM
I want to run a remote script auto opping a certain nick on a certain channel when certian nick joins that channel.

I have not gotten it to work properly, and I need some assistance.

The reasons for this is that I have tow computers that join this channel, and one of them I have to reboot quite often due to overheating, but that otherone can be online and have an uptime of many weeks.

Is this way corrcet?:

(Assume channel name is ChanName, and nick is MyNick)

on *:Join:#ChanName: { mode $chan +o MyNick }

I want this script to work only on my nick.

I would appreciate any inputs on this.

Regards
LexRock
Posted By: nomer2007 Re: Auto oping certain nicks. - 06/11/07 06:16 PM
on *:Join:#ChanName: { if $nick == MyNick mode $chan +o $nick }
Posted By: LexRock Re: Auto oping certain nicks. - 06/11/07 06:27 PM
thank you very much!

I will try it right now smile
Posted By: Lpfix5 Re: Auto oping certain nicks. - 06/11/07 08:42 PM
nomer even brackets after : are useless on single line code.

on *:JOIN:#ChanName:if $nick == MyNick mode $chan +o $nick

laugh
Posted By: Horstl Re: Auto oping certain nicks. - 06/11/07 09:35 PM
Imho, brackets like these are never 'useless', maybe they're just not mandatory in this specific situation.

But (at least in most situations) they increase readability, thus I think it's a good idea to set them habitually, uniformly and univocally - and one won't run across problems in other situations where they might be mandatory.

besides these:
on *:JOIN:#ChanName:if $nick == MyNick mode $chan +o $nick
on *:JOIN:#ChanName: { if $nick == MyNick mode $chan +o $nick }

The following are all "common styles", too:
on *:JOIN:#ChanName: if $nick == MyNick { mode $chan +o $nick }
on *:JOIN:#ChanName: if ($nick == MyNick) mode $chan +o $nick
on *:JOIN:#ChanName: if ($nick == MyNick) { mode $chan +o $nick }

on *:JOIN:#ChanName: {
if ($nick == MyNick) { mode $chan +o $nick }
}

... and I do prefer the last two styles, for reasons named above smile
Posted By: Riamus2 Re: Auto oping certain nicks. - 06/11/07 11:10 PM
Agreed. There are times when ()'s and {}'s are not necessary and there are times when they are. When your script suddenly doesn't work and you are doing the same thing as you always did (not using parentheses and braces), you will be stuck for quite awhile with no idea that it's because you didn't use them in a particular situation. Instead, being in the habit of using them will always keep you from running into such a situation.

There have been comments regarding speed of using them vs. not using them and the speed is so minimal that it isn't noticeable until you are talking about trying to run thousands of lines that use them within a couple of seconds. Even then, you're still looking at milliseconds of difference, which isn't important.

So, since speed isn't really an issue and it's better to be in the habit of using them to prevent problems when they won't work, it is a good idea to always promote using them to new scripters rather than promoting not using them.

The only time I won't use {}'s are on certain ELSE lines where there is only one command for the ELSE. Even then, I may still use them just to make things more clear.

Of course, there is a such thing as overuse of ()'s. Too many ()'s make things confusing as well.

These are fine:
if (this == that || this == that) { }
if (this == that) || (this == that) { }

But, this starts to become too much, imo:
if ((this == that) || (this == that)) { }

Personally, I prefer the first of those 3 examples.
Posted By: noMen Re: Auto oping certain nicks. - 07/11/07 07:43 AM
A lot of people ask questions about the speed of command processing. And now, in the only case the mirc helpfile advises to do something to speed up processing, no one seems to be interested ....

If you do /help /if you will find this:
"Using brackets speeds up processing. If an alias uses too few brackets then the statement might be ambiguous and the alias will take longer to parse, might be parsed incorrectly, or might not be parsed at all."

Posted By: Riamus2 Re: Auto oping certain nicks. - 07/11/07 08:14 PM
Regardless what the help file states, braces usually slow it down rather than speed it up (as I stated). Also as I mentioned, it's such a minor difference that it isn't worth worrying about. The main issue is what the rest of that quote tells you... not using braces can make code ambiguous, which is why it will fail occasionally and why being in the habit of using them would save problems in the future.
Posted By: RoCk Re: Auto oping certain nicks. - 07/11/07 09:40 PM

Originally Posted By: Riamus2

Regardless what the help file states, braces usually slow it down rather than speed it up...



I would like to see some benchmarks to back that claim because I don't believe that to be true.
Posted By: Riamus2 Re: Auto oping certain nicks. - 08/11/07 02:44 AM
There were some posted a few months back. Basically:

if (this is true) do this

vs.

if (this is true) { do this }

Anyhow, I didn't do the tests and am just going by what others posted, but no one debunked them back then, so they were probably correct.
Posted By: TropNul Re: Benchmarking brackets ... - 08/11/07 05:35 PM
I'm of those who think that using brackets renders clearer and 'simpler' code if the latters are not excessively used.

While reading this thread, i've decided to benchmark the issue. Here's the rough benchmarking code.

Some people may be surprised when seeing the results.

Code:
; Benchmarking brackets ...
; 08.11.2007 @20hr54 by tropnul
; usage: /testcore

alias test1 {
  If 1 <= 2 noop
}

alias test2 {
  If (1 <= 2) noop
}

alias test3 {
  If 1 <= 2 { noop }
}

alias test4 {
  If (1 <= 2) { noop }
}

alias test5 {
  If 1 <= 2 noop | noop
}

alias test6 {
  If (1 <= 2) noop | noop
}

alias test7 {
  If 1 <= 2 { noop | noop }
}

alias test8 {
  If (1 <= 2) { noop | noop }
}

alias test9 If 1 <= 2 noop | noop

alias test10 If (1 <= 2) noop | noop

alias test11 If 1 <= 2 { noop | noop }

alias test12 If (1 <= 2) { noop | noop }

alias testproc {
  Var %z = 5000
  Set %t $ticks
  While %z {
    $1
    Dec %z
  }
  Var %t' = $calc($ticks - %t)
  Set %f %f test $+ $remove($1,test) $+ : $+(%t',ms)
}

alias testcore {
  Var %i = 1
  While (%i <= 12) {
    noop $testproc(test $+ %i)
    inc %i 
  }
  Echo -at %f
  Unset %t , %f
}


Without saying anything about the results (I'll let you test it ;)), I must say that my opinion didn't change after doing the benchmarking. I still believe that 'using brackets renders clearer and 'simpler' code if the latters are not excessively used.'

Regards
Posted By: noMen Re: Benchmarking brackets ... - 08/11/07 06:44 PM
Nice smile I added these three:

Code:
alias test13 if 1 <= 2 || 2 <= 3 && 3 >= 2 noop

alias test14 if 1 <= 2 || (2 <= 3 && 3 >= 2) noop

alias test15 if (1 <= 2) || (2 <= 3 && 3 >= 2) noop


Posted By: Mpdreamz Re: Auto oping certain nicks. - 08/11/07 07:22 PM
Originally Posted By: Riamus2

But, this starts to become too much, imo:
if ((this == that) || (this == that)) { }


Actually thats the only right way to avoid ambiguity and the way alot of languages will FORCE you to do it. I actually prefer this style since it's easer to understand how the if is evaluated just as ((2 - 4) * 2) is easier to understand than 2 - 4 * 2 both are valid but yet yield different values because of the ambiguity in the latter.

The test posted above is wrong on many levels i.e "If 1 <= 2 noop | noop" .... i'll let you figure out why thats wrong yourself.

Then theres the issue you only test 1 condition if statements when comparisons get complex, i have a good hunch using all the proper ()'s will speed it up. I tested this some versions back but i'm unable to find my post on here. but as starbucks_mafia put it very well here
Quote:

Whether that's still true, whether that's always true, and whether the speed benefits actually matter or not, I don't know.
Posted By: TropNul Re: Auto oping certain nicks. - 09/11/07 08:57 AM
Quote:

The test posted above is wrong on many levels i.e "If 1 <= 2 noop | noop" .... i'll let you figure out why thats wrong yourself.


This example was done on purpose for those who still confuse when conditioning like that. I assure you that many still think that the 2 following commands in 'If 1 <= 2 noop | noop' will be executed if the condition is true. As this is totally false, I added this kind of 'ambiguous' format.

I had no intention to prove anything. I just wanted to see how all these examples behaved globally. As nomen added some more examples, there may be like those many many more that can be added. It's just a matter of wanting to test.

Regards
Posted By: Mpdreamz Re: Auto oping certain nicks. - 09/11/07 03:35 PM
I apologize for assuming you didn't know which in retrospect is rather rude of me.

I guess if you had stated:
Quote:

I had no intention to prove anything. I just wanted to see how all these examples behaved globally.

I wouldn't have replied so fiercely as i felt you blatantly ignored some (perhaps) important factors.
Posted By: LexRock Re: Auto oping certain nicks. - 17/11/07 01:46 PM
I got a little follow-up question:
Say I want to message anohter nickthe instant I join the same channel, how do I do that? (Assume the one i want to message is callen AnotherNick, and the message is: "Hey you")

How do I set up this?
Posted By: RoCk Re: Auto oping certain nicks. - 17/11/07 04:12 PM

Code:

on me:*:JOIN:#chan: {
  .timer 1 5 if (AnotherNick ison # ) msg $!v1 Hey You
}



Change #chan to the channel name you want.
Posted By: LexRock Re: Auto oping certain nicks. - 18/11/07 03:19 PM
Thanks!
Posted By: nomer2007 Re: Auto oping certain nicks. - 18/11/07 03:43 PM
Code:
on me:*:JOIN:#chan: {
  .timer 1 5 if (AnotherNick ison # ) msg $!v1 Hey You
}


$v1 is referring to the (nick)
but what is $!v1 refer to?
Posted By: RoCk Re: Auto oping certain nicks. - 18/11/07 04:04 PM

It's referring to the nick as well, adding the ! forces the identifier to be evaluated when the time executes rather then when the timer is started. I don't know why I used that instead of just using the nick, probably just because it's shorter and it's habit I guess.

~ Edit ~

From mirc.chm:

You can force identifiers to be re-evaluated when used in a /timer command by using the
format $!me or $!time.


Posted By: RoCk Re: Auto oping certain nicks. - 19/11/07 05:12 PM

I probably shouldn't have used the ME prefix. ME is an event prefix that has not been documented for a long time, but is still supported.

Code:

on ME:*:JOIN:#chan: {
  .timer 1 5 if (AnotherNick ison # ) msg $!v1 Hey You
}


on ME:*:JOIN:#chan:

In red is ME, the event prefix which will cause the event to be triggered only by yourself

In blue is the user level, which in the case of the other thread is SITEBOT


To not use the ME prefix, you would use this instead...
Code:

on *:JOIN:#chan: {
  if ($nick == $me) .timer 1 5 if (AnotherNick ison # ) msg $!v1 Hey You
}



This is what I should've used then.

Posted By: nomer2007 Re: Auto oping certain nicks. - 19/11/07 06:48 PM
Thank you sir smile
Posted By: LexRock Re: Auto oping certain nicks. - 20/11/07 03:01 PM
Thanks folks, this helped me alot!:)
© mIRC Discussion Forums