mIRC Homepage
Posted By: mysticalNinja Op/Deop/Voice/Devoice Script - 25/08/11 04:14 PM
i made an op/deop/voice/devoice script and i want to do that only the op's with level up to 10.
Code:
 if ( $1 == !op ) { /cs op $chan $2 | notice $2 Welcome  }
    if ( $1 == !deop ) { /cs deop $chan $2 | notice $2 Sorry  }
if ( $1 == !voice ) { /cs voice $chan $2 | notice $nick  Voiced }
    if ( $1 == !devoice ) { /cs devoice $chan $2 | notice $nick DeVoiced }

i made that with if ( $nick isop)
i know i have to make it with on *:TEXT: but can you tell me how to do it because i am newbie with script.
Thanks in advance
Posted By: Riamus2 Re: Op/Deop/Voice/Devoice Script - 25/08/11 04:21 PM
Code:
on 10:text:*:#channel: {
  ; Your code here
}


Make sure the users are set at level 10 (or higher) in your user list. And, I'd suggest using ELSEIF instead of IF for the last 3 just to make it more efficient.
Posted By: mysticalNinja Re: Op/Deop/Voice/Devoice Script - 25/08/11 04:28 PM
Thanks but i dont want the opers to do it if they dont have access lvl 6
and i dont want the users to do it smile
smile
Posted By: Riamus2 Re: Op/Deop/Voice/Devoice Script - 25/08/11 06:03 PM
The number in the on text event tells you what level the person has to be. You said originally that you wanted them to have access level 10, so 10 is there. If you want 6 instead, use that. No one without an access level (regular channel visitors, etc) cannot use it because it requires them to have the access level listed in the event.
Posted By: mysticalNinja Re: Op/Deop/Voice/Devoice Script - 25/08/11 07:38 PM
it works thanks and if the user that gonna use it dont have the access to use it how i can make to send him a notice tha You Can Use This Command.
Posted By: Riamus2 Re: Op/Deop/Voice/Devoice Script - 25/08/11 07:56 PM
Instead of only triggering for a specific level (having the level in the event line itself), you can use an IF statement to check $ulevel and then based on what the level is, allow the command or give an error message.
Posted By: Tomao Re: Op/Deop/Voice/Devoice Script - 26/08/11 12:55 AM
That's true, Riamus2, but by using the if statement, it'll trigger the error check anytime if anyone sends a text. The text event may need to be made a regex to ensure it triggers on those aforementioned commands only. I don't think making it as:

on *:text:!*:#:{

is such a good idea, because it'll also be triggered if someone enters !!!!!!!! for any reason.
Posted By: Riamus2 Re: Op/Deop/Voice/Devoice Script - 26/08/11 10:09 AM
It can definitely be made regex, but there really isn't anything wrong with a text event that triggers on everything either. Yes, it's less work to avoid triggering on all text, but it really doesn't hurt. That's what any theme script is going to do.
Posted By: Tomao Re: Op/Deop/Voice/Devoice Script - 26/08/11 04:42 PM
I meant if I composed the code this way:
Code:
on *:text:*:#:{  
  tokenize 32 $strip($1-)
  if ($ulevel == 10) { 
    if ($1 == !op) { 
      cs op $chan $2 
      notice $2 Welcome 
    }
    elseif ($1 == !deop) { 
      cs deop $chan $2 
      notice $2 Sorry
    }
    elseif ($1 == !voice) { 
      cs voice $chan $2 
      notice $nick  Voiced 
    }
    elseif ($1 == !devoice) { 
      cs devoice $chan $2 
      notice $nick DeVoiced 
    }
  }
  else { 
    notice $nick You cannot use the command $1 
  }
}
this is going to trigger "You cannot use the command" warning every time someone enters a message who doesn't have an access level 10.
Posted By: Riamus2 Re: Op/Deop/Voice/Devoice Script - 27/08/11 01:01 AM
Ok, I see what you meant. Yeah, you'd have to do it differently... something like:

Code:
on *:text:*:#:{  
  tokenize 32 $strip($1-)
  if ($istok(!op !deop !voice !devoice,$1,32) && $2) {
    if ($ulevel == 10) {
      cs $remove($1,!) $chan $2
      if (op isin $1) { notice $2 $iif($1 == !op,Welcome,Sorry) }
      else { notice $nick $iif($1 == !voice,Voiced,DeVoiced) }
    }
    else { notice $nick You cannot use the command $1 }
  }
}


Or, for a regex option:

Code:
on *:text:*:#:{
  tokenize 32 $strip($1-)
  if ($regex($1,/!(de)?(op|voice)/) && $2) {
    if ($ulevel == 10) {
      cs $remove($1,!) $chan $2
      if (op isin $1) { notice $2 $iif($1 == !op,Welcome,Sorry) }
      else { notice $nick $iif($1 == !voice,Voiced,DeVoiced) }
    }
    else { notice $nick You cannot use the command $1 }
  }
}


I believe I have the regex correct, but someone can improve it if it needs it. smile
Posted By: Tomao Re: Op/Deop/Voice/Devoice Script - 27/08/11 06:55 AM
Right on. Thanks for understanding what I meant and taking your time with these two examples, Riamus2.
Originally Posted By: Riamus2
I believe I have the regex correct, but someone can improve it if it needs it. smile
Code:
on $*:text:/^!(de)?(op|voice)( |$)/i:#:{
  tokenize 32 $strip($1-)
  if ($2) {
I'm sure you're already aware that regex is case-sensitive until you specify the /i modifier at the end of match or (?i) option in the regex match section. This is to presume that some people may have their text capitalized. The ^ is to make sure it starts with ! followed by the command. ( |$) basically means it proceeds a space or ends the command as is. It's better than the \b word boundary. \b won't prevent punctuation characters.

Last but not least, happy birthday to you. I see you have a birthday cake by your nickname.
Posted By: Riamus2 Re: Op/Deop/Voice/Devoice Script - 27/08/11 02:57 PM
Thanks for the updated regex. Still learning and I did forget about /i. I considered putting it on the event line like that, but then you don't get the else option to give an error message to the user.

And thanks for the birthday wish. smile
Posted By: Tomao Re: Op/Deop/Voice/Devoice Script - 27/08/11 04:43 PM
Originally Posted By: Riamus2
I considered putting it on the event line like that, but then you don't get the else option to give an error message to the user.
Well it's not the end of the world with $regml(). Here is just my example:
Code:
on $*:text:/^!((de)?(op|voice))( |$)/iS:#:{
var %n = $strip($2), %c = $regml(1)
if (%n) {
if ($ulevel == 10) {
cs %c #
if (%c == op) notice %n Welcome
elseif (%c == deop) notice %n Sorry
else notice $nick $+($iif(%c == voice,Vo,Devo),iced)
}
else notice $nick you can't use the command $+(!,%c)
}
}
Posted By: Riamus2 Re: Op/Deop/Voice/Devoice Script - 27/08/11 07:50 PM
Ah, good one. I didn't think of being able to use $regml() when the regex is in the event line. smile
© mIRC Discussion Forums