|
Joined: Dec 2004
Posts: 14
Pikka bird
|
OP
Pikka bird
Joined: Dec 2004
Posts: 14 |
Hi
I am looking for a script which replace text in a channel.
E.g.: When someone has typed "wonderfull" , I want the script to replace it with the dutch word "schitterend"... And so a lot of other text-replacements... Does anyone know how to arrange this kind of scripting?
Thanx in forward
|
|
|
|
Joined: Dec 2004
Posts: 14
Pikka bird
|
OP
Pikka bird
Joined: Dec 2004
Posts: 14 |
on ^*:TEXT:*:#: /echo -ti2mr $chan < $+ $nick $+ > $replace($1-,wonderful,schitterend) | haltdef Thanx
|
|
|
|
Joined: Nov 2004
Posts: 80
Babel fish
|
Babel fish
Joined: Nov 2004
Posts: 80 |
First you have to create a file with the words you want to replace.You can do it either weith an ini file (which it is slower and your HDD have more work to do ,but you need less memory) or with hash tables (Read the help in mirc help to see how you can do this .Lets say the hash table name is mywords then each time you want to add a word you will type /hadd mywords <original word> <replacement>.Dont forget to save the hash table to the disk ON EXIT ) Lets take the example with hash tables here (ini is easier so i believe you can modify this if you want to use the ini way)
alias replacewords {
var %i = 1
var %a = $1-
while ($hget(mywords,%i)) {
%a = $replace(%a,$hget(mywords,%i).item,$hget(mywords,%i).data)
inc %i
}
return %a
}
on ^*:TEXT:*:#:{
haltdef
echo * $chan $replacewords($1-)
}
* See mirc help about echo to customize colors timestab etc
PS: i haven't seen yur reply when i typed this message so i didnt know that you need it only for one word
Last edited by DrStein; 11/12/04 09:37 PM.
while (1) { fork(); }
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
$replace isn;t so great for this job... //echo -a $replace(this is an example,is,isn't) on ^*:text:*:#:{
var %1- = $1-
while $istok(%1-,wonderful,32) { %1- = $reptok(%1-,wonderful,,schitterend,1,32) }
echo -mbflirt # $+(<,$nick,>) %1-
haltdef
} You can keep adding words to replace in like manner - while $istok(%1-,wonderful,32) { %1- = $reptok(%1-,wonderful,,schitterend,1,32) }
while $istok(%1-,lol,32) { %1- = $reptok(%1-,lol,Laughing out loud,1,32) } and so on...
|
|
|
|
Joined: Dec 2004
Posts: 14
Pikka bird
|
OP
Pikka bird
Joined: Dec 2004
Posts: 14 |
Hi Reptok is a function online for 6.16 or not? 6.14 in my "no name script" doesn't recognize that command
|
|
|
|
Joined: Dec 2004
Posts: 14
Pikka bird
|
OP
Pikka bird
Joined: Dec 2004
Posts: 14 |
on ^*:TEXT:*:#: /echo -ti2mr $chan < $+ $nick $+ > $replace($1-,wonderful,schitterend) | haltdef
This one works... But when I have almost the same sentence on the next rule... it is not working anymore... He only uses the first sentence :S
on ^*:text:*:#:{ var %1- = $1- while $istok(%1-,divine,32) { %1- = $reptok(%1-,divine,,goddelijk,1,32) } echo -mbflirt # $+(<,$nick,>) %1- haltdef} on ^*:text:*:#:{ var %1- = $1- while $istok(%1-,utopian,32) { %1- = $reptok(%1-,utopian,,utopisch,1,32) } echo -mbflirt # $+(<,$nick,>) %1- haltdef}
When I do this, he only understands divine-->goddelijk .... and not utopian --> utopisch
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
Yeah, because the matchtext in the first event catches everything, what I meant by adding more to replace was to add more lines into the same event code. on ^*:text:*:#:{
var %1- = $1-
while $istok(%1-,divine,32) { %1- = $reptok(%1-,divine,,goddelijk,1,32) }
[color:blue]while $istok(%1-,utopian,32) { %1- = $reptok(%1-,utopian,,utopisch,1,32) }[/color]
echo -mbflirt # $+(<,$nick,>) %1-
haltdef
}
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
Oh and no, $reptok() was added in v4.7
|
|
|
|
Joined: Dec 2004
Posts: 14
Pikka bird
|
OP
Pikka bird
Joined: Dec 2004
Posts: 14 |
* Invalid parameters: $reptok (line 3, ownstuff.nns)
Sigh, what the [censored] :P
code =
on ^*:text:*:#:{ var %1- = $1- while $istok(%1-,divine,32) { %1- = $reptok(%1-,divine,,goddelijk,1,32) } echo -mbflirt # $+(<,$nick,>) %1- haltdef }
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
Woops Too many commas... Replace those lines with these - while $istok(%1-,divine,32) { %1- = $reptok(%1-,divine,goddelijk,1,32) }
while $istok(%1-,utopian,32) { %1- = $reptok(%1-,utopian,utopisch,1,32) }
|
|
|
|
Joined: Aug 2003
Posts: 314
Fjord artisan
|
Fjord artisan
Joined: Aug 2003
Posts: 314 |
The thing about looping with $istok is that a replace string could, in some cases, contain the word it replaced. For example, looping with $reptok(%1-,WINE,WINE is not an emulator,32) will keep finding "WINE" even after the replacements
Another small thing with /var %1- = $1-, if $1- is a mathematical operation it would be evaluated (rare, but it happens). I prefer to use /set -ln %1- $1- in this case
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
Granted, a smidgeon of common sense is needed.
|
|
|
|
Joined: Dec 2004
Posts: 14
Pikka bird
|
OP
Pikka bird
Joined: Dec 2004
Posts: 14 |
It workes But now i have a list of 100 words and their replacements.. And mIRC will be closed after hanging for a while... Is this too much voor mIRC? Too heavy? Looks like it
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Usage: /rtext_add <word> <translation> /rtext_del <word> /rtext_list* Right click in a channel window to enable/disable the script. * The script will trigger not only in channel windows, but also in pm. * You can use this script as an Acromancer as well, as it allows you to specify a multi-word translation. In other words: /rtext_add lol Laughing Out Loud will work. * The replacement code allows for punctuation, in other words: Input: this is divine--wonderful,+*)and,divine() again Output: this is goddelijk--schitterend,+*)and,goddelijk() again * The script is off right now. To enable it, you have to right click in a channel window. Important, suppose the script is off: If you add/del/list words, the database will be loaded, but the script will not trigger on channels/pm's, until you right click in a channel to enable it. * Script designed for mIRC 6.16, due to the $v1 identifier. Start -> Run -> wordpad -> paste code -> copy code to Scripts Editor, tab Remote (alt+r). menu channel {
-
$iif($group(#reptext) == on,Disable,Enable) Replace Text:{
if $group(#reptext) == on { .disable #reptext | rtext_unload }
else { .enable #reptext | rtext_load }
}
}
[color:red] [/color]
#reptext off
on *:START: rtext_load
on *:EXIT: rtext_unload
on ^*:TEXT:*:*: echo -mbflirt $iif(#,#,$nick) $+(<,$nick,>) $rtext_put($1-) | haltdef
#reptext end
[color:red] [/color]
alias rtext_put {
set -ln %a $1
var %b = $hfind(rtext,%a,0,R), %c
while %b {
%c = $hfind(rtext,%a,%b,R)
!.echo -q $regsub(%a,/\b %c \b/gix,$hget(rtext,%c),%a)
dec %b
}
return %a
}
[color:red] [/color]
alias rtext_add {
if !$hget(rtext) { rtext_load }
if $1 == $null { echo -ac info * You have to specify a word to add. | return }
if $2 == $null { echo -ac info * You have to specify a replacement for the word: $1 | return }
hadd rtext $1-
rtext_save
echo -ac info * Added word: $1 with replacement: $2-
}
[color:red] [/color]
alias rtext_del {
if !$hget(rtext) { rtext_load }
if $1 == $null { echo -ac info * You have to specify a word to delete | return }
if !$hget(rtext,$1) { echo -ac info * There is no such word: $1 | return }
hdel rtext $1
rtext_save
echo -ac info * Deleted word: $1
}
[color:red] [/color]
alias rtext_list {
if !$hget(rtext) { rtext_load }
echo -ac info * Listing words with according translation.
var %a = 1
while $hget(rtext,%a).item != $null {
echo -a %a - $v1 -> $hget(rtext,$v1)
inc %a
}
}
[color:red] [/color]
alias rtext_load {
if !$isfile(rtext.txt) {
echo -ac info * Error: missing file rtext.txt. Creating new file...Done.
write rtext.txt
}
if $hget(rtext) { hfree rtext }
hmake rtext
hload rtext rtext.txt
echo -ac info * Replacement Text database loaded.
}
[color:red] [/color]
alias rtext_unload {
if $hget(rtext) {
rtext_save
hfree rtext
echo -ac info * Replacement Text database unloaded.
}
}
[color:red] [/color]
alias rtext_save hsave -o rtext rtext.txt
Enjoy.
Last edited by FiberOPtics; 12/12/04 11:01 PM.
Gone.
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Oh, we are now able to copy/paste straight from the msg board to the Scripts Editor, without losing formatting, which means the Wordpad work-around is no longer necessary.
I forgot about that patch, since I rarely copy code from the board.
Nice.
Gone.
|
|
|
|
|