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 ➜ Trying to make a tick timer

Trying to make a tick timer

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


Posted by Ashass   (50 posts)  Bio
Date Wed 02 Jul 2008 07:09 PM (UTC)
Message
I'm trying to make a tick timer, and a lot of people have already made one for zmud, but I'm not quite sure how to go about it for mushclient. I have a fair grasp of lua, so it should be fairly easy once it gets started

Background information:

1 tick = 41 seconds
1 tick changes the game time by half an hour
Time runs on a 24 hour clock, but its listed in am/pm style

My prompt looks like this:
<442/442hp, 158/158m, 170/170mv, 21842tnl> You have 0qp. It is 10:00am.

After a half hour, it looks like this:
<442/442hp, 158/158m, 170/170mv, 21842tnl> You have 0qp. It is 10:30am.

Please note specifically the time at the end, as this is the only visible way the tick changes


I'm thinking that a trigger that basically counts to 41 that is set off when the time changes (x:00 or x:30) and sends something like Note "TICK IN 5 SECONDS!" would be sufficient
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 03 Jul 2008 02:00 AM (UTC)
Message
Something like this should do it:


<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^\&lt;(.*?)hp\, (.*?)m\, (.*?)mv\, (.*?)tnl\&gt; You have (.*?)qp\. It is (?&lt;hour&gt;\d+)\:(?&lt;minute&gt;\d+)(am|pm)\."
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

if %&lt;hour&gt; ~= old_hour or
   %&lt;minute&gt; ~= old_minute then
  old_hour = %&lt;hour&gt;
  old_minute = %&lt;minute&gt; 
  DoAfterNote (36, "TICK IN 5 SECONDS!")  -- 5 seconds warning
end -- if

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


See: http://mushclient.com/pasting for how to copy that into the client

- Nick Gammon

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

Posted by Ashass   (50 posts)  Bio
Date Reply #2 on Thu 03 Jul 2008 03:41 PM (UTC)
Message
Alright, I understand the code bit, and thanks for that, but I can't get the pattern to match now
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 03 Jul 2008 11:46 PM (UTC)
Message
It matched when I tested it on your example line. This is the basic approach I take when making triggers:


  • Copy an example line from the output window.

  • Paste into the trigger "trigger" box:


    <442/442hp, 158/158m, 170/170mv, 21842tnl> You have 0qp. It is 10:00am.


  • Replace things that might change by wildcards (asterisks):


    <*hp, *m, *mv, *tnl> You have *qp. It is *. *


  • If necessary hit "convert to regular expression" now and refine it.


That should be enough for you. In this case you count asterisks, so the time would be wildcard 6.

So you could amend the script to start the tick timer whenever wildcard 6 (%6) is different from before. Using this method, %6 would be a string (eg. "10:00am") so it needs to be quoted.

eg.


if old_time ~= "%6" then
  old_time = "%6"
  DoAfterNote (36, "TICK IN 5 SECONDS!")  -- 5 seconds warning
end -- if




- Nick Gammon

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

Posted by Ashass   (50 posts)  Bio
Date Reply #4 on Fri 04 Jul 2008 01:26 AM (UTC)

Amended on Fri 04 Jul 2008 01:55 AM (UTC) by Ashass

Message
Follow up question, how would i convert this so that the first */*hp goes into a trigger that gets the health, and divides it. -- This is what I tried to do, but failed miserably.

<triggers>
<trigger
enabled="y"
expand_variables="y"
keep_evaluating="y"
match="^\&lt;(?&lt;health1&gt;\d+)\/(&lt;?&lt;health2&gt;\d+)hp\, (.*?)m\, (.*?)mv\, (.*?)tnl\&gt; You have (.*?)qp\. It is (?&lt;hour&gt;\d+)\:(?&lt;minute&gt;\d+)(am|pm)\.(.*)?"
regexp="y"
send_to="12"
sequence="100"
variable="health"
>
<send>Note "Caught trigger"

if %&lt;hour&gt; ~= old_hour or
%&lt;minute&gt; ~= old_minute then
old_hour = %&lt;hour&gt;
old_minute = %&lt;minute&gt;
DoAfterNote (36, "TICK IN 5 SECONDS!") -- 5 seconds warning
end -- if

percent = math.floor (%&lt;health1&gt;/%&lt;health2&gt; * 100)

if(percent == 100) then
Note "You are in excellent condition."
end -- if

if(percent &lt; 100 and percent &gt;= 90) then
Note "You have a few scratches."
end -- if

if(percent &lt; 90 and percent &gt;= 75) then
Note "You have some small wounds and bruises"
end -- if

if(percent &lt; 75 and percent &gt;= 50) then
Note "You have quite a few wounds"
end -- if

if(percent &lt; 50 and percent &gt;= 30) then
Note "You have some big &amp; nasty wounds"
end -- if

if(percent &lt; 30 and percent &gt;= 15) then
Note "You are pretty hurt"
end -- if

if(percent &lt; 15 and percent &gt; 0) then
Note "You are in awful condition"
end -- if

if(percent == 0) then
Note "You are dead!"
end -- if</send>
</trigger>
</triggers>




------------------------

Well, i tested it some more, and it seems to work when i actively send commands to the game, but not when i sit quietly (regening, for example)

Is there any way to bypass this?

Also, on a side note, every time i enter a command, my prompt shows, followed by what i did.

eg:

<43/43hp, 102/102m, 106/106mv, 29127tnl> You have 0qp. It is 4:30am.
You are in excellent condition.
Ogmin clan gossips 'dae'ni come get sword'

<43/43hp, 102/102m, 106/106mv, 29127tnl> You have 0qp. It is 4:30am.
You are in excellent condition.


<43/43hp, 102/102m, 106/106mv, 29127tnl> You have 0qp. It is 5:00am.
You are in excellent condition.
Ghurt clan gossips 'We wun hurt yer.'

<43/43hp, 102/102m, 106/106mv, 29127tnl> You have 0qp. It is 5:00am.
You are in excellent condition.


<43/43hp, 102/102m, 106/106mv, 29127tnl> You have 0qp. It is 5:30am.
You are in excellent condition.
i
You are carrying:
Nothing.

<43/43hp, 102/102m, 106/106mv, 29127tnl> You have 0qp. It is 5:30am.
You are in excellent condition.


<43/43hp, 102/102m, 106/106mv, 29127tnl> You have 0qp. It is 6:00am.
You are in excellent condition.



------------------------------------

Follow up! It seems that the tick is ONLY set if there is something that continues on after my prompt (eg)

<43/43hp, 102/102m, 106/106mv, 29127tnl> You have 0qp. It is 5:30am. You see a giant squid here

-------------------------------------
Added a space to the end of my prompt (invisible extra char) and it seems to catch the trigger every time now. Although I *would* like to know how to make it so i don't need that, this works well enough for now.

And thanks a ton nick, i've been using your client for damn near 8 years now (stopped mudding for a long while, but when i started again, your client was the very first thing i went to go download it =)
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 04 Jul 2008 07:28 AM (UTC)
Message
http://mushclient.com/faq - point 11, might be relevant. It might not be firing until the line completes. If possible configure the prompt to have a newline at the end of 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.


23,319 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.