Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Lua
➜ Auto Rescue(sort of)
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| ReallyCurious
USA (50 posts) Bio
|
Date
| Tue 10 Apr 2007 02:43 AM (UTC) |
Message
| I'm trying to create an autorescue throughout multiple worlds that can be toggled on/off through any world.
I think I could do this with just a handful of variables/triggs/aliases but I'm having a hard time.
I'm stuck on something like this right now.
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="(?U)^(?!You)(.*), fighting (?!you)(@to_rescue).$"
regexp="y"
send_to="12"
sequence="100"
>
<send>Send ("rescue %2")</send>
</trigger>
</triggers>
The small spider is standing here, fighting Warrior.
rescue Warrior
Warrior the Male Human is standing here, fighting the small spider.
This is fine for auto rescuing 1 person. But if I want an auto rescue list with dozens of names I can't seem to do that with a variable.
If I change the variable 'to_rescue' to Warrior|Druid|Cleric for example, the trigger doesn't work.
Any ideas? | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #1 on Tue 10 Apr 2007 03:35 AM (UTC) Amended on Tue 10 Apr 2007 03:37 AM (UTC) by Shaun Biggs
|
Message
| match="^(?!You)(.*), fighting (Warrior|Druid|Cleric).$"
Should work... Don't see why it wouldn't capture the variable at all.
Odd question though. Why would you put anything before a "^" in a regex pattern? The carat forces the pattern to match only if it's at the start of a line, and adding anything in front kind of defeats the purpose. Unless (?U) does something I am not familiar with (which is entirely possible).
|
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #2 on Tue 10 Apr 2007 04:02 AM (UTC) |
Message
| ok, after a little bit of brainstorming...
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^(?!You)(.*), fighting (\w+).$"
regexp="y"
send_to="12"
sequence="100"
>
<send>resc = {"Warrior", "Druid", "Cleric"}
for i,v in pairs(resc) do
if v = "%2" then
Send ("rescue "..v)</send>
end -- match player
end -- search values
</trigger>
</triggers>
This way you can capture pretty much anything and only rescue whoever is in your list. An added benefit is that you can define the resc variable somewhere else, and just have an alias set up to add names with table.insert( resc, "foo" ) and another to remove them, scanning for indexes and using table.remove( resc, index ). Then just have the value save state, and you can dynamically adjust them without having to muck about with your triggers each time. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #3 on Tue 10 Apr 2007 04:27 AM (UTC) Amended on Tue 10 Apr 2007 04:30 AM (UTC) by Nick Gammon
|
Message
|
Quote:
Unless (?U) does something I am not familiar with (which is entirely possible).
It seems that (?U) turns on the "ungreedy" option for subsequent matches, and putting that at the start of the regexp makes sense. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #4 on Tue 10 Apr 2007 04:29 AM (UTC) |
Message
|
Quote:
If I change the variable 'to_rescue' to Warrior|Druid|Cleric for example, the trigger doesn't work.
Inside the help for editing a trigger is this note:
If you want to use variables inside regular expressions and not have special characters "fixed" by putting backslashes inside them, use the syntax:
@!variable
Thus you want:
match="(?U)^(?!You)(.*), fighting (?!you)(@!to_rescue).$"
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #5 on Tue 10 Apr 2007 04:40 AM (UTC) |
Message
| I thought the triggers weren't greedy to begin with. Either way, that's a neat trick that I'll have to try and remember.
|
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| ReallyCurious
USA (50 posts) Bio
|
Date
| Reply #6 on Tue 10 Apr 2007 06:18 AM (UTC) |
Message
| I put resc table in the default script.lau(nothing else is there anyway). So, for every char I want to have on the rescue list I can do it easily. So the send on the trigger is this:
for i,v in pairs(resc) do
if v == "%2" then
Send ("rescue "..v)
end
end
Can you explain what this is doing? As if I were a small child. :)
I think what I'm going to do from here is put this trigger and the multiple ones I need to make like it in each world I want to have a "rescuer_type" class and make an alias to toggle 'enable_trigger' on/off from a main window.
Thanks again.
p.s. About (?U). Yeaaa I didn't know what it meant when I saw it explained in this link: http://www.gammon.com.au/forum/bbshowpost.php?id=84 and I still don't. What is a greedy match? :) I just saw Nick used it in the example, sooo! | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #7 on Tue 10 Apr 2007 08:34 AM (UTC) |
Message
| |
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #8 on Tue 10 Apr 2007 08:38 AM (UTC) |
Message
|
for i,v in pairs(resc) do
if v == "%2" then
Send ("rescue "..v)
end
end
Quote:
Can you explain what this is doing? As if I were a small child. :)
This is iterating through the table "resc". As it is a numerically keyed table I would have used ipairs instead of pairs, but the result will be the same in this case.
For each table item (ie. each time through the 'for' loop) we get two things: the key of the table (i) and the table value (v).
In his example, the keys would simply be 1, 2, 3 so we don't use them further. The values will be "Warrior", "Druid", "Cleric" (one at a time).
So, he is checking if we get a match on the wildcard against one of those 3 words. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| ReallyCurious
USA (50 posts) Bio
|
Date
| Reply #9 on Tue 10 Apr 2007 03:30 PM (UTC) |
Message
| thanks.
it's very useful. I was trying to get this exact same outcome when I first started this but I was trying to use a variable instead of a table. Using a table with loop is much easier. | Top |
|
Posted by
| ReallyCurious
USA (50 posts) Bio
|
Date
| Reply #10 on Tue 10 Apr 2007 03:58 PM (UTC) Amended on Tue 10 Apr 2007 04:54 PM (UTC) by ReallyCurious
|
Message
| How do I disable/enable triggers by group?
/world.DisableTriggerGroup = ("Auto_Rescue")
This did something, not sure what. But the triggers grouped into Auto_Rescue are still enabled.
Also,
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="Auto_Rescue"
match="(?U)^(?!You)(.*) stops fighting (/w+) opponent and turns to (/w+).$"
regexp="y"
sequence="100"
>
<send>for i,v in ipairs(resc) do
if v == "%3" then
Send ("rescue" ..v)</send>
</trigger>
</triggers>
I just want to double check this. Using %3 here is correct isn't it?
Also,
Match: (?U)^(?!You)(.*) stops fighting (/w+) opponent and turns to (?P<rescueme>/w+).$
and in send:
<send>for i,v in ipairs(resc) do
if v == "rescueme" then
Send ("rescue" ..v)</send>
Can I get something like this to work with the named wildcard. | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #11 on Tue 10 Apr 2007 06:39 PM (UTC) |
Message
| Enabling and disabling triggers are done with the same trigger.
EnableTriggerGroup( "foo", true ) enables the group foo
EnableTriggerGroup( "foo", false ) disables the group foo
|
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| ReallyCurious
USA (50 posts) Bio
|
Date
| Reply #12 on Tue 10 Apr 2007 07:32 PM (UTC) |
Message
| Thanks. This works great now with aliases to toggle the group on/off using world sends. I think I'm going to work on getting a script to do an 'inventory_check' and stock up on any supplies they need when in a town. This is going to be looking at more than one string from the mud though, I haven't done anything like that yet.
| Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #13 on Tue 10 Apr 2007 09:38 PM (UTC) |
Message
|
Quote:
match="(?U)^(?!You)(.*) stops fighting (/w+) opponent and turns to (/w+).$"
I just want to double check this. Using %3 here is correct isn't it?
%3 is the third capture. If you are in doubt the best thing is to use named captures, like this:
match="(?U)^(?!You)(?P<mob>.*) stops fighting (?P<player>/w+) opponent and turns to (?P<otherplayer>/w+).$"
Now we have named the wildcards "mob", "player" and "otherplayer". Then you can refer to them in the body of the trigger like this:
if v == "%<player>" then
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| ReallyCurious
USA (50 posts) Bio
|
Date
| Reply #14 on Tue 10 Apr 2007 10:30 PM (UTC) |
Message
| Thanks.
On evaluating more than one string.
example:
You are carrying:
a big waterskin [2]
a loaf of bread
a small waterskin
a note with a brown feather
a small leather bag
a map
a long, black sword
I want to check this and make sure that 'a big waterskin [2]' is 'a big waterskin [5]', so I'd send directions to go buy the appropriate amount of skins to get to 5 if i had less or drop the necessary amount if i had more. Also, I want to check for items that might not be here, and if they aren't I'll go stock up on those too.
Any suggestions on the best way to approach something like this? | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
64,019 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top