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
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Tue May 10, 2011 9:38 pm   

Hide Gauge When Not In Use
 
Hey guys,

I have a setup that tracks my subdued mobs by counting down a variable on a gauge. Each mob has a separate gauge. In order to save space, I'm trying to set it up so that when the countdown expires, the gauge fades out and the next closest-to-0 gauge takes it place. Kind of like cooldown bars from WoW or any other MMO. Code for gauge attached below.

Code:

<button type="Gauge" variable="Tagge Subdue" autosize="false" width="200" height="18" toolbar="2" iconleft="false" inset="true" color="red" textcolor="white" gaugelowcol="yellow" priority="19" id="218">
  <caption>Tagge Subdue: @TaggeCD s.</caption>
  <expr>@TaggeCD</expr>
  <gaugemax>2700</gaugemax>
  <gaugelow>300</gaugelow>
  <tooltip>Tagge Subdue</tooltip>
</button>


Also, instead of the textual countdown going from 600s down to 0, is it possible to convert it to show 10:00?

Thanks! Look forward to learning more code with you guys and churning out some nice products. =)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue May 10, 2011 11:28 pm   
 
To make it disappear, simply disable it with the #T- command. One way would be to have an Expression trigger (a trigger which fires when a specific expression is TRUE) which tests whether @TaggeCD=0. Something like:
Code:

<trigger type="Expression" priority="23270" id="2327">
  <pattern>@TaggeCD=0</pattern>
  <value>#T- MyGauge</value>
</trigger>

You'd also need some other trigger to enable this gauge with #T+.

As for your second question, you might be able to change your caption to something like:
Code:
Tagge Subdue: %format("&d:&02d", @TaggeCD/60, %mod(@TaggeCD,60))
Reply with quote
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Wed May 11, 2011 5:23 am   
 
Rahab,

Thanks for the info!

The first portion worked like a charm! For anyone else wondering, the trigger I used to enable the gauge back with the #T+ was the original trigger that sets off the gauge countdown. =)

For the second portion, inserting that code turns it into MM:SS format, but will read 0:32 instead of 5:32 (minutes are not showing while seconds are, and accurately loop from 59-0. Any idea on this fix for the minutes?

Thanks!
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Wed May 11, 2011 2:42 pm   
 
Tagge Subdue: %format("&d:&02d", (@TaggeCD/60), %mod(@TaggeCD,60))

The brackets are required around the expression to force the calculation otherwise it just ends up as a string like 600/60 for instance.
_________________
Taz :)
Reply with quote
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Wed May 11, 2011 6:17 pm   
 
Awesome! Working as described! =)

Another question:

I am having the gauges line the side of the screen and count down delays.
I want them to appear in order of shortest delay until longest delay. Is there a way to do this? Perhaps some trigger to sort gauge priority on time left on each variable?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed May 11, 2011 8:04 pm   
 
You can change the priority of a setting with the %priority() function.

That's actually pretty cool--I hadn't noticed that until I went checkin the docs just now.
Reply with quote
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Thu May 12, 2011 6:31 am   
 
Can you give me a code example of this please? My head takes a minute to wrap around code like this. =)

For example, if I have Gauge1 (time controlled by VariableA) and Gauge2 (time controlled by VariableB). How would I make it to display whichever gauge is ending soonest?

Thanks!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu May 12, 2011 1:33 pm   
 
Let's do this in a more general way, so that you can sort any number of gauges by time remaining. Let us assume that the variable @GaugeList contains a database matching the names of all the gauges to the related time-remaining variable, something like: "Gauge1=VariableA|Gauge2=VariableB|Gauge3=VariableC". The following would be a very crude way of sorting the gauges--a much better sorting routine could be designed. This is to give you an idea how it could be done.
Code:

#LOCAL $Gauges $Next $NextPriority
$Gauges = %dbkeys(@GaugeList)                    \\ Make a list of the gauge names
$NextPriority = 100                              \\ The first gauge will be set to priority 100
#WHILE $Gauges {                                 \\ Loop until you set all the gauge priorities
  $Next = $Gauges.1                              \\ Check the first gauge in the remaining list
  #FORALL $Gauges {                              \\ Loop through all the remaining gauges
    $Time1 = @{@GaugeList.$Next}                 \\ Find the time left on the gauge you are checking
    $Time2 = @{@GaugeList.%i}                    \\ Find the time left on the next gauge in the list
    #IF ($Time1 < $Time2) {$Next = %i}           \\ Pick the gauge with the least time left
  }                                              \\ Loop until you have the next gauge to prioritize
  #CALL %priority($Next,"button",$NextPriority)  \\ Set the priority for this gauge
  $Gauges = %delitem($Next, $Gauges)             \\ Remove that gauge from the list
  $NextPriority = ($NextPriority + 100)          \\ Increment the priority
}                                                \\ Loop until all the guages have been prioritized
Reply with quote
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Thu May 12, 2011 3:14 pm   
 
Okay, so, I need to make a Variable called @gaugelist, and have the gauge names equaling the variables that determine their countdown. The code you posted, where am I supposed to put it?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu May 12, 2011 3:46 pm   
 
That was one example of how you could do it. There are hundreds of ways you could do it. I don't know how you currently have your triggers and buttons set up. This was intended to show you the principles so that you could figure out how to use it yourself. Without a whole lot more information about your triggers and buttons, we simply cannot tell you how to do this for your case.

You have misunderstood the @GaugeList variable I described above. As I described it, @Gaugelist contains _both_ the name of the gauge _and_ the name of the variable which is associated with that gauge. So, if Gauge1 is based on VariableA, and Gauge2 is based on VariableB, and Gauge3 is based on VariableC, then you could have:
@GaugeList = {Gauge1=VariableA|Gauge2=VariableB|Gauge3=VariableC}

This is called a database variable, where Gauge1, Gauge2, and Gauge3 are the keys, and VariableA, VariableB, and VariableC are the values of those keys. You can use the %db function to find the value associated with a key, or use the syntax @variablename.keyname, as I do above. There are numerous other functions you can apply to database variables as well.

You don't have to do this with a database variable--that is just one possible way to do it. However you do it, you somehow need to know the names of the gauges and the variables associated with those gauges.

Where are you supposed to use it? Again, that depends on all the rest of your code. I have no idea how you are setting the countdowns on your gauges. Perhaps you could put this code into whatever trigger you are using to set the initial countdown values. Or perhaps you need to do it some other way.
Reply with quote
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Thu May 12, 2011 7:13 pm   
 
Thank you for all of the info. I'm trying to learn as we patch along here... Here's a sample of a gauge setup for me.

Code:

<class name="Decoy" id="366">
  <trigger priority="530" id="367">
    <pattern>^You create and position a hologram of yourself to fool those looking for you.</pattern>
    <value>#VAR DecoyCD 300
#T+ DecoyCountdown
#T+ DecoyGauge</value>
  </trigger>
  <trigger name="DecoyCountdown" type="Alarm" priority="7580" enabled="false" id="368">
    <pattern>*1</pattern>
    <value>#IF (@DecoyCD<=0) {#T- DecoyCountdown
} {#ADD DecoyCD -1}</value>
  </trigger>
  <var name="DecoyCD" id="369">0</var>
  <button name="DecoyGauge" type="Gauge" variable="DecoyGauge" autosize="false" width="150" height="25" toolbar="4" iconleft="false" inset="true" color="maroon" textcolor="white" gaugelowcol="yellow" priority="3" enabled="false" id="370">
    <caption>Decoy: %format("&amp;d:&amp;02d", (@DecoyCD/60), %mod(@DecoyCD,60))</caption>
    <expr>@DecoyCD</expr>
    <gaugemax>300</gaugemax>
    <gaugelow>30</gaugelow>
    <tooltip>Decoy</tooltip>
  </button>
  <trigger type="Expression" priority="2410" id="371">
    <pattern>@DecoyCD=0</pattern>
    <value>#T- DecoyGauge</value>
  </trigger>
</class>


Okay, so as I understand it:

Variable: DecoyCD - tracks the time for the cooldown.
Trigger: @DecoyCD=0 - tracks when the variable gets to 0 in order to hide the gauge.
Trigger: DecoyCountdown - the brain behind the countdown, ticking -1 from the variable until complete.
Trigger: You create..... - tells the variable when to begin, what number to begin at, brings the gauge visible, and starts the countdown trigger.
Gauge: DecoyGauge - basic gauge

This is the basic setup I have for all of my gauges.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri May 13, 2011 12:13 am   
 
Okay, that looks good. Straightforward setup. You could probably just insert the code I put above in the beginning of the "You create and position..." trigger, but since I expect you have a lot of triggers like this, it will be easier if you don't have to put this into every single one.

So, create an alias, maybe named SortGauges. Put my code into SortGauges. In the "You create and position..." trigger (and every similar trigger for the other gauges), add a line with the command SortGauges. Then, all you have to do is create a new variable, listing every gauge and it's variable:
Code:
#var GaugeList {DecoyGauge=DecoyCD|AnotherGauge=AnotherCD|...}

You can edit the variable later if you need to add more gauges, either in the PackageEditor or with commands like #ADDKEY or #DELKEY.

As I said before, there are probably a hundred ways you could do something similar, some of which would be better, but I think this should work. Note, though, that I haven't actually tested the code. One last thought--I'm not sure how fast this will run. Since it will involve redrawing the screen multiple times every time the SortGauges alias is executed, it could actually be a bit slow. If lag is a danger when you are executing this, we should probably come up with a different algorithm that won't have to redraw quite so often.
Reply with quote
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Sat May 21, 2011 12:25 pm   
 
Rahab,

Sorry for the late reply. Got it working like a champ! Thank you so much!
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