Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Mon May 30, 2011 1:31 pm   

Multiple timers in Status window
 
Hi,

Being the control freak that I am, I wanted to experiment with timers regarding my prots. My layout at the moment is that I have the status window on the left side of my mud window, with a lot of information, like most of the prots in the mud.
I also made so that the appear/disappear when prots go on/off which is really nice. Now, I would like to add a timer in the status window, beside the prots currently on.

For example, it would look like:

Prot 1 [time]
prot 2 [time]

etc

The time would increase as it does, so that I can keep track on for how long they have been up and so on. Is this possible at the moment?
I have been reading up on timers but nothing seems to be able to do what I want to do.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon May 30, 2011 3:58 pm   
 
#alarm -1 {#raise onSecond}
#event "evtProt1" {
#if (@prot1) {
prot1 = (@prot1 - 1)
} {
#t- evtProt1
}
}

Put a #T+ evtProt1 in the on trigger, and repeat the event for each prot you want.
_________________
EDIT: I didn't like my old signature
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Mon May 30, 2011 4:38 pm   
 
Hey,

Not entirely sure that I understand what this does. What does this one do #if (@prot1)? It is just a variable, so it doesn't check against anything?
Also, what variable will hold the time information that I can put in the status window?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon May 30, 2011 6:22 pm   
 
Before suggesting an approach, a bit more information would be helpful. Can you tell us if you measure the time remaining on buffs in terms of ticks or in terms of minutes and seconds? How do you know the duration of your buffs? An example of the output from the mud which displays this information would be helpful. If you measure the duration of buffs in ticks, how do you know when a tick has occurred on the mud?
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Mon May 30, 2011 6:36 pm   
 
There is no exact time for how long a buff is up, just an estimate, which is what I want. What I want is quite simple.
I cast a spell/use a skill that puts a buff on me. When the buff hits me and succeeds, I trigger it, and give myself a message saying that this buff is currently up.
From this moment, I want a timer to off and start increasing in seconds, so that I know that buff1 has been upp for 100 seconds, or 120 seconds etc.

It is not about ticks or anything like that, just a counter I guess that shows for how long a buff has been up.
At the moment, I have made it so that when no buffs are up, my status window is just black. When one buff is up, the name becomes green plus I get notified.
My plan was to have a counter beside the name that shows for how many seconds the buff has been up.

cast buff1 on me
buff1 is up
start timer

The plan is to have the status window on the left side, and then list all the current buffs there.
buff1 [24]
buff2 [105]
.
.
.
Where 24 and 105 would be the time for how long they have been up at the moment. The only information I can get from the mud is when the buff lands on me and when the buff disappears.
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon May 30, 2011 7:33 pm   
 
K, in that case I'd recommend using a trigger that will set a variable for each of the buffs you want tracked according to the current time when the buff is cast, as expressed by the %secs variable, then calculate the amount of time that has elapsed by comparing that value with the current value of %secs and display the difference comprehensively as elapsed seconds and minutes. An alarm timer to keep the values updated will make it in to an active timer. The code for that looks something like this:

Code:
<cmud>
  <class name="Timers" copy="yes">
    <trigger priority="3080" copy="yes">
      <pattern>^echo when armor buff cast$</pattern>
      <value>timers.armor = %secs</value>
    </trigger>
    <func name="buff_timer" copy="yes">
      <value>#IF !@timers.$buff {#RETURN %null}
$elapsed = (%secs - @timers.$buff)
$seconds = $elapsed / 1000 \ 60
$seconds = %concat(%repeat("0", (2 - %len($seconds))), $seconds)
$minutes = $elapsed / 60000
#RETURN %format("&amp;14s &amp;2d:&amp;2s", %proper($buff), $minutes, $seconds)</value>
      <arglist>$buff</arglist>
    </func>
    <stat showinbar="false" showinwindow="true" priority="3160" copy="yes">
      <value>@buff_timer("armor")</value>
    </stat>
    <var name="timers" type="Record" copy="yes">
      <value>armor=0</value>
      <json>{"armor":0}</json>
    </var>
    <trigger priority="3080" copy="yes">
      <pattern>^echo when armor buff falls$</pattern>
      <value>timers.armor = 0</value>
    </trigger>
    <trigger name="TimerUpdates" type="Alarm" priority="3250" copy="yes">
      <pattern>.01</pattern>
      <value>#UPDATE Timers</value>
    </trigger>
  </class>
</cmud>


Copy / paste that, then show it the line #SHOW "echo when armor buff cast" and a counter for the armor buff will show up in your status window. Show it the line #SHOW "echo when armor buff falls" and it disappears from the status window. Add more buffs with their associated echoes as needed.

edit: I used minutes and seconds because that's how I'm used to doing these things. ie, I'd get the output 0:24 and 1:45 instead of 24 and 105, respectively. If you just want seconds, change the buff_timer function to:
Code:
<func name="buff_timer" copy="yes">
      <value>#IF !@timers.$buff {#RETURN %null}
$elapsed = (%secs - @timers.$buff)
$seconds = $elapsed / 1000
#RETURN %format("&amp;14s &amp;0d", %proper($buff) $seconds)</value>
      <arglist>$buff</arglist>
    </func>
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Mon May 30, 2011 7:43 pm   
 
#IF (@var)
is the same as
#IF (!%null(@var))
_________________
Discord: Shalimarwildcat
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Mon May 30, 2011 8:55 pm   
 
Ok, just tried this out and it worked nicely. This is a lot more advanced than I am used to, hence my questions. Need to read up on this.
The time value is static though in the status window, and you talked about alarm timer to keep it updated though I do not know how to do that.

I tried reading up on alarms, but since I never really used them before I came up with nothing at all. Would be rocking to give me a kick in the right direction then I should be fine for now I guess.
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon May 30, 2011 10:21 pm   
 
There is an alarm incorporated in to that script which should be keeping the timers constantly updated. That's this bit:
Code:
    <trigger name="TimerUpdates" type="Alarm" priority="3250" copy="yes">
      <pattern>.01</pattern>
      <value>#UPDATE Timers</value>
    </trigger>

That tells Cmud to run the command #UPDATE Timers every 0.01 seconds. Cmud can't actually cause an alarm trigger to fire that quickly, but it should be firing as quickly as possible. I believe the limit is close to 0.2 or 0.5 seconds. The #UPDATE command tells Cmud to reevaluate whatever status items, like the status window, are in the designated class. So #UPDATE Timers is telling it to update the status window in the class 'Timers'.

In the script snippit I posted I made a class called 'timers' and a variable called 'timers'. I don't think that would cause conflicts with #UPDATE but I suppose it might. Try changing the name of the class and the corresponding #UPDATE line in the alarm and see if it updates properly after that.
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Tue May 31, 2011 10:44 am   
 
I tried it once more, changed the name of the class to Prots, also changed it to #UPDATE Prots. No change.
If the buff is off and I cast it on me, the status window doesn't update. I need to change something in the status window, and then save it for it to show the time. The time will then also not move at all until I change something in the status window and save it.
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Tue May 31, 2011 11:04 am   
 
Well that's curious Confused When I install and test the script, it works just fine and maintains the timer automatically, as intended. I'm really not sure why it would behave differently for you.

Try adding the line #PRINT Alarm fired! to the alarm trigger, immediately after the line #UPDATE Prots. If the alarm is running properly, you should get a series of Alarm fired! messages on your screen. If you don't see those, it isn't firing. Also try manually inputting #UPDATE Prots to the command line and hit enter a few times a few seconds apart and see if that causes the time in your status window to update, as it should. This should help us isolate exactly what the problem is.

If the alarm isn't firing, you might try copy/pasting this to your command line (where you usually type things in Cmud while mudding). It should change the alarm so that it tries to fire once a second, instead of one hundred times a second. I don't think that would cause problems, but it's worth a try.
#ALARM "TimerUpdates" 1
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Tue May 31, 2011 11:56 am   
 
I already had a status window which I thought created problems. Removed my old status window, removed the whole script, put it back in.
My new status window was created, I tried again but it didn't work.
I tried with #PRINT Alarm Fired! and it fired away like crazy so that one works. I tried to manually write #UPDATE Prots and press enter a few times but nothing changes.
I made a change in my status window and saved it, and it updated.

Looking on the triggers I have under the class Prots I have one called "TimerUpdates: .01", the pattern is ".01" and the value is "#UPDATE Prots". Is that correct?
It seems to work, just that "#UPDATE Prots" doesn't seem to work at all.
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Tue May 31, 2011 12:35 pm   
 
That all sounds correct, except that the #UPDATE line should be causing updates. Did you move or change the status bar object created by the script? It should have been created in the class 'Timers' (which you then renamed 'Prots') That's where the status bar object needs to be located for the '#UPDATE Prots' command to function properly.

If that's all as it should be, try installing this script in to a new Cmud session, with no other settings at all:
Code:
<cmud>
  <class name="Prots" copy="yes">
    <trigger priority="3080" copy="yes">
      <pattern>^echo when armor buff cast$</pattern>
      <value>timers.armor = %secs</value>
    </trigger>
    <func name="buff_timer" copy="yes">
      <value>#IF !@timers.$buff {#RETURN %null}
$elapsed = (%secs - @timers.$buff)
$seconds = $elapsed / 1000 \ 60
$seconds = %concat(%repeat("0", (2 - %len($seconds))), $seconds)
$minutes = $elapsed / 60000
#RETURN %format("&amp;14s &amp;2d:&amp;2s", %proper($buff), $minutes, $seconds)</value>
      <arglist>$buff</arglist>
    </func>
    <stat name="ProtStatusWindow" showinbar="false" showinwindow="true" priority="3160" copy="yes">
      <value>@buff_timer("armor")</value>
    </stat>
    <var name="timers" type="Record" copy="yes">
      <value>armor=0</value>
      <json>{"armor":0}</json>
    </var>
    <trigger priority="3080" copy="yes">
      <pattern>^echo when armor buff falls$</pattern>
      <value>timers.armor = 0</value>
    </trigger>
    <trigger name="TimerUpdates" type="Alarm" priority="3250" copy="yes">
      <pattern>.01</pattern>
      <value>#UPDATE ProtStatusWindow</value>
    </trigger>
  </class>
</cmud>

This is essentially the same as the script I posted previously except that it has given the status bar object the name 'ProtStatusWindow' and the alarm trigger has been changed to update that object directly with the line '#UPDATE ProtStatusWindow' rather than updating it by class.

Even though you want things to show up in the status window rather than the status bar, Cmud still calls it a 'status bar' object internally, it'll just have the 'show in status window' option enabled and the 'show in status bar' option disabled. It is possible to have multiple status bar objects in your Cmud settings, you're not limited to just one of them, and you can have them spread across multiple classes, just like other settings, like triggers or aliases or variables. Status bar objects show up in the status bar or window in order according to their priority, such that lower priority status bar objects are displayed first.
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Tue May 31, 2011 12:42 pm   
 
WOO! It works perfectly fine now. You are the best!
Thanks a lot for the help.
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Tue May 31, 2011 12:42 pm   
 
Smile No problem.
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Tue May 31, 2011 1:56 pm   
 
One last question.
Is it possible to output only the timer of Armor, like it is right now. Right now, the output from "@buff_timer("armor")" will generate "Armor 0:30". Since I want to be able to control colors and such, the best thing would be to be able to call the timer for Armor, and only the timer.
Is this a possibility with the current script?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Tue May 31, 2011 2:40 pm   
 
With a slight modification, yep.
Change the last line in the function 'buff_timer' from:
#RETURN %format("&14s &2d:&2s", %proper($buff), $minutes, $seconds)
to:
#RETURN %format("&2d:&2s", $minutes, $seconds)

That will cause it to return only the timer, not the name and the timer.
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Tue May 31, 2011 5:01 pm   
 
Haha, this is becoming more and more complex.
Is it possible to do something like this?(This is my status window)

Code:

%ansi(@scol1)@buff1 [@buff_timer("@buffname1")]
%ansi(@scol2)@buff2 [@buff_timer("@buffname2")]
%ansi(@scol3)@buff3 [@buff_timer("@buffname3")]
%ansi(@scol4)@buff4 [@buff_timer("@buffname4")]
%ansi(@scol5)@buff5 [@buff_timer("@buffname5")]
%ansi(@scol6)@buff6 [@buff_timer("@buffname6")]
%ansi(@scol7)@buff7 [@buff_timer("@buffname7")]
%ansi(@scol8)@buff8 [@buff_timer("@buffname8")]
%ansi(@scol9)@buff9 [@buff_timer("@buffname9")]
%ansi(@scol10)@buff10 [@buff_timer("@buffname10")]
%ansi(@scol11)@buff11 [@buff_timer("@buffname11")]
%ansi(@scol12)@buff12 [@buff_timer("@buffname12")]
%ansi(@scol13)@buff13 [@buff_timer("@buffname13")]
%ansi(@scol14)@buff14 [@buff_timer("@buffname14")]
%ansi(@scol15)@buff15 [@buff_timer("@buffname15")]


Where @scol is either black(off) green(on), @buff is the name of the buff(Barkskin, Combat Stance etc), and then the timer.
Before, I had so that the buffs had their place, basically barkskin was at the top, then combat stance and so on. The problem then is that if I only have on buff on, it could be in the middle of the window which isn't nice looking.
Now, the first buff will be at the top, the second one at number 2 etc.

The problem is to make the timer follow them in the list. I tried giving @buffname1 the value of combatstance but no timer shows, but putting in @buff_timer("combatstance") works perfectly.
Is it possible to something like what I did above, but actually make it to work? :P


EDIT: I solved this problem, so I do not need anymore help...yet. :P
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net