mIRC Homepage
Posted By: Tw33ty $read problem - 17/07/06 02:26 PM
Any1 knows why this doesn't work?

Code:
on *:join:#:{
var %x = 1
inc %x
if ($read(badword.txt,%x) isin $nick) {
kick # $nick Bad Nick!
}
}
Posted By: MikeChat Re: $read problem - 17/07/06 04:59 PM
it didnt work because you have a var there that does nothing the way you wrote it.
if you have one word per line in badword.txt:
Code:
on *:join:#:{
var %x = $lines(badword.txt)
while (%x) {
if ($read(badword.txt,%x) isin $nick) {
kick # $nick Bad Nick!
}
dec %x
}


something like this might work, it might have false matches too.
fex: The_Assassin joins
A valid word, but likely to have a match in your file.

there is no good substitute for a good op
Posted By: Tw33ty Re: $read problem - 17/07/06 05:14 PM
thx
but what do while (%x) and dec %x exactly mean?
Posted By: Kurdish_Assass1n Re: $read problem - 17/07/06 05:48 PM
hey MikeChat laugh, "while (%x)" means while %x isn't null (has a value) and dec %x means decrease the value of %x by 1.
Posted By: Tw33ty Re: $read problem - 17/07/06 06:21 PM
thx
and where is the difference between "dec %x" and "inc %x"?
Posted By: OrionsBelt Re: $read problem - 17/07/06 06:37 PM
dec = decrease (so make smaller, 6, 5, 4, 3, ,2, 1)
inc = increase (so make bigger, 1, 2, 3, 4, 5, 6)
Posted By: billythekid Re: $read problem - 17/07/06 06:37 PM
dec %x is decresing by one and inc %x is incrementing by one. i personally prefer to inc until a number or condition is met, others prefer to decrement until a number or condition(usually 0) is met.

btk
Posted By: MikeChat Re: $read problem - 17/07/06 06:56 PM
as was said by Kurdish_Assass1n, the while runs in a loop the commands following it in the script, dec %x reduces the value of %x

on @*:join:#:{
var %x = $lines(badword.txt)
; If your badword.txt has 14 lines, %x has the value "14"
while (%x) {
; /help while loops
; as long as %x has a value bigger than 0 it will perform the commands
if ($read(badword.txt,%x) isin $nick) {
kick # $nick Bad Nick!
}
dec %x
; decreases the value in %x, which started at say 14
; each loop it will decrease just like a $calc would do, then the
;if ($read(badword.txt,%x) will read line 14, then line 13 then line 12 and so on til it
;hits 0, then the loop will exit to any other scripting written in before the
;closeing } of the event

}
Posted By: Tw33ty Re: $read problem - 17/07/06 09:33 PM
all right ... i think I got it ... thx for helping smile
Posted By: DaveC Re: $read problem - 18/07/06 09:02 AM
I sugest doing it this way.

Code:
on @*:join:#:{
 var %max = $lines(badword.txt), %counter = 1
 while (%counter <= %max) {
    if ($read(badword.txt,nt,%counter) isin $nick) { kick $chan $nick Bad Nick! | return }
    inc %counter
  }
}


1st get a %MAX value to go to (total lines in the file), and also set a start value %COUNTER to count up to the %MAX

Check if COUNTER is less or equal to MAX and if so do the contents of the while loop
..Read the word on line number COUNTER of the file and if its in $nick, then kick the nick & RETURN (exits the event) [means u dont carry on]
..Otherwise just add one to COUNTER and repeat the while loop check

* the reason i would start at the begining of the file and work towards the end, is two fold, there is less disk access in reading the first lines of the file vs the last lines, so if the match is located near the start smaller disk access has occured, 2nd reason is more real world logic than fact, the more likely bad words well be in the file first, so its better to start from the front of the file, than the end.

* the reason i store the %MAX value, is becuase every time u do $lines(badword.txt) it must read the whole file to get the number of lines, so its much much better to do it once and store it than compare to it in the while loop.

* the last thing to note is the RETURN following the kick, there is no reason to continue through the rest of the file if the user was kicked.
© mIRC Discussion Forums