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
Atreides_096
Wanderer


Joined: 21 Jan 2005
Posts: 99
Location: Solvang, CA

PostPosted: Sat Jan 29, 2005 3:31 am   

Can someone help? Need to fix a bug involving timing events.
 
Ok, I have written a script for the MUD Aardwolf, which tracks (amongst other things) how long it takes me to "quest". It then averages my quest time overall, for output from an alias. However, whenever I begin a quest BEFORE an even hour (7:00:00pm for example), and end AFTER the hour (so, say, start at 06:59:45pm and end at 07:00:46pm), it counts the time as minus (in the above example, would be like -58 minutes -59 seconds).

However, if I were to simply put in an if statement (if time is not greater than 0, don't add) it would obviously then not track all quests, which would throw off averages and such, unless I had it remove all statistics from the quest (not the desired result). Anyone have a suggestion on how to fix it? Some of the code below:

Code:
#class {GroupInfo|Questing}
#var qendstemp {%time( c)}
#var timeqc %eval( %eval( 60 * %eval( %time( nn)-@QSMinute)) + %eval( %time( ss)-@QSSecond))
#add timeqct {@timeqc}
#math qendm {(@timeqc)/60}
#math qends {(@timeqc) - ((@qendm)*60)}
#class 0
#if {@qpbonus>0} {gt ~@G-=~@g(~@GQuest Complete~@g)~@G=-"   "~@WQPs: ~@Y@qpointsr~@W+~@Y@qpbonus~@W+~@Y2~@W+~@Y@lqtb~@W. Gold: ~@W@qgoldr"   " ~@G-=~@g(~@G Time: @qendm~m @qends~s~ @g)~@G=-~@Y} {gt ~@G-=~@g(~@GQuest Complete~@g)~@G=-"   "~@WQPs: ~@Y@qpointsr~@W+~@Y2~@W+~@Y@lqtb~@W. Gold: ~@Y@qgoldr"   "~@G-=~@g(~@G Time: @qendm~m @qends~s~ @g)~@G=-~@Y}
#class {GroupInfo|Questing}
#var qpbonus 0
#var lqtb 0
#class 0
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat Jan 29, 2005 9:11 am   
 
Instead of using %time() you could use the %secs variable
first we make a permanent variable fullday which basically is just how many milliseconds is in a full day
Code:
#var fullday %eval(24*60*60*1000)

when you start a quest you set time1
Code:
#var time1  %secs()

when you finish set time2 and calculate the elapased time
Code:
#var time2  %secs()
#var elapsed  %eval(@time2-@time1)
#var elapsed %if(@elapsed>0,@elapsed,%eval(@fullday + @elapsed))

the if function in the above line is incase you start at say 11pm and finish at 2am in which case the elapsed time would be a negative
(or 0 if it took exactly 24 hours) so we add a full day to it to get the actual time,this if check will work as long as the quest last
1 millisecond and less than 48 hours.
Then to display the elapsed time in a format hh:mm:ss
you could make a function like this
Code:
#FUNC secs2time { %eval(%1/3600000):%mod(%1/60000),60):%mod(%1/1000),60)}


and pass the value in @elapsed to the function secs2time


you could also use the JScript Date object to avoid any problems with
negative values
Code:
#var time1 %mss(Date.parse(Date()),JScript)
#var time2 %mss(Date.parse(Date()),JScript)
#var elapsed %mss(%expand(@time2)-%expand(@time1),JScript);
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Jan 29, 2005 3:05 pm   
 
#var timeqc %eval( %eval( 60 * %eval( %time( nn)-@QSMinute)) + %eval( %time( ss)-@QSSecond))

First, you need to replace the #VARIABLE command with the #FUNCTION command in the above statement. Otherwise, the command gets evaluated immediately and only the result is put into the variable.

Second, the statement evaluates the difference in minutes {%eval( 60 * %eval( %time( nn)-@QSMinute))} and the difference in seconds {%eval( %time( ss)-@QSSecond)} but has nothing to account for a difference in hours. To fix it, simply add a statement to evaluate the difference in hours {%eval (3600 * %eval( %time( hh) - @QSHour))}. Of course, you'll also need to create @QSHour.
_________________
LightBulb
Senior member

Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious.
Reply with quote
DeathDealer
Adept


Joined: 20 Jul 2004
Posts: 268

PostPosted: Mon Jan 31, 2005 6:19 pm   
 
Been using this one for a while now, and never ran into a problem with it:
Code:
#ALIAS resetquests {#VAR totalqp 0;#VAR totalquests 0} "qtimer"
#ALIAS lquest {#MATH qptemp ((@totalqp*100)/@totalquests);#MATH averageqp (@qptemp/100);qpfloat=%mod( @qptemp, 100);#IF (@qpfloat < 10) {qpfloat=%concat( "0", @qpfloat)};%1 ~@Wquest:~@w @questmob ~(@questarea) ~@Wtime:~@w @questlength ~@Wreward:~@w @questreward@tierbonus@doubleqp@questbonus~+2~=%eval(@questreward@tierbonus@doubleqp@questbonus+2)qp@questpracs@questtrains@questtp ~@Waverage: ~@w@{averageqp}.@{qpfloat}qp/quest over @totalquests quests.} "qtimer"
#VAR totalquests {249} {_nodef} "qtimer"
#VAR totalqp {4850} {_nodef} "qtimer"
#VAR tierbonus {+1} {_nodef} "qtimer"
#VAR ss {58} {_nodef} "qtimer"
#VAR questtrains {} {_nodef} "qtimer"
#VAR questtp {} {_nodef} "qtimer"
#VAR questtime {118601} {_nodef} "qtimer"
#VAR queststart {45253074} {_nodef} "qtimer"
#VAR questroom {Brothel} {_nodef} "qtimer"
#VAR questreward {13} {_nodef} "qtimer"
#VAR questpracs {} {_nodef} "qtimer"
#VAR questor {The Administrator} {_nodef} "qtimer"
#VAR questmob {a citizen} {_nodef} "qtimer"
#VAR questlength {01:58} {_nodef} "qtimer"
#VAR questgold {520} {_nodef} "qtimer"
#VAR questfinish {45371675} {_nodef} "qtimer"
#VAR questbonus {} {_nodef} "qtimer"
#VAR questarea {Pompeii} {_nodef} "qtimer"
#VAR qptemp {1947} {_nodef} "qtimer"
#VAR qpfloat {47} {_nodef} "qtimer"
#VAR onquest {0} {_nodef} "qtimer"
#VAR ms {601} {_nodef} "qtimer"
#VAR mm {01} {_nodef} "qtimer"
#VAR HH {00} {_nodef} "qtimer"
#VAR doubleqp {} {_nodef} "qtimer"
#VAR charname {YOUR_CHAR_NAME_HERE} {_nodef} "qtimer"
#VAR averageqp {19} {_nodef} "qtimer"
#TRIGGER {^~*~* You gain a bonus trivia point! ~*~*} {#IF (@onquest = 1) {#VAR questtp "+tp"}} "qtimer"
#TRIGGER {^~*~* You gain a bonus training session ~*~*} {#IF (@onquest = 1) {#VAR questtrains "+train"}} "qtimer"
#TRIGGER {^~*~* You gain a bonus practice ~*~*} {#IF (@onquest = 1) {#VAR questpracs "+prac"}} "qtimer"
#TRIGGER {^~*~* You gain a bonus (%d) practices ~*~*} {#IF (@onquest = 1) {#VAR questpracs "+%1pracs"}} "qtimer"
#TRIGGER {^You get lucky and gain an extra (%d) quest {point|points}.} {#IF (@onquest = 1) {#VAR questbonus "+%1";#AD totalqp %1}} "qtimer"
#TRIGGER {^You gain an extra 2 quest points 'MCCP Bonus'.$} {#IF (@onquest = 1) {#MATH HH @questtime/3600000;#MATH mm (@questtime/60000)-(@HH*60);#MATH ss (@questtime/1000)-(@HH*3600)-(@mm*60);#MATH ms @questtime-(@HH*3600000)-(@mm*60000)-(@ss*1000);#IF (@HH < 10) {HH=%concat( "0", @HH)};#IF (@mm < 10) {mm=%concat( "0", @mm)};#IF (@ss < 10) {ss=%concat( "0", @ss)};#IF (@ms < 100) {ms=%concat( "0", @ms)};#IF (@ms < 10) {ms=%concat( "0", @ms)};#VAR questlength @mm:@ss;#VAR onquest 0;#AD totalqp 2;lquest spouse}} "qtimer"
#TRIGGER {^You ask (*) for a quest.$} {#VAR questor "%1"} "qtimer"
#TRIGGER {^The gods reward you (%d) bonus quest points*} {#IF (@onquest = 1) {#VAR doubleqp "+%1+2";#AD totalqp %1}} "qtimer"
#TRIGGER {^@questor tells you 'Seek (*) out somewhere in the vicinity'$} {#VAR questmob "%1";#VAR queststart %secs;#VAR onquest 1} "qtimer"
#TRIGGER {^@questor tells you 'of (*).'$} {#VAR questarea "%1"} "qtimer"
#TRIGGER {^@questor tells you 'of (*) which is in the general area'$} {#VAR questroom "%1"} "qtimer"
#TRIGGER {^@questor tells you 'I am also giving you (%d) quest {point|points} tier bonus.} {#IF (@onquest = 1) {#VAR tierbonus "+%1";#AD totalqp %1}} "qtimer"
#TRIGGER {^@questor tells you 'As a reward, I am giving you (%d) quest points and (%d) gold.'$} {#IF (@onquest = 1) {#VAR questreward %1;#VAR questgold %2;#AD totalqp %1;#AD totalquests 1}} "qtimer"
#TRIGGER {^(*) tells you 'Congratulations @charname on completing your quest!'$} {#VAR questbonus "";#VAR questtrains "";#VAR questpracs "";#VAR questtp "";#VAR tierbonus "";#VAR doubleqp "";#VAR questor "%1";#VAR questfinish %secs;#VAR questtime %eval( @questfinish - @queststart)} "qtimer"
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