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 ➜ Checking health using script

Checking health using script

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


Posted by Avocado   (13 posts)  Bio
Date Sat 09 Nov 2013 06:01 AM (UTC)
Message

On, http://www.gammon.com.au/forum/?id=6030, you explained how to create a trigger that sends a colored note when hp is low. How can I do this with an an alias script please?
Below is what I was trying, but it doesn't work.



<aliases>
  <alias
   match="chkhp"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"
wait.make(function () -- Start of Coroutine

Send ("look")

  local x = wait.match("^[%/%hp*",2)

if %1 &lt; 50 then
  Note ("Your health is low.")
else
  Note ("Your health is OK.")
end --

end) -- end of Coroutine</send>
  </alias>
</aliases>


Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 09 Nov 2013 06:21 AM (UTC)
Message
The "match" doesn't look right. It looks like a half regular expression, half normal match.

Template:regexp Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.


- Nick Gammon

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

Posted by Avocado   (13 posts)  Bio
Date Reply #2 on Sun 10 Nov 2013 12:04 AM (UTC)
Message
Thanks Nick,

I also had to look into other sites on internet for pattern matching. I included the website address on the code as remarks. Below is what I came up with. I wasn't sure if I was able to 'grab' all 6 variables at once, so I used 3 lines to 'capture' them as variables. With speed of current CPU's I doubt any slowdowns, but if anyone would like to suggest a slicker way, please do. I would like to learn.




<aliases>
  <alias
   match="baf"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>-- find my hp and mana and movement points


require "wait"
wait.make (function() -- start of coroutine


Send ("look")

-- This is what we're looking for:  [100/100hp 100/100mn 100/100mv]

local x = wait.match ("[*tnl] &gt;", 2) 

Note (x)  -- This will print out what's 'captured', i.e.:  [100/100hp 100/100mn 100/100mv]

if not x then
  ColourNote ("white", "blue", "no match found")
else
  ColourNote ("white", "blue", "YES match is found")


-- Pattern matching:  http://www.lua.org/pil/20.1.html 
-- to capture hp, mana, &amp; movement pts as variables

  _, _, hp, hpT = string.find(x, "%[(%d+)/(%d+)hp %d+/%d+mn %d+/%d+mv.")
  _, _, mn, mnT = string.find(x, "%[%d+/%d+hp (%d+)/(%d+)mn %d+/%d+mv.")
  _, _, mv, mvT = string.find(x, "%[%d+/%d+hp %d+/%d+mn (%d+)/(%d+)mv.")

  Note ("hit points is:  ", hp)
  Note ("mana is:  ", mn)  
  Note ("movement is:  ", mv)

end -- if

end) -- of Coroutine</send>
  </alias>
</aliases>
Top

Posted by Avocado   (13 posts)  Bio
Date Reply #3 on Sun 10 Nov 2013 12:10 AM (UTC)
Message
darn it...

that one line looks wrong...


local x = wait.match ("[*mv]", 2) 


in parenthesis, there should be five characters.:

quotes
open bracket
asterisk
mv (two lower case letters m v)
close bracket.
comma
space
2 (number two)


Top

Posted by Avocado   (13 posts)  Bio
Date Reply #4 on Sun 10 Nov 2013 12:13 AM (UTC)
Message
i meant 8 characters. Sorry, can't count.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Sun 10 Nov 2013 06:34 AM (UTC)
Message
Maybe show the actual MUD output rather than trying to describe it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


22,442 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.