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
➜ Match line IF other line is NOT there
Match line IF other line is NOT there
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Blixel
(80 posts) Bio
|
Date
| Sat 12 Aug 2017 07:31 AM (UTC) |
Message
| I have a regular expression that is working how I want it to work. The regular expression looks to see if there is a corpse in the room, and if there is, I can "search corpse" to find treasure. The regular expression is as follows:
^There is a (.*)corpse(.*?)|(.*?)corpse here.|(.*?)a corpse,(.*?)$
However, if there are mobs in the room, I don't want to take the time to search the corpses until after the mobs are dead. This is just due to how the timing in the game works. If I'm searching corpses while other mobs are in the room, they can attack me. So it doesn't make sense to search them until the room is clear.
Here is a text sample for when I should NOT be taking the time to search corpses.
[]
[]M
[] ^
[] x
[]$
[] ^
M - troll, gnoll
There is a longsword and a corpse here.
Because that "M - " line exists, I should NOT search corpses. But after the troll and gnoll are dead...
[]
[]
[] ^
[] x
[]$
[] ^
There is a longsword, a corpse, and a corpse here.
It is now ok to search corpses because that "M - " line no longer exists.
I'm not sure how to modify the regular expression so that it will:
IF ("M - " does not exist) AND (corpses are in the room) THEN
Send ("search corpse")
ELSE
keep fighting
| Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 12 Aug 2017 09:33 PM (UTC) |
Message
| What you need here, I think, is a separate trigger that detects the mobs in the room. It can disable the "corpse" trigger if found. Thus the corpse trigger won't match.
Of course, you need to re-enable it eventually. For example, if each room description starts with something (like [] in your example) then you enable the corpse trigger. Then the "M" line disables it. Something like that. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Blixel
(80 posts) Bio
|
Date
| Reply #2 on Sat 12 Aug 2017 11:50 PM (UTC) |
Message
|
Nick Gammon said:
What you need here, I think, is a separate trigger that detects the mobs in the room. It can disable the "corpse" trigger if found. Thus the corpse trigger won't match.
Of course, you need to re-enable it eventually. For example, if each room description starts with something (like [] in your example) then you enable the corpse trigger. Then the "M" line disables it. Something like that.
I think I understand what you are saying. I was trying to do something sort of along those lines. I created a variable called "roomCleared" which I was trying to use to determine whether or not a room had monsters in it. If that variable is true, then it is supposed to mean there are no monsters in the room. And if that was the case, then the regular expression that catches the presence of corpses was allowed to send "search corpse" to the world. However, I've never been able to make it work right.
Each new room has a little ASCII picture showing the room you are in. They are quite useful, but they do not all start with "[]". However, every room does start with a clear screen command.
Here is a screenshot showing the room code. Since it includes various ANSI characters, I don't think it would work if I copy/pasted it here as regular text: http://i.imgur.com/atP8YaB.jpg
What regular expression could I use to pick up on that "FF" bit at the beginning of each room. I believe it means form feed or something like that. In DOS EDITOR, it looks like a Chinese symbol or something: http://i.imgur.com/iDoCDad.jpg | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 13 Aug 2017 09:11 PM (UTC) |
Message
| The screen clear will be discarded by the time the text reaches the output window (MUSHclient doesn't clear the screen) but you could use the "OnPluginPacketReceived" plugin callback to detect 0xFF in an incoming packet. Here is an example:
|
To save and install the Detect_Mobs_In_Room plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as Detect_Mobs_In_Room.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Detect_Mobs_In_Room.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Detect_Mobs_In_Room"
author="Nick Gammon"
id="e640974622b699c35c9d56b0"
language="Lua"
purpose="Detects if mobs are in the room"
date_written="2017-08-14 07:56:50"
requires="5.00"
version="1.0"
>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="M - *"
send_to="9"
sequence="100"
variable="MobsInRoom"
>
<send>yes</send>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
-- initial state
SetVariable ("MobsInRoom", "no")
function OnPluginPacketReceived (s)
if string.find (s, "\f") then
SetVariable ("MobsInRoom", "no")
end -- if a screen clear
end -- OnPluginPacketReceived
]]>
</script>
</muclient>
This sets a plugin variable (MobsInRoom) to "no" initially. Then when a new room starts (a form feed) it sets it to "no" ready for that room. Then if a line starting with "M - " arrives it sets the variable to "yes".
To detect that in your other trigger, pull in the variable from the plugin like this:
if GetPluginVariable ("e640974622b699c35c9d56b0", "MobsInRoom") == "no" then
-- search corpses
end -- if
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Blixel
(80 posts) Bio
|
Date
| Reply #4 on Tue 15 Aug 2017 07:02 AM (UTC) |
Message
| Excellent! This is working great. I was running the latest 4.xx stable, so I had to upgrade to 5.x to get the script to work, but it's working beautifully.
My regular expression to match corpses is:
^There is a (.*)corpse(.*?)|(.*?)corpse here.|(.*?)a corpse,(.*?)$
That seems to match all the possible variations of text that can appear for the different wording of corpses being in the room.
And I'm using this trigger to search the corpses for treasure:
if GetPluginVariable ("e640974622b699c35c9d56b0", "MobsInRoom") == "no" then
require "wait"
wait.make (function ()
wait.time (0.5)
Send("search corpse")
Send("look")
end)
end
After searching for the corpse, it sends another "look" command to the game because if there are multiple corpses in the room, only the 1 corpse will be searched if we don't re-look.
This does make the output a bit spammy ... so I need to work on a routine that can count the corpses in the room, and then send the "search corpse" command multiple times without having to re-look in between.
Here's an example of the output as it is now once the last mob has been killed:
>look
You are standing in the middle of an east-west path. The walls are blank,
damp stone and the ground is bare. Handholds are cut in the cliff here.
............
............
............
-----dn-----
x $
[][][][][][]
There is a pearl, a corpse, and a corpse here.
>search corpse
You are standing in the middle of an east-west path. The walls are blank,
damp stone and the ground is bare. Handholds are cut in the cliff here.
............
............
............
-----dn-----
x $
[][][][][][]
A quartz falls to the ground.
You find 27 gold pieces.
The corpse collapses into dust.
>look
You are standing in the middle of an east-west path. The walls are blank,
damp stone and the ground is bare. Handholds are cut in the cliff here.
............
............
............
-----dn-----
x $
[][][][][][]
There is a pearl, a corpse, and a quartz here.
>search corpse
You are standing in the middle of an east-west path. The walls are blank,
damp stone and the ground is bare. Handholds are cut in the cliff here.
............
............
............
-----dn-----
x $
[][][][][][]
>look
A stone falls to the ground.
The corpse collapses into dust.
You are standing in the middle of an east-west path. The walls are blank,
damp stone and the ground is bare. Handholds are cut in the cliff here.
............
............
............
-----dn-----
x $
[][][][][][]
There is a pearl, a quartz, and a stone here.
>
All that "look"'ing makes the screen scroll quite a bit. But it works and that's the most important thing. Thanks again! | 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.
15,141 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top