|
zerosk8tr137@hotmail.com Newbie
Joined: 25 Jan 2003 Posts: 2 Location: USA
|
Posted: Sat Jan 25, 2003 2:16 am
Trigger Help - (One Trigger - Multiple patterns) |
The question I have is for a simple trigger, however, the answer to it could help me greatly with more complex endeavors...
I want to make ONE trigger that fires off of several POSSIBLE outputs from the mud...
Output:
(HEAD) (NAME) (TAIL) has entered the realm.
Examples are:
Aslyn has entered the realm.
Lord Aslyn has entered the realm.
Lord Aslyn Tarrant has entered the realm.
Lord Aslyn The Great has entered the realm.
Lord Aslyn 303 has entered the realm.
Lord Aslyn The 303 had entered the realm.
(Though the HEAD and NAME are limited to one word the TAIL could be as many words/numbers as the character entering it sees fit)
I would like to create a trigger that will take ANY text followed by:
" has entered the realm."
And then strip it all down so I am JUST picking up the second word, the (NAME), as %1.
So I could then do -
"tell %1 Welcome to the game!"
Please help, and thanks in advance...
Zero |
|
|
|
Turbomudder Beginner
Joined: 25 Jan 2003 Posts: 19
|
Posted: Sat Jan 25, 2003 2:34 am |
This is a very common and useful situation. Its solution is to insert wildcards into trigger. These can be found in the "pattern matching" section of the help files. For this particular trigger you would want...
%w (%w)*has entered the realm. as your trigger
%w as you will read in the help file, will match any one word... that should do you fine, and indeed prove extremely useful in many applications
Signed,
Turbomudder ;) |
|
|
|
Emit Magician
Joined: 24 Feb 2001 Posts: 342 Location: USA
|
Posted: Sat Jan 25, 2003 3:42 am |
#TRIGGER {(*) has entered the realm.} {
namelist = %replace(%1," ","|"}
#IF (%numitems(@namelist) > 1) {
name = %item(@namelist, 2)
}{
name = @namelist
}}
--edited to provide commentary because i was so obsessed with the color codes i forgot it the first time--
this should work regardless of how many words a person has. The only thing that won't work is the case where a person has a suffix but no prefix, i couldn't tell if that case would ever occur from your post. essentially all we do is capture all the words before "has entered..." and put them in a string list. if the list has more than 1 member, we assume that the second word is the name. if it has only one member then that is the name itself after this just throw a line in the trigger sorta like:
chat hi @name
and you should be fine.
if the error case is likely to occur, post, and i'll try to think of something else.
--------
moon.icebound.net:9000 |
|
|
|
zerosk8tr137 Newbie
Joined: 16 Jun 2001 Posts: 5 Location: USA
|
Posted: Sat Jan 25, 2003 4:44 am |
Thank you guys for the responces -
Turbomudder - I did indeed try a wildcard, and in my experience they work when you want to accept ANYTHING, but dont also work if that ANYTHING can be nothing.
IE: * (%w) * has entered...
Only works for:
Lord Aslyn Tarrant has entered...
But does not work dor:
Aslyn has entered...
EMIT - Unfortunantely the ERROR case is the MOST liekly to occur on this particular mud. So is there something we can do.... Also could you explain the exact commands and functions you are calling in that code snippet. I am not familiar with all of them and would like to expand my knowledge.
Thanks,
Zero
~shane~ |
|
|
|
zerosk8tr137 Newbie
Joined: 16 Jun 2001 Posts: 5 Location: USA
|
Posted: Sat Jan 25, 2003 5:00 am |
This keeps getting worse and worse....
Mudout put: (head) (name) (tail)
Apparently both HEAD and TAIL can be multi words or NOT be there at all.
So examples:
Aslyn has entered...
Lord Aslyn has entered...
The Great Lord Aslyn has entered...
Aslyn the Great has entered...
Lord Aslyn the Great has entered...
Any possible combination of words in HEAD or TAIL from 0-?
*sighs*
Zero
~shane~ |
|
|
|
TonDiening GURU
Joined: 26 Jul 2001 Posts: 1958 Location: Canada
|
Posted: Sat Jan 25, 2003 5:50 am |
I'd make a trigger
^(%x) has entered...
^{@Pretitles} (%x) has entered...
^{@Pretitles} (%x) {@Posttitles} has entered...
^(%x) {@Posttitles} has entered...
Then something used to collect pre/post titles:
^(*) has entered...
#ADDITEM Checkthrough {%1}
#VAR Pretitles "Lord|The Great Lord"
#VAR Posttitles "the Great"
Then I'd start tracking pre and post titles to help
parse out the real name. Depends on if the pre/post titles
are a finite fixed number or not.
Used %x as it seems to be the rage to have odd characters in names
these days.
Ton Diening |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Jan 25, 2003 6:12 am |
Given that (HEAD) can be any number of words, including none, and that (TAIL) can be any number of words including none, there's absolutely no pattern which will pick NAME out of every possible string. You'll just have to do it yourself.
There are some things you can do, such as highlight (#HIGHLIGHT, #CW, #COLOR) the entry line, save the entire head-name-tail (#VAR, #ADDITEM) string to a variable so you can pick out names at your leisure, and make noise (#BEEP, #PLAY) to get your attention. That way, you can employ your superior human judgment to pick out the name yourself.
#TR {^(*) has entered the realm} {#BEEP;#ADDITEM fullnames {%1};#PCOL {blink,bold,red} %x1}
LightBulb
Senior Member |
|
|
|
zerosk8tr137@hotmail.com Newbie
Joined: 25 Jan 2003 Posts: 2 Location: USA
|
Posted: Tue Jan 28, 2003 4:22 pm |
Thanks to everyone who has posted - I have finally determined exactly what I need to do. Now it is just a matter of doing it.
Though (HEAD) can be multiple words or none, every possible head comes from someone's rank in a clan. This being finite. I think it should be possible to create an array of all possible heads. Then when a player logs in (* has entered the realm.) set the trigger to take all of the (HEAD) (NAME) (TAIL) into another array list. I then want to make it take the captured array list and compare it to the words in the possible_head array list. If a word is present in BOTH lists it disqualifies it as being the player's name and moves on to the next...until it finds one that ISNT in the possible_head list. Then it sets that word as the characters name. And the trigger can then perform its function on the player...
So if someone could help me get there with the code that would be terrific.
Zero |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue Jan 28, 2003 7:32 pm |
Add additional #IF statements as needed to remove other titles. Use care to keep the {}'s and ()'s matched up.
#TR {^(*) has entered the realm} {#VAR name {%1};#IF %begins( {@name}, "Lord ") {#VAR name {%word( {@name}, 2)}};#IF %begins( {@name}, "The Great Lord ") {#VAR name {%word( {@name}, 4)}};#VAR name {%word( {@name}, 1)};tell @name Welcome to the game!}
LightBulb
Senior Member |
|
|
|
Emit Magician
Joined: 24 Feb 2001 Posts: 342 Location: USA
|
Posted: Tue Jan 28, 2003 11:34 pm |
Thats a good approach, but to avoid writing an #if for each command, here is something you can do:
#var headnames {The|Great|Lord|Lady}
except expand this list to include every word that could possibly appear in a head name, so it might end up like this:
#var headnames {The|Great|Lord|Lady|Duke|Duchess|etc.....}
once you have that, make the trigger that puts all words in "head name tail" into a string list, delete all occurances of any headnames, and then set the remaining first word as the name:
#tr {(*)has entered the realm.} {
fullname = %replace(%1, " ", "|")
#forall {@headnames} {#delitem @fullname %i}
name = %item(@fullname, 1)
tell @name Welcome Back @name
}
and this should only fail in the case where the persons name is one of the possible words of the headnames (this shouldn't be happening, i think).
error case:
Lord Lord has entered the realm.
The Great Lord Great has entered the realm.
--edit comment--
if this error case ever occurs, i would complain to the coders of the mode and see if they would take the bad name out as a possible name.
--------
moon.icebound.net:9000 |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Wed Jan 29, 2003 12:01 am |
Since many people face similar problems I decided I would write up the best possible script I could come up with for handling it.
#CLASS {NameExtractor}
#ALIAS addhead {#IF (%ismember( "%-1", @Titles)) {#NOOP Title already set} { #ADDITEM Titles {%-1}}}
#ALIAS removehead {#VAR TitleTemp {@Titles} {_nodef} {NameExtractor};#VAR MatchedWord {1} {_nodef} {NameExtractor};#VAR MatchCount {1} {_nodef} {NameExtractor};#WHILE (@MatchedWord) {MatchedWord=0;#FORALL @TitleTemp { #IF (%word( %i, @MatchCount)!=%word( @Name, @MatchCount)) {#DELITEM TitleTemp {%i}} {MatchedWord=1}};#IF (@MatchedWord) {#IF (@MatchCount=%numwords( @TitleTemp)) {MatchedWord=0;#ADD MatchCount 1;Name=%word( @Name, @MatchCount)};#ADD MatchCount 1}}}
#ALIAS titlehelper {#INPUT {%concat( "addhead ", %pop( UnknownTitles))}}
#VAR Titles {Lord|The Great Lord}
#VAR Name {Aslyn}
#VAR TitleTemp {The Great Peach}
#VAR MatchedWord {0}
#VAR MatchCount {5}
#VAR UnknownTitles {}
#TRIGGER {^(*) has entered the realm} {Name="%1";removehead;#IF (%numwords( @Name)>1) {#ADDITEM UnknownTitles {@Name}} {#ECHO @Name}}
#STAT {%if(@UnknownTitles,<SEND "titlehelper" 'Click to put unknown data in command box'>UnknownTitle</SEND>)}
#CLASS 0
In order to put that into zMud just copy the whole thing and paste it in the command line, then press enter.
What it does is attempt to match any title in the list @Title. As each fails it removes it so longer titles will not take forever to match. When ther is only 1 left and all of its words have been matched it considers that to be an exact match. So if you have set on of your titles to be "The" and a person has a title of "The Beast" it will erroniously match and think thier name is "Beast". The other thing it does is store a list of failures. This list cause a little item to appear on the status line, just click it to have the offending name data put in the command box with the addhead alias prepended. You can then edit it to match the correct title and hit enter. The included trigger just #ECHO's the name on success, you can replace that with anything you want. |
|
|
|
zerosk8tr137 Newbie
Joined: 16 Jun 2001 Posts: 5 Location: USA
|
Posted: Wed Jan 29, 2003 8:09 am |
Thanks again to everyone I finally got it working...
Emits idea worked out with just a few changes to it....the hardest part being to establish the list of known suffix.
I decided to post exactly what it does and how to make it work for anybody facing a similiar circumstance.
Output from MUD: (HEAD) (NAME) (TAIL) has entered the realm.
Example: Lord Aslyn Tarrant has entered the realm.
The idea is to capture the name of the player when they enter the mud in order to greet them.
Firstly you must compose a list of all possible HEAD's - and assemble them in a string array.
#var headnames {The|Great|Lord|Lady|...}
Then the trigger:
#tr {(*)has entered the realm.} {
fullname = %replace(%1, " ", "|")
#forall {@headnames} {#delitem fullname %i}
name = %item(@fullname, 1)
tell @name Welcome Back @name!
}
Explination:
Line 1 - the * takes everything before "has entered..." and sets it as %1
Line 2 - replaces all of the spaces in %1 with | and stores them to a variable. (Thus making a string array)
Line 3 - Goes through all of the names in headnames and deletes them from fullname (thereby removing ALL possible HEADs)
Line 4 - sets what is now the first item in the fullname list to the variable name
Line 5 - executes a command using the players name
TADA!
Thanks for everyone's help, especially Emit!
Zero
~shane~ |
|
|
|
|
|