Help - Search - Members - Calendar
Full Version: Mushclient Timestamp
Achaea's Forums > Off-Topic > Tech Support > Curing Systems and Scripts
Trevize
I have a lot of people ask for a millisecond MUSHclient timestamp. Well, since Lua normally only has down to seconds, I haven't made one before, but when someone asked earlier, I finally decided to figure out some way to do it.

Here it is! If you have your own prompt trigger, you'll want to integrate this with it instead of just adding it, if not just add it in.

Trigger:
CODE
<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^\d+h(, \d+m)?(, \d+e)?(, \d+w)? [@cexkdb]*(?: Vote)?-"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="25"
  >
  <send>prompt.data = TriggerStyleRuns
prompt.time = GetLineInfo (GetLinesInBufferCount(), 9)
prompt.time = os.date ("%%I:%%M:%%S", prompt.time)
prompt.ms = GetLineInfo (GetLinesInBufferCount(), 12)
prompt.ms = math.ceil (math.fmod (prompt.ms, 1) * 1000)
prompt.draw ()</send>
  </trigger>
</triggers>


Script file:
CODE
prompt = {
  data = false,
  draw = function ()
    if prompt.data then
      for k,v in ipairs (prompt.data) do
        ColourTell (RGBColourToName (v.textcolour),
                    RGBColourToName (v.backcolour),
                    v.text)
      end -- for
    end -- if
    Note (string.format (" [%s.%03.f]", prompt.time, prompt.ms))
  end, -- func
  }
Dontarion
CODE
time_now = GetInfo (232) % 60

for _, v in ipairs(TriggerStyleRuns) do
ColourTell (RGBColourToName (v.textcolour), RGBColourToName (v.backcolour), v.text)
end

ColourTell("silver", "", os.date(" <%%H:%%M:") .. string.format ("%%0.3f>", time_now))

Note(\n)


This is something I grabbed from MUSH forums somewhere. I've added all kinds of other things to my prompt but this is much more tidy then what I used to have in my prompt with regards to prompt time.
Trevize
QUOTE (Dontarion @ Oct 6 2009, 02:37 PM) *
CODE
time_now = GetInfo (232) % 60

Hmm. That gets when the script is run, rather than when the line arrived. I suppose the difference would be very minor, but I'd much prefer when the line actually arrived.
Nitro
Having some odd things with this script. I'm using the GetLineInfo method for both seconds and milliseconds. I'm spamming a certain command and I get:

CODE
7730h, 7281m cexdb-|47:54:440|


next prompt:

CODE
7730h, 7281m cexdb-|47:55:561|


The seconds seem to switch mid second.
Dontarion
It sounds like the seconds is being rounded from milliseconds.
Irion
Mine is working fine.

Thanks Trevize!
Trevize
Nitro and Dontarion are right, the high performance counter and os.time aren't always quite in synch. Dontarion's script shows it less, since his seconds are found from the high performance counter, and hours/minutes are shown from os.time. Mine is more noticeable with the milliseconds only coming from the high performance counter. But it's there in both scripts. It also seems to vary per session, I close MUSH and re-open it and sometimes it's so close it's not noticeable, sometimes it's in the middle of the second.

I'm working on a version that will work slightly different, but will not have these problems.
Trevize
New version. Shows: prompt [time] <seconds.milliseconds since last prompt>

Sample:
CODE
5085h, 4592m, 21715e, 19089w exdb- [10:40:21] <3.666>
You begin to writhe helplessly, throwing your body off balance.
5085h, 4592m, 21715e, 19101w edb- [10:40:27] <6.055>
You have recovered balance on all limbs.
5085h, 4592m, 21715e, 19101w exdb- [10:40:28] <1.266>
You toss a sparkling cloud of dust over yourself and as it settles you shimmer into invisibility.
5085h, 4522m, 21715e, 19087w xdb- [10:40:30] <1.514>
You have recovered equilibrium.
5085h, 4522m, 21715e, 19093w exdb- [10:40:34] <3.622>
You project a net of light about yourself until your image becomes faded and ghostly.
5085h, 4472m, 21715e, 19083w xdb- [10:40:34] <0.479>
You have recovered equilibrium.
5085h, 4472m, 21715e, 19089w exdb- [10:40:38] <3.594>


This version lacks the problems of minutes/seconds or seconds/milliseconds being off, due to the fact the system time and high precision counter are slightly misaligned, by simply not putting them together.

Trigger:
CODE
<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^\d+h(, \d+m)?(, \d+e)?(, \d+w)? [@cexkdb]*(?: Vote)?-"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="25"
  >
  <send>prompt.data = TriggerStyleRuns
prompt.time = GetLineInfo (GetLinesInBufferCount(), 9)
prompt.lastms = prompt.ms
prompt.ms = GetLineInfo (GetLinesInBufferCount(), 12)
prompt.draw ()</send>
  </trigger>
</triggers>


Script:
CODE
prompt = {
  data = false,
  draw = function ()
    if prompt.data then
      for k,v in ipairs (prompt.data) do
        ColourTell (RGBColourToName (v.textcolour),
                    RGBColourToName (v.backcolour),
                    v.text)
      end -- for
    end -- if
    if prompt.lastms then
      Note (string.format (" [%s] <%.3f>", os.date ("%I:%M:%S", prompt.time), prompt.ms - prompt.lastms))
    else
      Note (string.format (" [%s]", os.date ("%I:%M:%S", prompt.time)))
    end -- if
  end, -- func
  }
Soludra
QUOTE
3001h, 3658m, 5776e, 7080w ex- [07:42:34] <5.540>


So the timestamp is really a typical hours:minutes:seconds with a seconds.milliseconds delta?
Trevize
QUOTE (Soludra @ Oct 6 2009, 10:45 PM) *
QUOTE
3001h, 3658m, 5776e, 7080w ex- [07:42:34] <5.540>


So the timestamp is really a typical hours:minutes:seconds with a seconds.milliseconds delta?

Precisely. You can also easily modify it to just include one or the other, or to use ColourNote to display it in a specific color.
Irion
If the problem is that the two clocks are out of sync, then couldn't you figure out the factor that the milliseconds are off by? So like set up a loop that samples some initial second value, and then keeps sampling both the milliseconds and seconds until the seconds change and then record that millisecond value. Just subtract this from the timer, and in the event that this is a negative number just subtract from 1.

Unless this isn't the problem.
Trevize
QUOTE (Irion @ Oct 6 2009, 11:00 PM) *
If the problem is that the two clocks are out of sync, then couldn't you figure out the factor that the milliseconds are off by? So like set up a loop that samples some initial second value, and then keeps sampling both the milliseconds and seconds until the seconds change and then record that millisecond value. Just subtract this from the timer, and in the event that this is a negative number just subtract from 1.

Unless this isn't the problem.

I was just talking to Soludra, and that is one solution.

QUOTE
You tell Vida Sophiste Soludra Ar'thela, the Solar Mapmaker, "External libraries are one option. But too much work for someone who is casually using MUSH. Option two is find the difference, it'd just take one second, as soon as it changes the second over, take the millisecond to three decimals and set it as a var, figure it up from there."
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.