How do I reop or unban myself

From Scriptwiki
Jump to: navigation, search

This tutorial will help you create a script that gives you some basic protection. Whenever someone deops you in your channel, it will automatically ask Q to reop you again. Also, when someone bans you, it will attempt to unban you again. Difficulty: easy

First we'll look at how mIRC scripting actually handles these things. Whenever something happens (a message, a mode change, a kick and so on), your script can react to this. What you need are the so called remote events. You can read more about them by typing /help remote in a mIRC window. I suggest you do that right now.

As you can see, the helpfile recommends you read through documents on Commands, Aliases, Variables and Identifiers. Although it is always a good idea to do so, you might not fully understand what they do and how they work, so understanding all this is not required for this tutorial.

Besides this, you'll see two other things in the help file. One is a list with events, the other is a note at the end: Note: You should never load or use a script that you don't understand. Whatever you do, keep this in mind! Lots of users have their Q accounts compromised and other data lost, just because they run a false script.

Back to our problem. We want to get our ops back when someone removes it, so the event we need is the DeOp event. Click on it in the list. The on OP and on DEOP events trigger when a user on a channel is opped or deopped. Sound like it's exactly what we need. Have a look at the format and the example below it:

 Format: on <level>:OP:<#[,#]>:<commands>
 Example: on 1:OP:#mirc,#irchelp:/msg $nick Please don't abuse your Op status

(on OP and on DEOP events work in a similar way.)

The 1 in the example is a userlevel. Userlevel 1 means the event always triggers, no matter what level the deop'ing user has, as mIRC per default assigns all users with level 1. The #mirc,#irchelp are obvioulsy channels the event should work for. Finally, the /msg $nick Please don't... part is the command that should be executed. $nick is an identifier. It returns something. If fishbot would have done the op, then mIRC would read the line as /msg fishbot Please don't... In words:

If someone with level 1 or higher (everyone) ops someone in #mirc or #irchelp, message him with Please don't abuse your Op status.

To use such an event, you'll need to paste it in Remote. Go to Tools -> Script editor or hit Alt + R. Should the field not be empty, then go to File and select New. If you'd want to use this event, you'd paste it in the large text field and press OK. For now, just press OK without pasting.

Let's say your channel is #mychannel. As we want this event to work for all userlevels too, we can make the biggest part of the event: on 1:DEOP:#mychannel:/command. The event can trigger more commands too. We're gonna change the format for that a bit:

on 1:DEOP:#mychannel:{
  command1
  command2
}

You might have seen the { } format before. Inside those, we can list as many commands as we want. Let's say your channel has Q. One of the commands we need would be: msg Q op #mychan. Instead of #mychan, we can use another identifier. $chan returns the channel all this happens on, so let's change the command to msg Q op $chan. This way you can use the same command for more than 1 channel.

Now we have another problem. If we'd use on 1:DEOP:#mychan:{ msg Q op $chan }, it would send the message if someone else gets deopped too. That's why we're gonna limit it using an if-statement. The if-statement basically checks something. If what it checks is true, it executes some commands. If not, it either does nothing or goes to an else part. For now we won't use else parts.

What we wanted to check was if it was you who got deopped. As the help on the op/deop event says, $opnick returns the person/nick who get's opped/deopped in those events. We'll need to use another identifier: $me. $me simply returns your own nickname. The if-statement we need would become if ($opnick == $me) { commands }. The == is an operator meaning 'equal to' and that's exactly what we want: "if (the person who gets deopped is equal to myself)"

Now, let's just put the if statement we just made inside the event:

on 1:DEOP:#mychannel:{
  if ($opnick == $me) {
    msg Q op $chan
  }
}

This will do what we need. If you get deopped on your channel, it will ask Q to reop you. Have a look at the spaces in front of some of the lines. mIRC automatically adds them when you click OK or the { } button in the remote dialog. The { } button is really useful, because it lets mIRC check if you have placed the { and } brackets correctly. When you'll write bigger scripts, you'll start using it a lot.

We'll now create another event. We want it to unban you whenever you get banned on your channel. Let's start with having a look at what actually happens. When someone bans, he sets a banmask, for example *!milk@*.cows.net. This mask contains wildcards, which means it bans dynamically. A wildcard, *, can be replaced by anything: bill!milk@white.cows.net will for example be banned.

With help from the helpfile, we can easily create the following event:

on @1:BAN:#mychannel:{
  if ($bnick == $me) {
    mode $chan -b $banmask
  }
}

Click the parts above you don't understand to see more information on them.

This event will work in some cases, but unfortunately by far not in all. $bnick only works when a nick is specified inside the banmask, like: nick!*@*.*. There is another possibility though.

If we want your full address, we can use $address($me,5) or $ial($me). (Again, click the identifiers mentioned for more detailed information on what they can do.)

We only used the == operator in if-statements until now. Now have a look at the iswm operator. It literally means is wildcard match. if (a*c iswm abc) would be true, if (ac* iswm abc) wouldn't.

Now, we can use this to check if the banmask matches your address; to check if 'you are banned':

on @1:BAN:#mychannel:{
  if ($banmask iswm $ial($me)) {
    mode $chan -b $banmask
  }
}

That will do the trick.

When you fully understand how these events work, you should also be able to create events that do these things:

- Kick someone who deops your friend - Only allow people with level 20 or higher to ban

Contributed by Voronoi