Trying to make a tick timer

Posted by Ashass on Wed 02 Jul 2008 07:09 PM — 6 posts, 25,748 views.

#0
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
Australia Forum Administrator #1
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
#2
Alright, I understand the code bit, and thanks for that, but I can't get the pattern to match now
Australia Forum Administrator #3
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



#4
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 =)
Amended on Fri 04 Jul 2008 01:55 AM by Ashass
Australia Forum Administrator #5
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.