mIRC Homepage
Posted By: sigbin how can i? little help plz - 15/08/07 04:15 PM
am hows is it to only work a "on *:nick" script in a specific channel?

is this correct?
Code:
on 1:NICK: {
  if ($chan == #channel) {
      if ($nick !isop $chan) {
        something to be executed
  }
}

or anything wrong with that code?
Posted By: LostShadow Re: how can i? little help plz - 15/08/07 04:19 PM
Should work fine. Make sure you have 1 on nick event in the remote page. You might also be looking at $newnick.
Posted By: sigbin Re: how can i? little help plz - 15/08/07 04:27 PM
i dont know how to use the $newnick can you give me an example on that?
Posted By: Horstl Re: how can i? little help plz - 15/08/07 05:00 PM
Two (fictive) examples smile
Code:
on ^*:nick: {
  echo -ca info $nick changed nick to $newnick
  haltdef
}

Code:
on *:nick: {
  if ($count($newnick,sex,fugg,whatever)) { echo -a offensive new nick of $nick : $newnick }
}
Posted By: Wims Re: how can i? little help plz - 15/08/07 06:16 PM
In a on nick event, $chan return $null (you don't change your nick in a specific channel).
Generaly you have to use $comchan($nick\$newnick,0) in a while smile
Posted By: sigbin Re: how can i? little help plz - 16/08/07 01:08 AM
thankz the both of you but i cant make it work or rather i dont know how to use that... can you help me integrate that to this code? some how make it work in a "on *:nick" script...
Code:
  if (!$hget(badnick)) hmake badnick 10
  var %i = 1
  while ($gettok($badnick,%i,32)) {
    if ($+(*,$gettok($badnick,%i,32),*) iswm $nick) {
      if ($nick !isop $chan) {
        hinc badnick $nick
        var %badnick = $gettok($badnick,%i,32)
        if ($hget(badnick,$nick) == 1) some kick nick command
        if ($hget(badnick,$nick) == 2) some ban nick command
      }
    }
    inc %i
  }
}
Posted By: Wims Re: how can i? little help plz - 16/08/07 02:07 AM
on *:nick:{
var %i = $numtok($badnick,32) ,%n $newnick ,%c $comchan(%n,0)
while (%i) {
if ($+(*,$gettok($badnick,%i,32),*) iswm %n) { hinc -m badnick %n $calc($hget(badnick,$nick) +1) | break }
dec %i
}
var %h = $hget(badnick,%n) ,%cmd $iif(%h == 1,kick,ban -k)
while (%c && %h) {
if ($me isop $comchan($newnick,%c)) && ($newnick !isop $v2) %cmd $v2 %n $iif(%h == 2,2) Badnick !
dec %c
}
}

i made some change, hope it's works smile

Note : your method to check if the nick is "bad" or not is not the best...
Posted By: sigbin Re: how can i? little help plz - 16/08/07 03:07 AM
thankz wims for the reply nd code... but this script i would lick to work that script in just a specific channel like channel #sigbin... that script will only work in that channel... am wim im in undernet network im using this command to kick or ban "/msg x kick #channel nick reason" i cant edit your code i dont know how...
Posted By: Wims Re: how can i? little help plz - 16/08/07 03:16 AM
Ok so use this :

on *:nick:{
var %i = $numtok($badnick,32) ,%n $newnick
while (%i) {
if ($+(*,$gettok($badnick,%i,32),*) iswm %n) { hinc -m badnick %n $calc($hget(badnick,$nick) +1) | break }
dec %i
}
if ($hget(badnick,$nick)) hdel badnick $nick
var %h = $hget(badnick,%n) ,%cmd $iif(%h == 1,msg x kick,$iif(%h == 2,ban -k))
if (%cmd) && ($me isop #sigbin) && (%n !isop $v2) %cmd $v2 %n $iif(%h == 2,2) Badnick !
if (%h == 2) hdel badnick %n
}

i add some "if" to delete the table for the old $nick, and another to delete the table of the $newnick if it's the second time that you "do something" for this nick..

Edit : change the $iif and if part, user that don't match your list were always ban
Posted By: sigbin Re: how can i? little help plz - 16/08/07 04:10 AM
thankz man... great help
Posted By: RusselB Re: how can i? little help plz - 16/08/07 04:49 AM
Wims: If you're going to post code, please use the Code Tags button. It looks like the # character, and is located in the bar at the top of these message areas.

Also please watch your formats, as you are using incorrect format for setting some of the variables, as well as setting variables when not required.

Here's a re-write of the code you posted.
Code:
on *:nick:{
  var %i = $numtok($badnick,32)
  while (%i) {
    if $+(*,$gettok($badnick,%i,32),*) iswm $newnick) { hinc -m badnick $newnick }
    dec %i
  }
  if ($hget(badnick,$nick)) hdel badnick $nick
  var %h = $hget(badnick,%n) ,%cmd = $iif(%h == 1,msg x kick,$iif(%h == 2,ban -k))
  if (%cmd) && ($me isop #sigbin) && ($newnick !isop $v2) %cmd $v2 $newnick $iif(%h == 2,2) Badnick !
  if (%h == 2) hdel badnick $newnick
}
Posted By: Wims Re: how can i? little help plz - 16/08/07 05:40 AM
Sorry about the code tags button, i'm not familiar with tags button, i'll try to use it now but is this is really annoying for you, or for other ?

And about the format, i don't call that "incorrect" because mirc allow us to script like that (i mean not put the egal sign in some case and the { }) i agree to say that i should not use this syntax but it's just a practice smile (and that take less place).
I'm one of those would want to see a single syntax for mirc in general because imo, if you have only one way to do something, so there can't be confusion for other.
You said that i use incorrect format, but compared to what are you saying this ? mIRC help not said it's incorrect (not said it's correct, but so, why allow it ?)

As $newnick is repeated several times, i think it's better to store it.
Posted By: Horstl Re: how can i? little help plz - 16/08/07 06:04 AM
Please use that code tags! This makes it much easier to comprehend...
Concerning syntax and brackets, every now and then there is a discussion about bracket use and misuse (most recent example) - there's much room for "personal taste of style".
For example, I'm prefering the most univocal bracket style:
Code:
on *:nick:{
  var %i = $numtok($badnick,32)
  while (%i) {
    if ($+(*,$gettok($badnick,%i,32),*) iswm $newnick) { hinc -m badnick $newnick }
    dec %i
  }
  if ($hget(badnick,$nick)) { hdel badnick $nick }
  var %h = $hget(badnick,%n) ,%cmd = $iif((%h == 1),msg x kick,$iif((%h == 2),ban -k))
  if ((%cmd) && ($me isop #sigbin) && ($newnick !isop $v2)) { %cmd $v2 $newnick $iif((%h == 2),2) Badnick ! }
  if (%h == 2) { hdel badnick $newnick }
}

On the other hand side, people will take snippets etc they see here as an example for their own scripts, thus the syntax should be as exemplary as possible (we all will slip up every once a while whistle ).

For example:
"var %varname plaintext-data" ...will work.
"var %varname $identifier" ...will not work in all circumstances.
"var %varname = plaintextdata or $identifier" ...will work. Therefore it is a good idea - from my point of view - to use always that syntax smile

Posted By: Wims Re: how can i? little help plz - 16/08/07 06:48 AM
My preference is to not use { } when it's not necessary and like Riamus2 said in the recent, thread don't put { } is more faster than put it (ok, not really..)

About the = sign, before, i used it in anytime because i did not know really what he mean, but today, i think it's necessary to use it only when value contain data that SHOULD be parsed as a variable setting like :

Code:
//var -s %a 1 ,%b 2 ,%c $mid(sometexthere,%a,%b)


If we just look at the $mid itself, he is right, but this command create an error :
* Invalid format: $mid
put the = sign solve the problem of course.
i don't know other case that = is required and i'll be happy to know, just for my knowledge smile
Posted By: Riamus2 Re: how can i? little help plz - 16/08/07 11:24 AM
I said it was faster, but I also said that it would not be noticeably faster. Unless you're testing speed by checking miliseconds, you won't even notice.

The biggest problem with not using them in this forum is that this forum is a help forum. People learn scripting from here. Even knowing how to script, this line is hard to understand without looking closely to see exactly what is going on in it:

Code:
if (%cmd) && ($me isop #sigbin) && (%n !isop $v2) %cmd $v2 %n $iif(%h == 2,2) Badnick !


If for no other reason, you should consider using {}'s in here just so that people learning scripting can easily understand what is going on and learn from it. It's also best to have people learn good scripting practices before learning shortcuts... especially shortcuts that may not always work. There are cases where leaving {}'s off will cause the script to fail even with only one command after an IF.

As for using the equal sign with /var, it is always best to use it simply because it also can fail if you do not. Yes, it will only fail with items that need to be parsed, but again, this is a help forum and people learning scripting will probably not see the relatively few times that we say when the equal sign is needed and when it isn't. That means that they may try without and then get an error and have no idea why they have an error.

Personally, I don't think it matters how people script on their own. If someone wants to make it 10ms faster by dropping a lot of {}'s, that's up to them. If he or she wants to make the code hard to understand so people are less likely to mess with it, that's also up to them. However, in a help forum or channel, it's better to follow proper syntax at all times. It reduces the number of problems people have when learning to script. smile
Posted By: Bekar Re: how can i? little help plz - 16/08/07 12:08 PM
Here Here!
Posted By: Wims Re: how can i? little help plz - 16/08/07 03:01 PM
Lol, ok.
Posted By: hixxy Re: how can i? little help plz - 16/08/07 03:46 PM
Using only one ( and ), or surrounding the entire if statement in an extra set of () would make it just as easy to read imo.

if (x && y && z) do this
if ((x) && (y) && (z)) do this
if (x) && (y) && (z) { do this }

The first two are just as good.
Posted By: Riamus2 Re: how can i? little help plz - 17/08/07 12:14 AM
Personally, I use:

if (x && y && z) { do this }

In any case, as I said, it's just my personal opinion. I think that the entire IF section should always have ()'s around it and commands should have {}'s around it except in certain situations when you may not want to. And unless there are order of operations issues, I don't bother with having a bunch of extra ()'s inside of the IF because too many also can make it harder to read. Again, it's just my personal opinion and I was just explaining my reasoning. smile

Note that I also don't put multiple commands on a single line using pipes except in the case of using RETURN after a command and I never put anything on the event line. Again, just personal preference. And for anyone who wants to mention speed... I don't accept that a few miliseconds are noticeable enough to make it worth doing it differently. smile
© mIRC Discussion Forums