Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ If/then/else and string.find?

If/then/else and string.find?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by CrazyPaladin   (12 posts)  Bio
Date Thu 17 Jan 2013 03:51 PM (UTC)
Message
Setup:
1A. My character can find hidden mobs
2A. My character "marks" mobs for the tank to hit
3A. If no mobs of the target level are in the room, I tell the group to move on to the next area

What I want:
1B. To parse all of the mobs in the room
2B. Search for 5 specific short descriptions
3B. If the first is present, do "mark <mobname>", and end the searching so the Tank can attack them mob he'll se as marked
4B. If the first is not present, search for the 2nd, etc.
5B. If none are present, do "grouptell None here.", and end

My Questions:
1C. How do I set that up in an if/then/elseif?
2C. Do I use string.find or string.match to look for part of the short desc?

I could set it up with simple triggers, but if I try to use the mob's short desc to match a trigger, then if multiples are present, all of those triggers fire, marking multiple mobs instead of just 1.

Any help, and any pointing to appropriate examples would be greatly appreciated.
Top

Posted by Chyort   USA  (58 posts)  Bio
Date Reply #1 on Fri 18 Jan 2013 04:35 AM (UTC)
Message
Not the scripting answer you are after, but since you mentioned trying to get simple triggers to work...


To stop multiple triggers from firing just put them into the same group and have each of them "EnableTriggerGroup ("groupname", false)" when they fire.

This wont let you do priorities, like kill mob B before mob A if they are both in the room. But after one trigger in the group fires, the entire trigger group gets disabled and wont continue to fire for every following mob(like, mark a, mark b, mark c.)

a 2nd trigger or alias to "EnableTriggerGroup ("groupname", true)" when your ready to mark your next target and your good to go.
Top

Posted by CrazyPaladin   (12 posts)  Bio
Date Reply #2 on Fri 18 Jan 2013 05:47 PM (UTC)
Message
Good idea Chyort! I used something like that a long while back, and may have to again. It just makes each trigger so big...it feels bloated. Here's what I was wanting, in "metacode". I know what I want it to do, I just don't know the syntax to get it there.

Things in bold are what I'm looking to find the syntax on how to do them.


something that tells the script to parse the output from the MUD when I autolook going into a new room

if 'short description A' is in the parsed text then
  Send ("mark mobA")
  break
elseif  'short description B' is in the parsed text then
  Send ("mark mobB")
  break
elseif  'short description C' is in the parsed text then
  Send ("mark mobC")
  break
elseif  'short description D' is in the parsed text then
  Send ("mark mobD")
  break
elseif  'short description E' is in the parsed text then
  Send ("mark mobE")
elseif none of the short descriptions are found then
  Send ("grouptell None here")
  end
end


I just don't know the proper syntax to use. :(
Top

Posted by CrazyPaladin   (12 posts)  Bio
Date Reply #3 on Wed 23 Jan 2013 04:38 PM (UTC)
Message
Anyone? Please?
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 23 Jan 2013 08:24 PM (UTC)

Amended on Wed 23 Jan 2013 08:25 PM (UTC) by Nick Gammon

Message
Something like this:


<triggers>
  <trigger
   enabled="y"
   match="You see * here."
   send_to="12"
   sequence="100"
  >
  <send>

mobname = "%1"

specialMobs = {
  { desc = "short description A", send = "mark MobA" },
  { desc = "short description B", send = "mark MobB" },
  { desc = "short description C", send = "mark MobC" },
  { desc = "short description D", send = "mark MobD" },

-- add more here ...

  }  -- end of table

for k, v in ipairs (specialMobs) do
  if string.find (mobname, v.desc, 1, true) then
    Send (v.send)
    return
  end -- if found
end -- for each table item

Send ("grouptell None here")

</send>
  </trigger>
</triggers>


The table contains what to search for, and what to send.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by CrazyPaladin   (12 posts)  Bio
Date Reply #5 on Wed 23 Jan 2013 09:44 PM (UTC)
Message
Excellent! Thank you SO much!
Top

Posted by CrazyPaladin   (12 posts)  Bio
Date Reply #6 on Thu 24 Jan 2013 03:51 PM (UTC)

Amended on Thu 24 Jan 2013 09:23 PM (UTC) by Nick Gammon

Message
Ok, so here's what I have so far. I have 2 questions, and then will supply data to hopefully help.

Questions

  1. 1. I may be doing my wildcards incorrectly, and need some guidance there.
  2. 2. This script fires a "mark <mob>" or "gtell None here." on EACH mob in the room. Is there a way to alter it to parse the whole room and either fire on the first, and break, or do a single "gtell None here." if none are present?


Data

Auto-look when entering a room: (mobs I want in bold)

Inside A Small Cave
  The air here is dank and gloomy.  Shadows dance and play about the
walls as light filters through cracks in the roof of this small shaft
leading into the mountain.  Dripping water can constantly be heard, as
well as other, more ominous sounds from deeper within.
       
   | | 
   | | 
   |*|_
   |_  

[5 am Full Moon][17, Nov-Fall] [LoS = 5'] 

[Exits: north south]
(M) (weak) A small mouse is here, squeaking at you.
(M) (wimpy) A water bug skitters over a small puddle.
(Hidden) (F) (even) A goblin slinks in a corner, with a knife already drawn.
(M) (weak) A small mouse is here, squeaking at you.
(Hidden) (M) (challenge) A large shadow looms over you.
(Glowing Aura) (F) (hard) A rock troll towers over the room.


And my script, based on what Nick graciously gave me.

<triggers>
  <trigger
   enabled="y"
   match="(^|>)(.+)\((even|challenge|hard|insane)\) (.+)"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

mobname = "%1"

specialMobs = {
  { desc = "A goblin slinks in a corner, with a knife already drawn.", send = "mark goblin" },
  { desc = "A large shadow looms over you.", send = "mark shadow" },
  { desc = "A rock troll towers over the room.", send = "mark troll" },

-- add more here ...

  }  -- end of table

for k, v in ipairs (specialMobs) do
  if string.find (mobname, v.desc, 1, true) then
    Send (v.send)
    return
  end -- if found
end -- for each table item

Send ("gtell None here")
print "%1"
print "%2"
print "%3"
print "%4"
print "%5"


Question #1

  • The "print"s are so I could see what my wildcards actually were...didn't know another way.
  • The following is what the room shows when using this script when printing the wildcards. Don't understand why %4 is the one I need
  • mobname = "%4" works just fine, I just want to understand WHY its the 4th wildcard


Question #1 Data (script stuff in bold)

Inside A Small Cave
  The air here is dank and gloomy.  Shadows dance and play about the
walls as light filters through cracks in the roof of this small shaft
leading into the mountain.  Dripping water can constantly be heard, as
well as other, more ominous sounds from deeper within.
       
   | | 
   | | 
   |*|_
   |_  

[5 am Full Moon][17, Nov-Fall] [LoS = 5'] 

[Exits: north south]
(M) (weak) A small mouse is here, squeaking at you.
(M) (wimpy) A water bug skitters over a small puddle.
(Hidden) (F) (even) A goblin slinks in a corner, with a knife already drawn.gtell None here

(Hidden) (F)
even
A goblin slinks in a corner, with a knife already drawn.

(M) (weak) A small mouse is here, squeaking at you.
(Hidden) (M) (challenge) A large shadow looms over you.gtell None here

(Hidden) (M)
challenge
A large shadow looms over you.

(Glowing Aura) (F) (hard) A rock troll towers over the room.gtell None here

(Glowing Aura) (F)
hard
A rock troll towers over the room.



Question #2

  • If I expand my trigger match to "(wimpy|weak|even|challenge|hard|insane)" to match every mob possible, I then get the following.
  • I would rather have the script match once, send the matched mark, and break OR match none, send the gtell ONCE and break


Question #2 Data (script stuff in bold)

Inside A Small Cave
  The air here is dank and gloomy.  Shadows dance and play about the
walls as light filters through cracks in the roof of this small shaft
leading into the mountain.  Dripping water can constantly be heard, as
well as other, more ominous sounds from deeper within.
       
   | | 
   | | 
   |*|_
   |_  

[5 am Full Moon][17, Nov-Fall] [LoS = 5'] 

[Exits: north south]
(M) (weak) A small mouse is here, squeaking at you.gtell None here
(M) (wimpy) A water bug skitters over a small puddle.gtell None here
(Hidden) (F) (even) A goblin slinks in a corner, with a knife already drawn.mark goblin
(M) (weak) A small mouse is here, squeaking at you.gtell None here
(Hidden) (M) (challenge) A large shadow looms over you.mark shadow
(Glowing Aura) (F) (hard) A rock troll towers over the room.mark troll


Any help or pointing to the right place to read up on something is greatly appreciated!

[EDIT] Corrected forum codes

[EDIT] Changed quote tags to code tags so I can see what you are seeing. (Nick)
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #7 on Thu 24 Jan 2013 09:30 PM (UTC)
Message
I think you are matching on the wrong wildcard for a start.

You should probably name it.

eg.

Change:


   match="(^|>)(.+)\((even|challenge|hard|insane)\) (.+)"


to:



   match="(^|>)(?P<mobname>.+)\((even|challenge|hard|insane)\) (.+)"


And then change:


mobname = "%1"


to:


mobname = "%<mobname>"


Quote:

This script fires a "mark <mob>" or "gtell None here." on EACH mob in the room. Is there a way to alter it to parse the whole room and either fire on the first, and break, or do a single "gtell None here." if none are present?


This would need something extra because the trigger matches each line. You need something that indicates the end of the mobs in the room (like, the next prompt).

Your trigger could set some flag, eg.


if not foundMobs then
  mobCount = 0
  foundMobs = true
end -- if


Then add one to foundMobs if you find a match.

And then the other trigger (eg. on the prompt) could test for foundMobs and check mobCount, eg.



if foundMobs then
  if mobCount == 0 then
    Send ("gtell None here")
  end -- if none cound
  foundMobs = false
end -- if


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by CrazyPaladin   (12 posts)  Bio
Date Reply #8 on Thu 24 Jan 2013 09:38 PM (UTC)
Message
I will try to add those, thank you!!
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.


23,095 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.