|
Joined: Oct 2005
Posts: 122
Vogon poet
|
OP
Vogon poet
Joined: Oct 2005
Posts: 122 |
hey just having trouble doing an on text event where if a word that is in a text file is in $1- it will preform commands
the textfile will have a word each line so
word word1 word2
then i need it to trigger if they say something like bla bla word1 bla bla kind of thing
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
Best method depends on if you are after getting a detect on " the sword stuck in the armor " detected as "word" which is what would happen with "IF (word isin $1-)" (method1) or do u only want it to detect the exact words in the text file being present as actual words? (method2)
method one means you trap every line of text, and then run through your text file doing ISIN's on each one method two means you trap every line of text, and then run through $1 $2 $3 etc using a $read(textfile,nts,$x)
I would actualy stick the text file into a hashtable if i was doing it as there faster.
|
|
|
|
Joined: Oct 2005
Posts: 122
Vogon poet
|
OP
Vogon poet
Joined: Oct 2005
Posts: 122 |
well yeh ill use exact word variations so sword would not be triggered, if hash table would make it easier then that would be alright, but you said ill have to manually check $1 $2 $3 could that possibly lag the script and how would i do that auto? without manually typing if $2, if $3 etc
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
this should work, it doesnt use hashtables, if its lagging ya come back ill write something that uses them (wont be overly faster since the OS well cache up the file to ram anyway) on *:TEXT:*:#:{
var %text = $1-
tokenize 32 $strip($1-)
while ($0) {
if ($read(textfile.txt,nts,$1) || $readn) {
....code on a match here ... $1 = matching word, %text = line of text said (before color stripping) ....
return
}
tokenize 32 $2-
}
} * code untested * it starts out saves the line into %text, i then strip the colors, when assuming there is a $1 (ie $0 is not zero), it checks $1 for being a word in the file, (since the nt s option well return no result when it locates one as it only returns the remaineder of the line which there isnt any) it then also checks if it had a matching $READN line it found a match on, if so do ya code and bugout, if NOT then tokenize $2- into $1-, and go back and look at the next word
|
|
|
|
Joined: Oct 2005
Posts: 122
Vogon poet
|
OP
Vogon poet
Joined: Oct 2005
Posts: 122 |
alright ty, just trying to do something else here, im tryin to check if a word is used in $1- and in text file, it checks if a variable of %NICKbad exists, % $+ $nick $+ Bad (then ill have another one if it is Set to 1 whcih is done if there wasnt a variable in the 1st place) code i got atm is
on *:TEXT:*:#:{
var %text = $1-
tokenize 32 $strip($1-)
while ($0) {
if ($read(badwords.txt,nts,$1) || $readn) {
if ( !$($+(%,$nick,.bad),2) ) {
set $+(%,$nick,.bad) 1
kick # $nick blah
return
}
else {
kick # $nick blah2
unset $+(%,$nick,.bad)
return
}
}
}
}
dont seem to be working tho Edit: Sorry and would it also be possible to do the script with hash tables, not so much because of the lag but because id prefer to use hashtables in another script im doing which is linked to this one
Last edited by onesikgypo; 16/01/06 01:27 AM.
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
on *:TEXT:*:#:{
if (!$hget(badwords)) { hmake badwords | hload -n badwords badwords.txt | .timer.hfree.badwords 1 3600 hfree -w badwords }
var %text = $1-
tokenize 32 $strip($1-)
while ($0) {
if ($hfind(badwords,$1,1,n).data) {
if ($($+(%,$nick,@badword),2)) {
kick # $nick blah2
unset $+(%,$nick,@badword)
}
else {
kick # $nick blah
set -u86400 $+(%,$nick,@badword) 1
}
return
}
tokenize 32 $2-
}
} * code untested * The first line, check s if the badword hashtable exists and if not, creates it, and loads it from the txt file using the -n (load data only option), lastly it creates a timer that well erase the hashtable each hour (3600secs), this well cause the next instance of the event to load it from file again, allowing for a hourly update should the badwords.txt file be altered. You may wish to change this frequency. A manual reload apon event can be envoked by simply typing /HFREE badwords. next I save the original text, tokenize it with out colors etc, loop through each word, I know look for the matching data in the hashtable *(note below) if its found i then see if the already done once flag on the nick has been set already, (i have adjusted this from being % nick.bad to being % nick@badword as @badword can not be part of a nick while .bad can be). If its already set I kick message 2, and unset the var, if it wasnt kick message 1 and set the flag, Im using -u86400 so the flAg self falls after 24hours, u can remove this or change the value, means currently u can be kicked once per 24hours without incurring a message2 kick. then I exit the event either way flag up or down. IF the word was NOT found i then retokenize $2- into $1-, and loop back for the next word. [b]<------ this was the bit you missed it would have likely caused your script to freeze mirc as it would have never ended.
|
|
|
|
|