Checking health using script

Posted by Avocado on Sat 09 Nov 2013 06:01 AM — 6 posts, 23,495 views.

#0

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>


Australia Forum Administrator #1
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.

#2
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>
#3
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)


#4
i meant 8 characters. Sorry, can't count.
Australia Forum Administrator #5
Maybe show the actual MUD output rather than trying to describe it.