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.
Entire forum
➜ MUSHclient
➜ Lua
➜ Two things: Timestamps and health loss
Two things: Timestamps and health loss
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
3
Posted by
| Noctem
(9 posts) Bio
|
Date
| Sun 27 May 2007 07:06 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #1 on Sun 27 May 2007 09:20 PM (UTC) |
Message
| 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
|
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sun 27 May 2007 09:22 PM (UTC) Amended on Sun 27 May 2007 09:25 PM (UTC) by Nick Gammon
|
Message
| First, let's tackle a simple timestamp (and I notice that Shaun has replied while I was making this):
<triggers>
<trigger
enabled="y"
match="<*/*hp */*m */*mv */*xp>*"
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 (" <%%H:%%M:%%S> ")) -- 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>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 27 May 2007 09:27 PM (UTC) Amended on Sun 27 May 2007 09:29 PM (UTC) by Nick Gammon
|
Message
| 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="<*/*hp */*m */*mv */*xp>*"
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 (" <%%0.3f> ", 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>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sun 27 May 2007 09:28 PM (UTC) |
Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sun 27 May 2007 09:43 PM (UTC) Amended on Sun 27 May 2007 09:48 PM (UTC) by Nick Gammon
|
Message
| 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="<*/*hp */*m */*mv */*xp>*"
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 (" <%%0.3f> ", 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 ("< ")
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 ("> ")
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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sun 27 May 2007 09:53 PM (UTC) |
Message
| 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
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Noctem
(9 posts) Bio
|
Date
| Reply #7 on Sun 27 May 2007 10:29 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Shienara
(4 posts) Bio
|
Date
| Reply #8 on Sat 09 Jun 2007 05:16 PM (UTC) |
Message
| 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("<%%H:%%M:") .. string.format ("%%0.3f> ", 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", "", "<")
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
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. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #9 on Sat 09 Jun 2007 09:45 PM (UTC) |
Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Noctem
(9 posts) Bio
|
Date
| Reply #10 on Sun 10 Jun 2007 01:23 AM (UTC) |
Message
| 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 <.<. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #11 on Sun 10 Jun 2007 01:46 AM (UTC) |
Message
| |
Posted by
| Noctem
(9 posts) Bio
|
Date
| Reply #12 on Sun 10 Jun 2007 01:49 AM (UTC) |
Message
| woot! I feel so unnoob and noob at the same time! | Top |
|
Posted by
| Noctem
(9 posts) Bio
|
Date
| Reply #13 on Mon 20 Aug 2007 11:31 PM (UTC) |
Message
| 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* | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #14 on Mon 20 Aug 2007 11:44 PM (UTC) |
Message
| Have you tried using a regular expression for it?
^(\d)h, (\d)m, (\d)e, (\d)p e?s?S?i?x?\-$
|
It is much easier to fight for one's ideals than to live up to them. | 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.
114,633 views.
This is page 1, subject is 3 pages long: 1 2
3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top