Jump to content

Simple Per Room Activation Example


err0r

Recommended Posts

I saw in the chat room where someone asked a simple way to enable a certain protection per room. In this example I will be using channel menu and gettok to set a variable containing rooms you want to enable the protection for.

 

First let's configure the popup window for the channel. For this example we will make a very simple on text protection.

This will add/remove the channel from the list of channels where the text prot will be active. A checkmark will mark if the protection is enabled for that particular channel

the variable will look like this

%textkick %#err0rtest,%#IRCommunity,%#_SoulFly_

Using $istok we can check if the room is already in variable. If it is it will remove it and if it isn't it will add it

menu channel {
      .$iif($istok(%textkick,$active,44),$style(1)) TextKick: $iif($istok(%textkick,$active,44),set %textkick $remtok(%textkick,$active,1,44),set %textkick $addtok(%textkick,$active,44))
    }

now on to a sample command to use the variable. In this very simple example it is set to trigger on the use of the word testing in their text. If the $chan istok ( sorta like isin ) the variable it will trigger. If not it won't.

on *:TEXT:*testing*:#: { 
    if ($istok(%textkick,$chan,44)) { echo -a the prot is on }
    }

 

For those unfamiliar with *toks here is a brief explanation of what i've done above

istok ( is token )

if ($istok(%textkick,$chan,44)

Here i am checking to see if the chan is in the variable. The 44 is simple the $chr num for a ,

In my example of the variable you see that each channel is separated by a comma

if my variable was %test one,two,three

$istok(%test,one,44) would be $true

$istok(%test,four,44) would be $false

 

Now we move on to the $addtok ( add token )

We have already checked to see if the channel istok .

Now in our menu snippet if $active is not in the variable we want to add it

set %textkick $addtok(%textkick,$active,44)

$addtok will only add it if it does not already exist.

So if you tried to addtok something that is already in there it will not add it twice. You will not have to worry about adding multiple instances of the same thing.

 

On the other end we have remtok ( remove token )

set %textkick $remtok(%textkick,$active,1,44)

Here we are removing the channel if it's in the variable.

the 1 represents the first instance. Since we used addtok there will always be just one instance so no need to change the 1.

You can leave the 1 out and it would remove any instance. Either way will work. Again the 44 is simply the character number for the , which I used to separate the channel names. You can use whatever character you want.. example space is 32, - is 45, etc

 

This is a very simple but effective way to do per channel events. As always there are lots of other ways to do it. If anyone sees any errors with this tutorial feel free to refine it. It's just a basic guide.

Link to comment
Share on other sites

Guest Travis

I suggest using # or $chan instead of $active.

 

I wrote tools in SoulFly that make channel specific switches very easy whether you choose to use hash tables, variables or an ini file.

 

Read about them here.

Link to comment
Share on other sites

just wanted to make sure i wasn't missing anything... it is specific in it's current format. There shouldn't be an instance in which what i posted wouldn't work correctly.

 

For those that do not understand:

 

make sure if you are using $active that the $active window will always be what you want. For example if you move to your status window then $active would not be the channel. Thus the term active.

 

If you use the menu channel or place the popup in the channel popup area then $active should be fine. You can use $chan if you prefer.

 

now if you use menu * you have to be very specific with your code as it does it for all menu's ie:nicklist,channel, etc.

 

Using the above method for channel specific stuff should be kept in the channel menu. If it was nicklist specific you should put it in your nicklist menu and so forth and so on.

 

Try to keep things in order and in their place and you will have a lot less trouble. The more general you are the more trouble you can run into. for all of us that have run into the stray error of invalid command with no line number you know what i mean.

 

There are countless other ways to do it.. ini's, text, hash, variables. It's whatever you get comfortable with. The method i described above is a very simple but effective way to achieve channel specific events.

 

If it works it works.

 

The debate will always continue what's best.. if vs $iif ,, brackets vs no brackets ,,,, $+ vs $+() ,,,, using $v1 instead of retyping the same thing ,,, halt vs return ,,,, goto vs while loop ,,,,, hash vs variable ,,,, look of code vs ability to easily edit the code... list goes on and on.. there are some advantages and disadvantages to most everything.. In the above i used $active vs $chan.. either will do fine in that example.. just whatever you prefer and are most comfortable with.

 

one thing i do see with $active.. many scripters i have seen that are used to running one script in one room misuse $active, $comchan, and amsg. It seems to be a carry over from our old msn days.. be careful using $active in on * commands. Same with $comchan(*,1) type things. If you are in multiple rooms the 1st common channel isn't always the one you want. same with $active. using amsg in place of msg <chan> is only intended if you wish to msg every channel you are in. Just because you only sit in one channel isn't a good reason to use amsg ( though i know it's easier ). It will only lead to problems later on. If you ever intend to use your script in multiple rooms make sure you use the proper identifiers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...