|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
I rewrote it, now everything working, but it must be a cleaner way to write it? would be nice if someone could explain or show me?
on *:ban:#: {
if ($me isop $chan) && ($banmask iswm $address($me,5)) && ($banmask != *!*@*) && ($banmask != *!~*@*) && (%ban.pro == Enabled) {
mode $chan -bo $banmask $nick
.notice $nick Don't ban me!!
}
if ($me !isop $chan) && ($banmask iswm $address($me,5)) && (%ban.pro == Enabled) {
echo -a Not oped in $chan $+ , can't unban my self.
}
else {
if ($me isop $chan) && ($banmask != *!*@*) && ($banmask != *!~*@*) && (%kickonban == Enabled) {
var %banmask = $banmask
if ($ial(%banmask,0).nick == 0) { return }
if ($banmask iswm $address($me,5)) { return }
var %totbu = $ial(%banmask,0).nick
var %stb = 1
while (%stb <= %totbu) {
echo -a working -> $ial(%banmask,%stb).nick
if (%stb == %totbu) { halt }
inc %stb
}
}
}
}
Last edited by sparta; 26/06/07 11:11 PM.
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
Joined: Dec 2002
Posts: 503
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 503 |
Just a few comments on the code in general.
1) Why do you put '$banmask' into '%banmask' ? You aren't changing it anywhere, so this is pointless. Just use '$banmask'.
2) As this is a channel-based event, you can drop the '$chan' in the if tests, i.e. 'if ($me isop)'.
3) The if's look to be checking the same things a few times, so can be re-structured to not re-check so many times.
4) Unless you've got code after this, why are you doing an extra 'if' within the while? It's superflouous.
|
|
|
|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
I fixed 1 and 2, dunno how to fix the last 2.
3) The if's look to be checking the same things a few times, so can be re-structured to not re-check so many times.
4) Unless you've got code after this, why are you doing an extra 'if' within the while? It's superflouous.
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
Joined: Jun 2007
Posts: 933
Hoopy frood
|
Hoopy frood
Joined: Jun 2007
Posts: 933 |
equals: elseif { while (%stb <= %totbu) {
echo -a working -> $ial(%banmask,%stb).nick
if (%stb == %totbu) { halt }
inc %stb
} Why use "if (%stb == %totbu) { halt }" at all? The while statement will automatically stop when %stb equals %totbu since that *is* your while statement.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Why use "if (%stb == %totbu) { halt }" at all? The while statement will automatically stop when %stb equals %totbu since that *is* your while statement. As mentioned, what you have there is unnecessary as your WHILE statement will automatically complete when those are equal. Beyond that, if you *did* want to halt the full script, you'd want to use RETURN instead of HALT, like you did previously. Or, if you just want to stop the WHILE loop, but want the script to continue running, then use BREAK.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Dec 2002
Posts: 2,031
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,031 |
2) As this is a channel-based event, you can drop the '$chan' in the if tests, i.e. 'if ($me isop)'. eh? That don't work.
|
|
|
|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
2)As this is a channel-based event, you can drop the '$chan' in the if tests, i.e. 'if ($me isop)'. it could have been working, on @*:ban:, then i could remove that line, but since i also use if ($me !isop $chan) { do stuff } it dosent work that well in my code
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
Joined: Dec 2002
Posts: 503
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 503 |
You're right.. Why did I think that worked ?! Anybody know if using '#' is faster than '$chan' in a channel-based event?
|
|
|
|
Joined: Dec 2002
Posts: 2,031
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,031 |
I don't know if it's faster or not but I normally use # over $chan in those types of situations, just a habit I guess. It's 4 less characters though
|
|
|
|
Joined: Jul 2006
Posts: 4,145
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,145 |
i make some test and it show that # is a little bit faster than $chan ( 10 ms with 5000 iteration ) but not tested with an event
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Dec 2002
Posts: 2,031
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,031 |
Maybe it's a little faster because with # there's no chance for parameters and properties so no need to check? I'm not sure if that's true or not, but it looks good. Could be true.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
I kind of have to laugh about such questions regarding speed. Yes, speed is important... to a point. Unless you have a huge script that does a LOT all at once, even a couple hundred miliseconds isn't going to be noticeable. It's just my opinion that worrying over that little bit of speed change is not worth the effort, of course. Now, if we're talking about seconds of difference, then it's worth caring about.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Dec 2002
Posts: 2,031
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,031 |
One identifier may not make a noticeable difference, but add that one unnoticeable difference together with all the other unnoticeable differences and suddenly you have a noticeable difference. But you're right, 10ms is nothing to worry about.
|
|
|
|
Joined: Dec 2002
Posts: 503
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 503 |
Yeah, I agree.
Was just curious..
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
One identifier may not make a noticeable difference, but add that one unnoticeable difference together with all the other unnoticeable differences and suddenly you have a noticeable difference. But you're right, 10ms is nothing to worry about. Only if it's all done at once. And in most cases, that is not true. There was discussion over how not using {}'s could make it "noticeably" faster. I have a LOT of scripts running and many of them use TEXT events in channels with a lot of text. The majority of code in my scripts use {}'s and there isn't enough of a slowdown to even notice without trying to detect it with a script. Everything happens fast enough that it might as well be called "instant." Sure, if you went through and ran all of my scripts without those {}'s and tested it with a script, you'd find that not using them would be faster... but when actually using the scripts as they are currently written, there isn't anywhere near enough slowdown to notice. It would really take a lot of things happening all at once for it to really be noticeable, or else some loop that needs to loop a LOT of times before getting a result, or something similar. That's all I'm saying. I believe in optimizing code, but there are just some things that really aren't worth bothering with and {}'s or ()'s or #/$chan are some of them. As such, I would use: if (this == that) { do this in $chan } Rather than: if (this == that) do this in # Or: if this == that { do this in # } Or whatever. Again, it's just my opinion. Besides, I personally find the first one much easier to read quickly without having to think about it. That makes for easier debugging.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
|