|
john_taylor_jr Wanderer
Joined: 17 Jan 2003 Posts: 57 Location: USA
|
Posted: Sat Dec 27, 2003 1:26 am
Find out what matched |
Ok I have a trigger like this
#CLASS {Bot}
#VAR hunt {keeper|paladin|guard}
#VAR avoid {warlock|witch|grimlin}
#TRIGGER {^(*) are here.$} {
#IF ("%1" =~ {@hunt}) {kill=1} {kill=0}
#IF ("%1" =~ {@online}) {kill=0}
#IF ("%1" =~ {@avoid}) {kill=0}
#IF ((@bot = 1) & (@kill=1)) {k @monster}
}
#CLASS 0
The @online is a list of players on the mud.
I was wondering if their were a way to find out which @hunt strings were matching
and then I could deal with setting @monster accordingly |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Dec 27, 2003 8:05 pm |
Why not just set @monster to %1 in the #IF for that list in the trigger? Unless there is overlap between the lists (which will definitely cause problems with your #IF commands), you should already know what list is matched simply by having that #IF condition evaluate to true.
|
|
|
|
john_taylor_jr Wanderer
Joined: 17 Jan 2003 Posts: 57 Location: USA
|
Posted: Sun Dec 28, 2003 2:18 am |
The %1 would be something like
Two keepers and Goblin are here. |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Mon Dec 29, 2003 6:15 pm |
You could do something like this:
#LOOP %numwords(%1) {#IF (%ismember(%word(%1,%i),@hunt)) {#say %word(%1,%i) is a match!;#var monster {%word(%1,%i)}}}
Danlo |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Dec 29, 2003 9:48 pm |
You certainely can. The syntax for using the pattern matching operator supports capturing of matches as well. A few changes and your good to go
#CLASS {Bot}
#VAR hunt {keeper|paladin|guard}
#VAR avoid {warlock|witch|grimlin}
#TRIGGER {^(*) are here.$} {
#IF ("%1" =~ "({@hunt})") {kill=1;monster="%%1"} {kill=0}
#IF ("%1" =~ {@online}) {kill=0}
#IF ("%1" =~ {@avoid}) {kill=0}
#IF ((@bot = 1) & (@kill=1)) {k @monster}
}
#CLASS 0
The red " are necessary to tell the parser that the () are part of the pattern. I believe further expansion will be preformed on the @hunt variable, if you have trouble you know where to ask. |
|
|
|
|
|