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 ➜ My mud doesn't have hp/maxhp moves/maxmoves in the prompt line so I created one

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

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


Posted by ReallyCurious   USA  (50 posts)  Bio
Date Fri 13 Apr 2007 08:56 AM (UTC)

Amended on Fri 13 Apr 2007 09:27 PM (UTC) by Nick Gammon

Message
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. :)
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 13 Apr 2007 09:39 PM (UTC)
Message
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




- Nick Gammon

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

Posted by ReallyCurious   USA  (50 posts)  Bio
Date Reply #2 on Sat 14 Apr 2007 12:29 AM (UTC)
Message
thanks. works great now. everything does.
(except multi-line triggers with getlines)
Top

Posted by ReallyCurious   USA  (50 posts)  Bio
Date Reply #3 on Mon 16 Apr 2007 10:23 AM (UTC)
Message
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
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #4 on Mon 16 Apr 2007 12:15 PM (UTC)

Amended on Mon 16 Apr 2007 12:17 PM (UTC) by Onoitsu2

Message
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
Top

Posted by ReallyCurious   USA  (50 posts)  Bio
Date Reply #5 on Tue 17 Apr 2007 09:29 AM (UTC)
Message
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.

Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 17 Apr 2007 09:01 PM (UTC)

Amended on Tue 17 Apr 2007 09:02 PM (UTC) by Nick Gammon

Message
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.

- Nick Gammon

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

Posted by ReallyCurious   USA  (50 posts)  Bio
Date Reply #7 on Wed 18 Apr 2007 11:06 AM (UTC)
Message
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
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #8 on Wed 18 Apr 2007 11:37 AM (UTC)
Message
My initial response is to see:

http://mushclient.com/faq -- point 33.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #9 on Thu 19 Apr 2007 02:14 AM (UTC)
Message
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

- 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.


28,722 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.