My mud doesn't have hp/maxhp moves/maxmoves in the prompt line so I created one

Posted by ReallyCurious on Fri 13 Apr 2007 08:56 AM — 10 posts, 40,019 views.

USA #0
In the mud I play the prompt line doesn't allow you to see your current health/max health current movement/max movement and that always bugged me. So, with about 2 hours of forum searching, examples here and there, I got this to work. Sort of...

Original prompt:
57H 122V 1596X 23C Exits:D> -- looks ugly

New prompt:
76/76H 122/122V 3727X 21C Exits:D -- much prettier

How I did it:
Into my scriptfile.lua goes:


function myprompt_line (name, line, wildcards)
  ColourNote ("white", "black", wildcards.health .. "/" .. GetVariable("maxhealth") .. 
                       "H " .. wildcards.moves .. "/" .. GetVariable("maxmoves") .. 
                                "V " .. wildcards.exp .. "X " .. wildcards.coins .. "C "
                                                  .. wildcards.other)
 end

Triggers:

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt_Line"
   keep_evaluating="y"
   match="(?P&lt;health&gt;\d+)H (?P&lt;moves&gt;\d+)V (?P&lt;exp&gt;\d+)X (?P&lt;coins&gt;\d+)C (?P&lt;other&gt;.*?)\&gt;$"
   omit_from_output="y"
   regexp="y"
   script="myprompt_line"
   send_to="12"
   sequence="100"
  >
  </trigger>
</triggers>
<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt_Line"
   match="^You have (\d+)\((\d+)\) hit and (\d+)\((\d+)\) movement points\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("maxhealth", "%2")
SetVariable("maxmoves", "%4")
ColourNote("silver", "blue", "Maximum health and movement defined")
</send>
  </trigger>
</triggers>


On my mud when you type 'score' you will get a line like: "You have 70(76) hit and 120(122) movement points." So for every time I hit score I'm defining max health/moves for myprompt_line function.

The problems:
In the 2nd trigger I posted I wanted to delay the ColourNote 2 seconds, but I couldn't figure out how to do that with DoAfter.

The bigger problem, though, is manipulating the 'new' prompt line. If I want to have the hp change color depending on the % of health left I'm not quite sure if I can do it since the prompt line is now a colournote(not coming from the mud) and I can't use triggers.
Anyway, I had fun trying to get this thing to work even if it took me almost 2 hours. :)
Amended on Fri 13 Apr 2007 09:27 PM by Nick Gammon
Australia Forum Administrator #1
I edited your post to add [code] tags to make the script more readable.

Quote:

In the 2nd trigger I posted I wanted to delay the ColourNote 2 seconds, but I couldn't figure out how to do that with DoAfter.


You want DoAfterSpecial - this lets you script something after a few seconds.

http://www.gammon.com.au/scripts/doc.php?function=DoAfterSpecial

For example:


DoAfterSpecial (2, 'ColourNote ("white", "red", "hi there")', 12)


I am making use of the fact that Lua lets you mix quotes here - the single quotes are around the entire ColourNote statement - the double quotes are part of the ColourNote.

This does the ColourNote 2 seconds later. The 12 is "send to script".

So in your case the line in your second trigger could look like this:


DoAfterSpecial (2,   -- after 2 seconds
                'ColourNote ("silver", "blue", "Maximum health and movement defined")', -- do this
                12)  -- send to script


Quote:

... if I want to have the hp change color depending on the % of health left I'm not quite sure if I can do it


That is easy. In the function myprompt_line instead of one big ColourNote do some ColourTell calls followed by Note. You know the figures, choose the colours appropriately.

To illustrate, although you need to do the calculations:


-- health

local percent_health = wildcards.health / GetVariable("maxhealth") * 100
local health_colour 

if percent_health < 10 then
  health_colour = "red"
elseif percent_health < 50 then
  health_colour = "orange"
else 
  health_colour = "black"
end -- if

ColourTell ("white", health_colour, 
            wildcards.health .. "/" .. GetVariable("maxhealth") .. "H ")

-- similar for moves and experience

Note ""   -- wrap up line



USA #2
thanks. works great now. everything does.
(except multi-line triggers with getlines)
USA #3
Another question on this:

Is it possible to change certain words which are in a named wildcard?

example:

76/76H 96/122V 1800X 58C Exits:D> - here it looks great.

but when I enter combat I get more information:

76/76H 103/122V 3170X 96C [me:Perfect] [a large fly:Awful] Exits:NS

My ColourNote is:

ColourTell ("white", health_colour,
wildcards.health .. "/" .. GetVariable("maxhealth") .. "H ")
ColourTell ("white", moves_colour,
wildcards.moves .. "/" .. GetVariable("maxmoves") .. "V ")
ColourTell ("white", "black", wildcards.exp .. "X " .. wildcards.coins .. "C "
.. wildcards.other)
Note ""

So the 'certain' words like, 'Perfect', 'Awful', etc are contained in wildcards.other.

I can't think of any way to highlight specific words contained in wildcards.others. Is it possible to do?

thanks
USA #4
Ok if this is your normal prompt, and the 2nd one is the battle prompt (I appended a '>' to the end to keep the formatting of the normal prompt, in case u missed that)

57H 122V 1596X 23C Exits:D>

57H 122V 1596X 23C [me:Perfect] [a large fly:Awful] Exits:NS>


a trigger like this SHOULD work ...

^(?P&lt;health&gt;\d+)H (?P&lt;moves&gt;\d+)V (?P&lt;exp&gt;\d+)X (?P&lt;coins&gt;\d+)C (?:\[me\:(?P&lt;selfstatus&gt;.*)\] \[(?P&lt;enemyname&gt;.*)\:(?P&lt;enemystatus&gt;.*)\]\s)?(Exits\:(?P&lt;exits&gt;.*)\&gt;)$


THEN you can do a check for "selfstatus" and "enemystatus" and compare them to whatever possible value/color combinations you want, then go from there, and if it does not match ANY in your list, then do not display them, cause it is an optional non-capturing section for the ENTIRE status output, but the status' as well as the mobname are all captured :)

Hope this is a decent push in the proper direction :)
I am not a master of RegExp, but can ALWAYS make them work, maybe not as efficiently as possible but it works :)

Laterzzz,
Onoitsu2
Amended on Mon 16 Apr 2007 12:17 PM by Onoitsu2
USA #5
ah thanks

?: captures both instances. I tested with prints.

I'm having a hard time getting it to do what I want though. Probably because I'm not using the proper syntax.

I -think- what I can do now is put all possible values for selfstatus into a variable and then check to see if that variable matches the selfstatus wildcard or it's nil. If it's nil then use 1 set of colortells if not then use the other.

Australia Forum Administrator #6
To illustrate with a slightly simpler example (one that doesn't have the named wildcards), this will match your case:


^(\d+)H (\d+)V (\d+)X (\d+)C (\[me:(.*?)\] ){0,1}(\[(.*?):(.*?)\] ){0,1}Exits:(.*)>


What we do here to optionally capture something like:


[me:Perfect]


... is to put the whole thing into an optional group, like this:


(\[me:(.*?)\] ){0,1}


The {0,1} at the end (or you could just put a ?) says the entire thing between the round brackets is optional.
Amended on Tue 17 Apr 2007 09:02 PM by Nick Gammon
USA #7
I've learned quite a bit of regexp by doing this prompt line.

Question: Is it possible to capture the colors of a string?

example:

57H 122V 1596X 23C [me:Perfect] [a large fly:Fair] Exits:NS>

57H 122V 1596X 23C [me:Perfect] [a large fly:Fair] Exits:NS>

Both strings identical but depending on the % of health left on 'a large fly' Fair can be 2 different colors.

And a follow-up to that question is: Can I incorporate that into my prompt line script. Although, I'm sure that if it's possible to capture color it's manageable one way or another.

Thx
Australia Forum Administrator #8
My initial response is to see:

http://mushclient.com/faq -- point 33.
Australia Forum Administrator #9
See this post for a more detailed description of how to find a particular colour in a line:

http://www.gammon.com.au/forum/?id=7818