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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Is there a way to make a timer count up?
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 page
Posted by
| BellisColdwine
(3 posts) 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 | Top |
|
Posted by
| Fiendish
USA (2,534 posts) 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
| |
Posted by
| BellisColdwine
(3 posts) 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, | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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 | Top |
|
Posted by
| BellisColdwine
(3 posts) 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.) | 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.
16,408 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top