[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Is there a way to make a timer count up?
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Is there a way to make a timer count up?

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


Posted by BellisColdwine   (3 posts)  [Biography] bio
Date Sat 15 Jul 2017 03:39 AM (UTC)
Message
Sorry for the rookie question, but I was trying to make some triggers that would "learn" the duration of some buffs. I can't figure out how to make a timer count up though.

My desired outcome:
cast stoneskin
"Your skin toughens" <-- trigger fires on this text, enabling a timer that counts up
"Your skin softens" <-- 2nd trigger fires on this text, stopping the timer, and ideally writing that value to a variable.

(Then I'd like use that variable as the duration of a regular timer that counts down and warns me when the spell is about to wear off in the future, but one step at a time.)

Is this possible? TIA
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sat 15 Jul 2017 01:48 PM (UTC)

Amended on Sat 15 Jul 2017 01:54 PM (UTC) by Fiendish

Message
I probably wouldn't use a timer for that. I'd store the current time when you detect the first message, and then subtract it from the current time when you get the second message.

See:
https://www.mushclient.com/scripts/doc.php?lua=os.difftime and https://www.mushclient.com/scripts/doc.php?lua=os.time
or
https://www.mushclient.com/scripts/doc.php?lua=utils.timer


If you really want to use timers, then set the timer duration to be excessively high (like 1000000s) and then use GetTimerInfo to find the elapsed time by subtracting from that known value.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by BellisColdwine   (3 posts)  [Biography] bio
Date Reply #2 on Sat 15 Jul 2017 11:59 PM (UTC)

Amended on Sun 16 Jul 2017 12:02 AM (UTC) by BellisColdwine

Message
Ah, makes good sense. Thank you.

Here's what I've got:

<aliases>
  <alias
   match="TestScriptOn"
   send_to="12"
   sequence="100"
  >
  <send>EnableTriggerGroup ("LearnMode", true")</send>
  </alias>

  <alias
   match="TestScriptOff"
   send_to="12"
   sequence="100"
  >
  <send>EnableTriggerGroup ("LearnMode", false")</send>
  </alias>
</aliases>

<triggers>
  <trigger
   enabled="y"
   group="LearnMode"
   match="*Your skin toughens.*"
   send_to="12"
   sequence="100"
   variable="StoneStart"
  >
  <send>SetVariable(StoneStart, utils.timer ())</send>
  </trigger>
  <trigger
   enabled="y"
   group="LearnMode"
   match="*Your skin softens*"
   send_to="12"
   sequence="100"
   variable="StoneEnd"
  >
  <send>SetVariable(StoneEnd, utils.timer ())</send>
  </trigger>
</triggers>

That all seems to be fine. Next I want to calculate the duration:

<aliases>
  <alias
   match="LearnDuration"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>/SetVariable("StoneDuration", tostring(tonumber(GetVariable("StoneEnd")) - GetVariable("StoneStart")))</send>
  </alias>
</aliases>

(Is there a better way to do that arithmetic? That seems awkward.)

Finally, I want to throw that into a Miniwindow as a cooldown button or bar or something. I'm still reading up on how to do that, but any advice on that would be appreciated!

Thanks,
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 16 Jul 2017 03:10 AM (UTC)
Message
For short-term calculations Lua variables are simpler than client variables, particularly as they can be various types.

eg.

Start of event:


StoneStart = utils.timer ()


End of event:


StoneEnd = utils.timer ()


Duration:


StoneDuration = StoneEnd - StoneStart

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by BellisColdwine   (3 posts)  [Biography] bio
Date Reply #4 on Tue 18 Jul 2017 01:35 AM (UTC)

Amended on Tue 18 Jul 2017 01:38 AM (UTC) by BellisColdwine

Message
Alright, so I have a rudimentary version working.

As above, I get a timestamp when the effect starts, then again when it stops. I am tracking 8 buffs this way, so I combined the math all into one alias:


<aliases>
  <alias
   match="LearnDuration"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("D1", math.floor(tonumber(GetVariable("1End")) - GetVariable("1Start")))
SetVariable("D2", math.floor(tonumber(GetVariable("2End")) - GetVariable("2Start")))
SetVariable("D3", math.floor(tonumber(GetVariable("3End")) - GetVariable("3Start")))
...etc
Note ("Calculated durations!")</send>
  </alias>
</aliases>


I have a trigger set up for a string of text received on login that creates the BuffBar miniwindow:


<triggers>
  <trigger
   enabled="y"
   match="Welcome to some stuff*"
   send_to="12"
   sequence="100"
  >
  <send>require "InfoBox"

BB = InfoBox:New("Buffs")
</send>
  </trigger>
</triggers>


And then a trigger for the buff activation that adds the bar:


<triggers>
  <trigger
   enabled="y"
   match="*Your skin toughens*"
   send_to="12"
   sequence="110"
  >
  <send>Duration = (GetVariable("SSDuration") * GetVariable("Extend"))
DMax = Duration
BBHA = BB:AddBar("Stoneskin: ", 100)

require "wait"

wait.make (function ()

 for i = Duration, 2, -2 do
  Duration = (Duration - 2)
  BBHA.value = (Duration/DMax*100)
  BB:Update()
  wait.time(2)
 end

 BB:RemoveBar(1)
end)</send>
  </trigger>
</triggers>

("Extend" is another tracked buff that increases buff duration by 50%. The value of the variable is 1 when not present and 1.5 when it is.)

This mostly works fine. There is a bit of lag somewhere in this that sometimes results in the buff wearing off before the bar thinks it should -- It was very noticible with a 1s wait time, but 2s gets it right 95% of the time.

So now my question is how to scale this up to all 8 buffs? I assume the lag is going to get worse when multiple scripts are waiting and firing at once, and does the index of existing bars change when one is removed? If so, do I just need to create all 8 on login and have them stick around all the time?

(Again, sorry for the newbie-ness of this. I'm not a scripter at heart so I'm mostly stumbling around to find something that works.)
[Go to top] 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.


1,199 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]