Two things: Timestamps and health loss

Posted by Noctem on Sun 27 May 2007 07:06 PM — 45 posts, 163,148 views.

#0
I have two things that I'd like to figure out in Lua as an introduction for myself before I begin scripting and triggering. I have the new mushclient, and have a linebreak added in my mud that i was told would supposedly help this.

So the first thing I want to figure out is how to add a timestamp. I don't care if it's the actual local time, or if it is a timer that starts from 0 and counts up for the amount of time that I am online. My reasons are so that I can measure the time it takes to perform certain abilities. I have absolutely no idea how to go about this, so all I can give you is a visual of what I want:

3044h, 2708m, 2875e, 10p ex- <23:30:13>

It'd be ideal to have hours, minutes, seconds and milliseconds, but if that's not possible, then that is understandable. If we can't do that, I'd rather have minutes, seconds, milliseconds instead of hours, minutes, seconds. Any and all help with this would be much appreciated.




The second thing I'd like to achieve is to have a little stamp everytime that I get hit for either health mana or ego loss (as seen in the prompt above.. h-health m-mana e-ego) I'd like to be able to see a little temporary stamp that mentions how much I've lost. It would also be helpful to have it fire everytime I regain one of those stats. I know a little more about this as it deals with math, but the extent of my programming experience is a lot of simple java programs that anyone can do. I'd especially like to have it show all three if I lose all three at once, or two if that happens. For instance, a visual:

3044h, 2708m, 2875e, 10p ex-

2665h, 1708m, 2434e, 10p ex- < -379 -1000 -441 >

3044h, 1708m, 2434e, 10p ex- < +379 > (assuming that I sip health for a 600 plus increase, and it only records what I go up to.)


I assume that if I have passive regeneration on any of these variables that it will automatically grab it anyway.

Thanks in advance for any help that can be given.
USA #1
the timestamps can be covered with os.date() os.time() and os.difftime() http://lua-users.org/wiki/OsLibraryTutorial for details more specific than what I'm going to show.

os.date() will give a timestamp if you do not care about the time differences. os.date() is very similar to strftime in C's standard time.h library. You can place a string in as an argument to affect how the time is displayed.
> = os.date()
Sun May 27 17:12:52 2007
> =os.date( "%Hh %Mm %Ss" )
17h 13m 17s
> =os.date( "%R" )
17:13
> = os.date( "%T" )
17:13:44
> = os.date( "%Z" )
EDT

http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html explains quite a bit more. That example just showed the local time zone.

if you want to show the difference in time, os.time() will return either a table of time data, or a number in seconds. These are not always compatible.
> t = os.date('*t')
> for i,v in pairs(t) do print( i,v) end
hour    17
min     18
wday    1
day     27
month   5
year    2007
sec     59
yday    147
isdst   true
> os.difftime( t, os.time() )
stdin:1: bad argument #1 to 'difftime' (number expected, got table)
stack traceback:
        [C]: in function 'difftime'
        stdin:1: in main chunk
        [C]: ?
> t = os.time()
> = os.difftime( t, os.time() )
-8
> return  os.difftime( os.time(), t )
15
Australia Forum Administrator #2
First, let's tackle a simple timestamp (and I notice that Shaun has replied while I was making this):


<triggers>
  <trigger
   enabled="y"
   match="&lt;*/*hp */*m */*mv */*xp&gt;*"
   omit_from_output="y"
   send_to="14"
   sequence="98"
   other_text_colour="silver"
  >
  <send>
-- display original line

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

-- add timestamp
Note (os.date (" &lt;%%H:%%M:%%S&gt; "))  -- add time, wrap up line</send>
  </trigger>
</triggers>


I did this using my Smaug prompt, you will need to redo the trigger match part.

This makes my prompt line look like this:


<28/28hp 105/105m 110/110mv 1252/8748xp> <07:21:32>

Amended on Sun 27 May 2007 09:25 PM by Nick Gammon
Australia Forum Administrator #3
For millisecond precision, we need the "high performance" timer, which has a greater resolution than timers which are directly available to Lua:


<triggers>
  <trigger
   enabled="y"
   match="&lt;*/*hp */*m */*mv */*xp&gt;*"
   omit_from_output="y"
   send_to="14"
   sequence="98"
   other_text_colour="silver"
  >
  <send>-- base time for differences
start_time = start_time or GetInfo (232)

-- find now
time_now = GetInfo (232)

-- difference
time_difference = time_now - start_time

-- display original line

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

-- add timestamp
Note (string.format (" &lt;%%0.3f&gt; ", time_difference))  -- add time, wrap up line</send>
  </trigger>
</triggers>



My example prompt looked like this using that code:


<28/28hp 105/105m 110/110mv 1252/8748xp> <253.194>

<28/28hp 105/105m 110/110mv 1252/8748xp> <253.381>

<28/28hp 105/105m 110/110mv 1252/8748xp> <253.560>


Amended on Sun 27 May 2007 09:29 PM by Nick Gammon
Australia Forum Administrator #4
These triggers are matching the prompt, omitting it, and then redisplaying it using the same colours (that is the 'for' loop). Then before wrapping up the line they append the extra information you want.
Australia Forum Administrator #5
Now for things like differences in health, mana etc. This is my test example, again based on the Smaug prompt:


<triggers>
  <trigger
   enabled="y"
   match="&lt;*/*hp */*m */*mv */*xp&gt;*"
   omit_from_output="y"
   send_to="14"
   sequence="98"
   other_text_colour="silver"
  >
  <send>

-- base time for differences
start_time = start_time or GetInfo (232)

-- find now
time_now = GetInfo (232)

-- difference
time_difference = time_now - start_time

-- display original line

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

-- add timestamp
Tell (string.format (" &lt;%%0.3f&gt; ", time_difference))  -- add time

-- do health difference

health = %1  -- health is first wildcard
health_diff = nil

if old_health and health ~= old_health then
  health_diff = health - old_health
end -- health change

old_health = health

-- do mana difference

mana = %3  -- mana is third wildcard
mana_diff = nil

if old_mana and mana ~= old_mana then
  mana_diff = mana - old_mana
end -- mana change

old_mana = mana


-- display if change

if health_diff or mana_diff then
 
  Tell ("&lt; ")
  if health_diff then
    Tell (string.format ("%%+ih ", health_diff))
  end -- if

  if mana_diff then
    Tell (string.format ("%%+im ", mana_diff))
  end -- if

  Tell ("&gt; ")
  
end -- if change

-- wrap up line
Note ("")</send>
  </trigger>
</triggers>


In my test, I gain 18 health:


<1/28hp 105/105m 110/110mv 1251/8749xp>  <978.669> 
The cathedral priestess utters the word 'ciroht'.

<19/28hp 105/105m 110/110mv 1251/8749xp>  <982.608> < +18h > 


You will need to rework that a bit for your prompt, and to add other fields (like ego) you want to get differences for. Also you might get fancier and, instead of using Tell in the part that displays the difference, use ColourTell, and use green for a positive amount, and red for a negative amount.
Amended on Sun 27 May 2007 09:48 PM by Nick Gammon
Australia Forum Administrator #6
Here is an example of colouring the health difference:


  if health_diff then
    local c  -- colour to use
    if health_diff < 0 then
      c = "indianred"
    else
      c = "seagreen"
    end -- if
    ColourTell (c, "", string.format ("%%+ih ", health_diff))
  end -- if

#7
Excellent, I don't have time to implement this now, but I will at some point in the next day, and get back to you. Thanks so much for replying so quickly and efficiently, it is much appreciated.
#8
Or using that but meshing them, displaying:

2409h, 2900m, 10945e, 13510w ex-<19:10:33.042><+123h><-22m>

2400h, 2900m, 10945e, 13510w ex-<19:11:41.090><-9h>

2409h, 2922m, 10945e, 13510w ex-<19:15:7.097><+9h><+22m>

This is my code:


<trigger
   enabled="y"
   match="^(\d+)h\, (\d+)m\, (\d+)e\, (\d+)w (.*)-(.*)$"
   regexp="y"
   send_to="14"
   omit_from_output="y"
   sequence="98"
  >
    <send>
      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("&lt;%%H:%%M:") .. string.format ("%%0.3f&gt; ", time_now))
      
      health = %1
      health_diff = nil

      if old_health and health ~= old_health then
        health_diff = health - old_health
      end

      old_health = health

      mana = %2
      mana_diff = nil

      if old_mana and mana ~= old_mana then
        mana_diff = mana - old_mana
      end

      old_mana = mana

      if health_diff or mana_diff then 
        if health_diff then
          ColourTell ("silver", "", "&lt;")
          local c
          if health_diff &lt; 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+ih", health_diff))
          ColourTell ("silver", "", "&gt;")
        end
        if mana_diff then
          ColourTell ("silver", "", "&lt;")
          local c
          if mana_diff &lt; 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+im", mana_diff))
          ColourTell ("silver", "", "&gt;")
        end
      end

      Note ("")
    </send>
  </trigger>


Although I have to ask is there a way to call a script routine and still use after omit? It feels yucky having to put the code in the <send> brackets.
Australia Forum Administrator #9
You can put the thing in a script file with an appropriate function, like this:


function mytrigger (name, line, wildcards, styles)

time_now = GetInfo (232) % 60

for _, v in ipairs(styles) do
        ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)  
      end
      
-- ... and so on ....

end -- mytrigger



Note that you now use the fourth argument (styles) instead of TriggerStyleRuns.
#10
I have a question stemming from the fact that I'm a complete noob at all this. How do I take text that has been written out like in the post above the post above mine, and put it into mushclient? I either have to copy into the world window which I haven't figured out yet, or I have to find someway to either save it as an .mct, or paste it in the triggers window. None of these methods have worked, and have indeed ended with a spamming of tells to a particular person who hated me enough already <.<.
Australia Forum Administrator #11
See: http://mushclient.com/pasting
#12
woot! I feel so unnoob and noob at the same time!
#13
Well I've tried all different possibilities presented here, and it all leads to stalling mushclient and making it fail. i can't get it to work at all. I think part of it may be due to the fact that part of my prompt changes frequently. Here is my prompt:

1388h, 1868m, 1484e, 10p esSix-

Depending on which skills I use, it can be 'esix' 'eSix' 'eix'

Those are all permanent possibilities, ie, they can be a part of the prompt the whole time I'm logged in if I do a particular skill.

Regardless, this is very frustrating because I keep failing at doing this, it spazzes the client out, and sends a billion tells to everyone.

Why is triggering and scripting so goddamn difficult for me. *seethes with anger at himself*
USA #14
Have you tried using a regular expression for it?

^(\d)h, (\d)m, (\d)e, (\d)p e?s?S?i?x?\-$
#15
Hey Noc, I'm Simimi, also from Lusternia. Let me see if I can get this to work for myself and I'll see what I can do for you. It is best to use a regular expression for the prompt, this is the one I use for my prompt, along with that it does.


^(\d+)h, (\d+)m, (\d+)e, (\d+)p, (\d+)en, (\d+)w (e?l?r?x?k?d?b?p?s?S?i?)(\<\>)?\-$

The last little bit is for people with Cubixes, so dun worry about it. I'm going to play with this real quick and see what I can do because it is something I would like for my system also.

Here is some testing on it done in game... I added an ego block to the previous code. I'll try to make it into a plugin if you like, so it can be called by a script file instead of being in the trigger box itself.


Forren makes a fist and punches towards you, releasing a blast of pure elemental energy that slams into you, searing your flesh.
Your magic tome warms as it absorbs a charge.
2833h, 3106m, 3507e, 10p, 15345en, 14430w elrx-<10:08:1.308> <-639H>

107h, 3106m, 3507e, 10p, 15345en, 14422w lrx-<10:08:11.331> <+274H><+75M>

A blinding pain explodes behind your eyes, which begin to tear up with blood.
Your magic tome warms as it absorbs a charge.
2420h, 2008m, 1668e, 10p, 15345en, 14430w elrx-<10:12:21.431> <-869H><-1098M><-1072E>


Let me see if I can figure out what Nick said about calling the script function from the script.

Well I get an error when I put this information into a script file about syntax with the use of the '%'.


function mytrigger (name, line, wildcards, styles)

time_now = GetInfo (232) % 60
      
      for _, v in ipairs(styles) do
        ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)  
      end

      ColourTell("silver", "", os.date("&lt;%%H:%%M:") .. string.format ("%%0.3f&gt; ", time_now))
      
      health = %1
      health_diff = nil

      if old_health and health ~= old_health then
        health_diff = health - old_health
      end

      old_health = health

      mana = %2
      mana_diff = nil

      if old_mana and mana ~= old_mana then
        mana_diff = mana - old_mana
      end

      old_mana = mana

      ego = %3
      ego_diff = nil

      if old_ego and ego ~= old_ego then
        ego_diff = ego - old_ego
      end

      old_ego = ego

      if health_diff or mana_diff or ego_diff then 
        if health_diff then
          ColourTell ("silver", "", "&lt;")
          local c
          if health_diff &lt; 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iH", health_diff))
          ColourTell ("silver", "", "&gt;")
        end
        if mana_diff then
          ColourTell ("silver", "", "&lt;")
          local c
          if mana_diff &lt; 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iM", mana_diff))
          ColourTell ("silver", "", "&gt;")
        end
        if ego_diff then
          ColourTell ("silver", "", "&lt;")
          local c
          if ego_diff &lt; 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iE", ego_diff))
          ColourTell ("silver", "", "&gt;")
        end
      end

      Note ("")
end


This causes an error on line 13 that reads;
[string "Script file"]:13: unexpected symbol near '%'


So the trigger can not make a call to the function.
Amended on Tue 21 Aug 2007 02:42 AM by Simimi
Australia Forum Administrator #16
You are mixing a couple of techniques here. If you do "send to script" then %1 is wildcard 1, straight from the current trigger invocation.

However if you call a function in a script file, which is precompiled, you don't use %1 but use wildcards [1] instead. Ditto for %2 and so on.
#17
Well, now it gives different errors related to the same problem, my mixing of styles (I had no idea you could use [1] in a script for a wildcard... idea nevr occured to me to use wild cards in my script! Saves me a lot of time that one does!)


[string "Script file"]:13: unexpected symbol near '['
13:    health = [1]

If I remove the equals I get an error on 14, such that;

[string "Script file"]:14: '=' expected near 'health_diff'
13: health [1]
14:      health_diff = nil


Hrm... As I change things the errors kind of cascade down in that manner, must be a lot that needs rewriting, or I am just not understanding something about this syntax issue.
USA #18
It should be
health = wildcards[1]

That's what the wildcards argument to the mytrigger function is doing. It's creating a table with the wildcards in it.
#19
Then, after changing that line, the error goes to line 44, which reads:

 if health_diff &lt; 0 then
with the error;

[string "Script file"]:44: 'then' expected near '&'
USA #20
if this is within the script file, the '&lt;' should be a '<'. When copying the trigger, MUSHclient converts it into xml, requiring '<' and '>' to become '&lt;' and '&gt;' respectively. You will need to fix this for all your comparisons, as well as in your ColourTell calls.
Australia Forum Administrator #21
Use MUSHclient's internal notepad, Convert menu -> Unconvert HTML Special.

However you shouldn't have the &lt; stuff in your script if you copied it from within the "send" box of the trigger. But, if you have copied the trigger to the clipboard it has to convert < to &lt; > to &gt; and so on, because the symbols < and > are themselves used to indicate the start of things (like triggers).
#22
For what it's worth, here is my script to reprocess and echo the prompt in Lusternia

function prompt (name,output,wildcard)
  hp.prev = hp.cur            -- Set Previous values for
  mp.prev = mp.cur            -- Computing differences
  ep.prev = ep.cur
  pp.prev = pp.cur
  hp.cur = tonumber(wc[1])
  mp.cur = tonumber(wc[2])
  ep.cur = tonumber(wc[3])
  pp.cur = tonumber(wc[4])
  
  local defs = wc[5]
  
  aff.prone = (string.find (defs, "p") ~= nil)
  bal.bal = (string.find (defs, "x") ~= nil)
  bal.eq = (string.find (defs, "e") ~= nil)
  bal.la = (string.find (defs, "l") ~= nil)
  bal.ra = (string.find (defs, "r") ~= nil)
  
  sipqueue()
  
  -- What color to echo health/mana/ego values as, the %'s
  -- aren't exact to lusty, lusty used 33%, 66% i think
  -- instead of 25%, 75%

  if hp.cur > .70 * hp.max then   
    hp.col = "green"            
  elseif hp.cur > .25 * hp.max then
    hp.col = "gold"             
  elseif hp.cur > 0 * hp.max then
    hp.col = "red"
  else
    hp.col = "silver"
  end
  
  if mp.cur > .70 * mp.max then
    mp.col = "green"
  elseif mp.cur > .25 * mp.max then
    mp.col = "gold"
  elseif mp.cur > 0 * mp.max then
    mp.col = "red"
  else
    mp.col = "silver"
  end
  
  if ep.cur > .70 * ep.max then
    ep.col = "green"
  elseif ep.cur > .25 * ep.max then
    ep.col = "gold"
  elseif ep.cur > 0 * ep.max then
    ep.col = "red"
  else
    ep.col = "silver"
  end
  
  if pp.cur > 7 then
    pp.col = "green"
  elseif pp.cur > 2 then
    pp.col = "gold"
  elseif pp.cur > 0 then
    pp.col = "red"
  else
    pp.col = "silver"
  end
  
  hp.per = math.floor (100 * ( hp.cur / hp.max ))
  mp.per = math.floor (100 * ( mp.cur / mp.max ))
  ep.per = math.floor (100 * ( ep.cur / ep.max ))
   
  ColourTell (hp.col, color.bg, hp.cur)
  ColourTell ("silver", color.bg, "(")
  ColourTell (hp.col, color.bg, hp.per)
  ColourTell ("silver", color.bg, ")")
  ColourTell (hp.col, color.bg, "h, ")
  
  ColourTell (mp.col, color.bg, mp.cur)
  ColourTell ("silver", color.bg, "(")
  ColourTell (mp.col, color.bg, mp.per)
  ColourTell ("silver", color.bg, ")")
  ColourTell (mp.col, color.bg, "m, ")
  
  ColourTell (ep.col, color.bg, ep.cur)
  ColourTell ("silver", color.bg, "(")
  ColourTell (ep.col, color.bg, ep.per)
  ColourTell ("silver", color.bg, ")")
  ColourTell (ep.col, color.bg, "e, ")
  
  ColourTell (pp.col, color.bg, pp.cur .. "p ")
  
  ColourTell ("silver", color.bg, defs .. "-")
  
  -- Computing differences and echoing based on whether it's   
  -- gain or loss
  if hp.cur ~= hp.prev then
    hp.diff = hp.cur - hp.prev
    if hp.diff > 0 then
      ColourTell ("coral", color.bg, "[")
      ColourTell ("limegreen", color.bg, "+" .. hp.diff .. "h")
      ColourTell ("coral", color.bg, "]")
    elseif hp.diff < 0 then
      ColourTell ("coral", color.bg, "[")
      ColourTell ("red", color.bg, hp.diff .. "h")
      ColourTell ("coral", color.bg, "]")
    end
  end
  if mp.cur ~= mp.prev then
    mp.diff = mp.cur - mp.prev
    if mp.diff > 0 then
      ColourTell ("steelblue", color.bg, "[")
      ColourTell ("limegreen", color.bg, "+" .. mp.diff .. "m")
      ColourTell ("steelblue", color.bg, "]")
    elseif mp.diff < 0 then
      ColourTell ("steelblue", color.bg, "[")
      ColourTell ("red", color.bg, mp.diff .. "m")
      ColourTell ("steelblue", color.bg, "]")
    end
  end
  if ep.cur ~= ep.prev then
    ep.diff = ep.cur - ep.prev
    if ep.diff > 0 then
      ColourTell ("lightgreen", color.bg, "[")
      ColourTell ("limegreen", color.bg, "+" .. ep.diff .. "e")
      ColourTell ("lightgreen", color.bg, "]")
    elseif ep.diff < 0 then
      ColourTell ("lightgreen", color.bg, "[")
      ColourTell ("red", color.bg, ep.diff .. "e")
      ColourTell ("lightgreen", color.bg, "]")
    end
  end
  if pp.cur ~= pp.prev then
    pp.diff = pp.cur - pp.prev
    if pp.diff > 0 then
      ColourTell ("violet", color.bg, "[")
      ColourTell ("limegreen", color.bg, "+" .. pp.diff .. "p")
      ColourTell ("violet", color.bg, "]")
    elseif pp.diff < 0 then
      ColourTell ("violet", color.bg, "[")
      ColourTell ("red", color.bg, pp.diff .. "p")
      ColourTell ("violet", color.bg, "]")
    end
  end
  Note ("")
  
  -- Hp: Coral
  -- Mp: Steelblue
  -- Ep: lightgreen
  -- Pp: violet

end


Quote:
Luciden raises a palm which glows with a tiny pinpoint of light. The light turns into a sparkling
current of energy that slams into you, dissolving your flesh.
2426(64)h, 3537(97)m, 3396(106)e, 10p elrx-[-707h]
You take a drink from a beryl vial.
The potion heals and soothes you.
3058(81)h, 3537(97)m, 3396(106)e, 10p elrx-[+632h]


On my achaean system, I use a timestamp, but it's just a second counter that I use for timing things. [16.05t] etc, it goes up to 60 then resets to 0

Sorry if this doesn't help at all
Amended on Wed 22 Aug 2007 12:16 AM by Gore
#23
Wow Nick, that saves me a lot of time. Every time I come to this forum I learn something new! Thanks for the help Gore. I collect examples of other people's work so I can learn from them, so this helps me immensely!

Well after working through this, using the converter, and changing the wildcards, we get this error.



[string "Script file"]:6: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
	[C]: in function 'ipairs'
	[string "Script file"]:6: in function 'mytrigger'
	[string "Trigger: "]:1: in main chunk




function mytrigger (name, line, wildcards, styles)

time_now = GetInfo (232) % 60

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

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

      health = wildcards[1]
      health_diff = nil

      if old_health and health ~= old_health then
        health_diff = health - old_health
      end

      old_health = health

      mana = wildcards[2]
      mana_diff = nil

      if old_mana and mana ~= old_mana then
        mana_diff = mana - old_mana
      end

      old_mana = mana

      ego = wildcards[3]
      ego_diff = nil

      if old_ego and ego ~= old_ego then
        ego_diff = ego - old_ego
      end

      old_ego = ego

      if health_diff or mana_diff or ego_diff then
        if health_diff then
          ColourTell ("silver", "", "<")
          local c
          if health_diff < 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iH", health_diff))
          ColourTell ("silver", "", ">")
        end
        if mana_diff then
          ColourTell ("silver", "", "<")
          local c
          if mana_diff < 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iM", mana_diff))
          ColourTell ("silver", "", ">")
        end
        if ego_diff then
          ColourTell ("silver", "", "<")
          local c
          if ego_diff < 0 then
            c = "salmon"
          else
            c = "lightgreen"
          end
          ColourTell (c, "", string.format ("%%+iE", ego_diff))
          ColourTell ("silver", "", ">")
        end
      end

      Note ("")
end


Appears the trigger is an issue, and all it is doing is calling the function "mytrigger"
Australia Forum Administrator #24
All it is doing? Can you paste the trigger please? See http://mushclient.com/copying
#25
I'm pretty sure this is the same as it was for the other thread. I am mixing the systems. I've never seen a trigger not call a function from a script file before...

<triggers>
<trigger
enabled="y"
match="^(\d+)h, (\d+)m, (\d+)e, (\d+)p, (\d+)en, (\d+)w (e?l?r?x?k?d?b?p?s?S?i?)(\&lt;\&gt;)?\-$"
regexp="y"
script="mytrigger"
sequence="100"
>
</trigger>
</triggers>

my output like that is:

3289h, 3106m, 2923e, 10p, 15345en, 14430w elrx-<%H:%M:%0.3f>

Amended on Wed 22 Aug 2007 07:37 AM by Simimi
USA #26
The lines like the following should only have the %% for % within a trigger's 'send to' function. There is no parser stripping them out from the script file.
ColourTell("silver", "", os.date("<%H:%M:") .. string.format ("%0.3f> ", time_now))
#27
Got it working, and here is the plugin!
http://forums.lusternia.com/index.php?act=attach&type=post&id=1518

Under Authors it states "Simimi/NickGammon/ShaunBiggs" I hope that is right and proper with the two of you?

I plan on setting up a website for these plugins at some point in the near future. Thanks so much for your help, it is very much greatly appreciated!
#28
Is there a way to possibly set this up in VBscript? I would just need the Time with the milliseconds if possible.
#29
if you use the plugin you can run it as is in Lua, while your system is in VBscript without a problem.
Australia Forum Administrator #30
Quote:

Under Authors it states "Simimi/NickGammon/ShaunBiggs" I hope that is right and proper with the two of you?


That is fine with me. :)
#31
So happy to hear it! Thanks for all of the help, it is greatly appreciated by the... looks like 5 people now using this plugin!
USA #32
Quote:
Under Authors it states "Simimi/NickGammon/ShaunBiggs" I hope that is right and proper with the two of you?

Hey, I'm up for claiming even partial credit for anything that works :p
USA #33
Quote:
Is there a way to possibly set this up in VBscript? I would just need the Time with the milliseconds if possible.


Stolen from aspalliance.com:
Quote:
To time to millisecond accuracy you need to use a little known VBScript function called, of all things, Timer(). The Timer() function returns the number of milliseconds between 00:00 (12:00 AM Midnight) and the time it's called.


  Dim dblTimer
  
  dblTimer = Timer()
  
  For i=0 to 100000
  Next
  
  Response.Write PrintInterval(Timer() - dblTimer)
Australia Forum Administrator #34
Paul DiLascia from Microsoft Systems Journal used to put an amusing disclaimer in his source:


// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
USA #35
Heh, good policy. On the other side of the spectrum Linus Torvalds:
Quote:
I'm basically a very lazy person who likes to get credit for things other people actually do.
#36
Hmm, I used that call and this is what I got:

Script error
World: Aetolia
Execution of line 12 column 3
Immediate execution
Type mismatch: 'PrintInterval'

What am I doing wrong?
USA #37
Gore:

That prompt script looks very....very familiar.
Possibly ever looked at, or have my or Batista's MUSHclient system??
#38
No, I asked you for help for my achaean one, it's daelok =p
#39
Using this code, I am able to get the seconds and milliseconds just fine, but they do not transfer over to minutes if that much time has passed. Also, sometimes the milliseconds expand out 6 spaces, which is annoying. Does anyone know how I can adjust this?
Example of what it looks like: <72.233719>
Example of what I want it to look like: <1:12:23>

Dim dblTimer

dblTimer = Timer()

For i=0 to 100000
Next

note "<" &(Timer() - dblTimer) & ">"
Australia Forum Administrator #40
The basic idea is to take the number and divide by 60 to give minutes, then take the integer amount (I forget the exact function name, it might be Floor or Int) and then multiply it back. To take your example:


72.233719 / 6 = 1.20389531667

Take integer amount = 1  (ie. 1 minute)

Multiply it back: 1 * 60 = 60 (ie. that minute was 60 seconds)

Subtract from original:  72.233719 - 60 = 12.233719

That is now your seconds and fractions of a second. 

There is a formatting function or you could multiply by 100 and divide back, eg.

12.233719 * 100 = 1,223.3719

Take integer amount = 1,223

Divide by 100 again:  1,223 / 100 = 12.23

That got rid of the other decimal places.


If you happen to have more than 60 minutes you can repeat the technique to get hours.
Amended on Sun 21 Oct 2007 04:30 AM by Nick Gammon
#41
I'm sorry Nick, I seem to be really bad at math, as I've tried all the setups I can and I either get a really large negative or the decimal moves way to far over. Would you mind showing me the correct way to put this into the note to show the minutes:seconds:milliseconds?
Australia Forum Administrator #42
Can you show us the code you used? Then we can see where the error crept in.
#43
This is the code I used to get this: 2.1837
which is the 2 seconds and 1837th of a second.


  note "" & (Timer() - dblTimer)

 Dim dblTimer
  
  dblTimer = Timer()
  
  For i=0 to 100000
  Next


The reason I have it with the note first is so it resets the timer after every note.
Australia Forum Administrator #44
Quote:

This is the code I used to get this: 2.1837
which is the 2 seconds and 1837th of a second.


Well not really, that is .1837 of a second, which is not 1/1837, they are different numbers.

I can't see in this code where you have tried to follow my suggestion of dividing by 60, or taking the integer and fractional value.