mIRC Home    About    Download    Register    News    Help

Topic Options
#235875 - 17/01/12 11:22 PM Problems with a ban all command
Starasdsd Offline
Nutrimatic drinks dispenser

Registered: 17/01/12
Posts: 7
I'm quite new to mIRC scripting and have had some coding experience in other languages, but I'm having trouble with this.
To make the banall command I am using a hash table, and the code is as follows:

on *:JOIN:#raku:{
/hadd -s Users_on_channel $address }
}

on *:PART:#raku:{
/hdel -s Users_on_channel $address }

on *:TEXT:*:#raku: {
if ($nick isop $chan && $me isop $chan) {
if ($1 == .banall) { set %var $hget(Users_on_channel,0).item ;returns amount of values in the hash table
set %i 1
while (%i <= %var)
{
/ban $chan $hget(Users_on_channel, %i).data
inc %i
}
}
}

Is there a more efficeint way of doing this or fixing the code?
And yes, the table exists.



Edited by Starasdsd (17/01/12 11:22 PM)

Top
#235876 - 17/01/12 11:41 PM Re: Problems with a ban all command [Re: Starasdsd]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
There really isn't much reason to use a hash table. You already know who is on the channel. Just ban them that way. You can loop through the nick list using $nick($chan,N) where N is the number of the nick. You can also use that to only ban regular users or regular and voiced users or whatever so you're not banning the ops. The only thing to keep in mind is that you need to check that $address() exists for each person because anyone in the channel when you join who doesn't type or do anything won't have an updated address. For anyone without the address, you'll need to check /userhost or /who or /whois to obtain the address of that nick before you can ban them. Of course, your script doesn't handle anyone who is already in the channel when you join anyhow. So if you want it to just work like yours, then skip anyone without an $address().

Notes on yours...
* Two many }'s on the on JOIN event.
* You are adding the ITEM $address to the table without and DATA and then you're banning using DATA. That won't work.
* Banning each person separately is a huge flood. You should check what the server allows for multiple bans and ban them in groups (e.g. +bbbb address1 address2 address3 address4).
* Use @ on your event to check if you are an op instead of using an IF ($me isop $chan) line.
* For while loops and anything else that is only used within the script and not needed once the script finishes, it's usually best to use local variables instead of global variables (/var instead of /set).
* You are missing a } in your on TEXT event.
* You aren't removing anyone who QUITS.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#235877 - 18/01/12 12:05 AM Re: Problems with a ban all command [Re: Riamus2]
Starasdsd Offline
Nutrimatic drinks dispenser

Registered: 17/01/12
Posts: 7
Ok... so, now I have this:


if ($1 == .banall) { var %var $nick(#raku,0,a,o)
var %i 1
while (%i <= %var)
{
/ban $chan $nick(#raku,%i,a,o)
inc %i
}
}

Top
#235878 - 18/01/12 12:22 AM Re: Problems with a ban all command [Re: Starasdsd]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
That should work if it's in your on text event. Again, you might want to combine bans into a group to avoid really flooding the channel. I usually do that by using $addtok() to add all the addresses to a variable, then when $numtok() says that I have the right number of addresses, I do a ban on that variable and unset it and add more addresses to it. That would be done in your while loop. Then, after the while loop is finished, you would want to check if the variable has anything in it and ban those. That is because you might have been banning in groups of 4, but ended up with 2 in the variable when you finished going through the nicks. So they'd have to be banned separately once the loop finishes.

Also, remember that anyone who was in the channel when you joined and who hasn't said or done anything will not have an $address. You'd need to obtain that by checking one of the commands I listed above with your script whenever the $address() is $null. That or just ban the $nick if the $address is $null.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#235883 - 18/01/12 03:11 AM Re: Problems with a ban all command [Re: Riamus2]
Starasdsd Offline
Nutrimatic drinks dispenser

Registered: 17/01/12
Posts: 7
Its not working for some reason, and I havent bothered adding $addtok etc because I am really not all that familiar with these identifiers smirk

I think the problem lies in the execution of the ban:

/ban $chan $nick(#raku,%i,a,o)
But i have no idea whats wrong.

Top
#235885 - 18/01/12 04:06 AM Re: Problems with a ban all command [Re: Starasdsd]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
This should work to ban all the users in the channel except ops.
Code:
on $@*:text:/\.banall/iS:#raku:{
  if ($nick isop #) {
    var %i = 1, %n, %- = $nick(#,0,a,o)
    while ($nick(#,%i,a,o)) {
      %n = %n $v1
      if (%i = %-) || ($numtok(%n,32) == $modespl) {
        mode # $+(+,$str(b,$v1)) $address(%n,2)
        %n = ""
      }
      inc %i
    }
  }
}
I've taken the liberty of banning the type two address instead, which is the host.

Top
#235886 - 18/01/12 04:16 AM Re: Problems with a ban all command [Re: Tomao]
Starasdsd Offline
Nutrimatic drinks dispenser

Registered: 17/01/12
Posts: 7
Not working, I am and op and so is the bot.
Also note I have this in an on text event.

this is what I have used:

Code:
if ($1 == .banall) { var %i = 1, %n, %- $nick(#raku,0,a,o)
      while ($nick(#raku,%i,a,o)) {
        %n = %n $v1
        if (%i = %-) || ($numtok(%n,32) == $modespl) {
          mode #raku $+(+,$str(b,$v1)) $address(%n,2)
          %n = ""
        }
        inc %i
      }
    }

EDIT: Shouldn't there be a space where the $+ and the start of the brackets are?


Edited by Starasdsd (18/01/12 04:26 AM)

Top
#235887 - 18/01/12 04:30 AM Re: Problems with a ban all command [Re: Starasdsd]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
You don't need to specify the channel name throughout the code. You only need the channel name jotted down by the text event, as shown to you above. That will tell mIRC to listen to the certain channel.

It's optional if you want to leave a space. It works both ways.

Do you happen to use an outdated copy of mIRC?

Top
#235888 - 18/01/12 04:41 AM Re: Problems with a ban all command [Re: Tomao]
Starasdsd Offline
Nutrimatic drinks dispenser

Registered: 17/01/12
Posts: 7
Ah I see.
I'm using version 7.22

Top
#235889 - 18/01/12 04:59 AM Re: Problems with a ban all command [Re: Starasdsd]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
Try with correct syntax, your first if statement is missing an opening {, and the 2nd if should be:

Code:
 if ((%i == %-) || ($numtok(%n,32) == $modespl)) {
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#235890 - 18/01/12 08:32 AM Re: Problems with a ban all command [Re: argv0]
Starasdsd Offline
Nutrimatic drinks dispenser

Registered: 17/01/12
Posts: 7
The first if statement is not missing a {..
Trying what you suggested.

EDIT: Doesn't work.

Ive tried other commands I have within the same event and they work fine, so it isn't a glitch.


Edited by Starasdsd (18/01/12 09:19 AM)

Top
#235891 - 18/01/12 10:10 AM Re: Problems with a ban all command [Re: Starasdsd]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
Hit Ctrl+H in the script editor, it will pop up a messagebox if you are missing any braces anywhere. Make sure it doesn't pop up any messageboxes.
_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#235892 - 18/01/12 10:37 AM Re: Problems with a ban all command [Re: argv0]
Starasdsd Offline
Nutrimatic drinks dispenser

Registered: 17/01/12
Posts: 7
It isnt missing any.

Top
#235901 - 18/01/12 10:18 PM Re: Problems with a ban all command [Re: Starasdsd]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
Place the code in a new remote file. You can't have multiple text events in the same remote. Only the first one on top will trigger:

This is your original code:
on *:text:*:#:{
...
}

This is my suggestion to you:
on *:text:*:#:{
...
}

You need to either remove the first text event or combine them as one. This is the scenario I can think of that your mIRC won't respond to the code execution.

Another way is to have both text events listen to different triggers:

on *:text:.banall:#:{
on *:text:.banall2:#:{

Then you can have as many as you want in the same remote without any conflict.


Edited by Tomao (18/01/12 10:34 PM)

Top