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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
The Raven
Magician


Joined: 13 Oct 2000
Posts: 463

PostPosted: Mon Jul 08, 2002 9:23 pm   

Example Script: Countdown Timer
 
On Battletech 3030, I have a technician character. Most of the time on the MUX is spent repairing mechs that are damaged. It takes real life time to do these repairs, limiting how much one person can do.

To keep track of my time, I made a countdown timer, and I thought it was interesting enough to warrent posting it here. In particular, the alias 'modtechtime' could be useful in many situations when you need to manually handle a timer, and want to display it nicely using hours minutes and seconds, instead of just thousands of seconds.

#CLASS {Technician} {setdef}

At random intervals between 5-20 minutes it checks my tech time, to recalibrate the timer as it drifts slightly.
#ALIAS checktechtime {
#ALARM +%random( 300, 1200) {checktechtime}
~+techtime
}

This multi-state trigger gags the output of the +techtime command, and captures the time into the TechTimeX variables... Days, Hours, Minutes, and Seconds. At the end of the states, it turns on the #TIMER (if it is not already on) with a 1 second loop.
#TRIGGER {^Technician Time For: } {#GAG}
#COND {^$} {#GAG}
#COND {^-------------------------------------------------------------------------------} {#GAG}
#COND {^Logged Repairs: (&TechTimeD).(&TechTimeH):(&TechTimeM):(&TechTimeS) Remaining Time:} {#GAG}
#COND {^Rested Time:} {#GAG}
#COND {^-------------------------------------------------------------------------------} {
#GAG
#IF (not @TechTimer) {
#TIMER 1 {modtechtime -1} 0 0
#TSET 1
#VAR TechTimer 1
}
}

Here is the fun alias. It takes one parameter, the number of seconds to add or subtract from the timer. It then adjusts the clock variables accordingly, including adding padded 0s as necessary. If the timer goes negative, then it sets all the variables to 0 and turns off the tick timer.
#ALIAS modtechtime {
#MATH TechTimeS {@TechTimeS + %1}
#IF (@TechTimeS >= 60) {
#MATH TechTimeS {@TechTimeS - 60}
#MATH TechTimeM {@TechTimeM + 1}
#IF (@TechTimeM >= 60) {
#MATH TechTimeM {@TechTimeM - 60}
#MATH TechTimeH {@TechTimeH + 1}
#IF (@TechTimeH >= 24) {
#MATH TechTimeH {@TechTimeH - 24}
#MATH TechTimeD {@TechTimeD + 1}
}
}
}
#IF (@TechTimeS < 0) {
#MATH TechTimeS {@TechTimeS + 60}
#MATH TechTimeM {@TechTimeM - 1}
#IF (@TechTimeM < 0) {
#MATH TechTimeM {@TechTimeM + 60}
#MATH TechTimeH {@TechTimeH - 1}
#IF (@TechTimeH < 0) {
#MATH TechTimeH {@TechTimeH + 24}
#MATH TechTimeD {@TechTimeD - 1}
#IF (@TechTimeD < 0) {
#VAR TechTimeD 0
#VAR TechTimeH 0
#VAR TechTimeM 0
#VAR TechTimeS 0
#VAR TechTimer 0
#TIMER 0
}
}
}
}
#IF (@TechTimeS < 10) {
#MATH TechTimeS {@TechTimeS + 0}
#VAR TechTimeS {0@TechTimeS}
}
#IF (@TechTimeM < 10) {
#MATH TechTimeM {@TechTimeM + 0}
#VAR TechTimeM {0@TechTimeM}
}
#IF (@TechTimeH < 10) {
#MATH TechTimeH {@TechTimeH + 0}
#VAR TechTimeH {0@TechTimeH}
}
#IF (@TechTimeD < 10) {
#MATH TechTimeD {@TechTimeD + 0}
#VAR TechTimeD {0@TechTimeD}
}
}

This is one example of how I use the timer. It does not let me accidentally do more repairs when my tech time is over an hour already.
#ALIAS fix {#if (@TechTimeH > 0) {#ECHO Tech time too high, access denied.} {~fix %-1}}

Simple Status bar to display my tech time.
#STAT {Tech Time: @TechTimeD~.@TechTimeH~:@TechTimeM~:@TechTimeS}
#CLASS 0
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Tue Jul 09, 2002 4:59 am   
 
You might consider posting this in the Finished Scripts forum.

LightBulb
Senior Member
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Jul 09, 2002 6:56 am   
 
quote:

You might consider posting this in the Finished Scripts forum.

LightBulb
Senior Member



He might put it in there, but he should definitely put a giant note somewhere at or near the top saying that it was designed in the beta version with the new trigger setup (6.2x wasn't it?) #COND doesn't exist yet in a public version.

li'l shmoe of Dragon's Gate MUD
Reply with quote
The Raven
Magician


Joined: 13 Oct 2000
Posts: 463

PostPosted: Wed Jul 10, 2002 9:52 pm   
 
Slapped down doubly hard for two stupid errors. LOL. I'll follow both suggestions, thanks.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Jul 11, 2002 4:55 am   
 
Nothing wrong with putting it here (aside from the beta references), but it's more likely to be looked at in the future if it's in Finished Scripts. And of course, when the next public version comes out those commands won't be beta any longer.

LightBulb
Senior Member
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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