StopWatch (AFKTime Counter) - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: StopWatch (AFKTime Counter) (/showthread.php?tid=89870)
StopWatch (AFKTime Counter) by NorteX on 03-25-2009 at 04:49 PM
Hey,
i want to program some counter who starts when i type (for example) /counter with 0.00 (min.seconds) then everytime when i type the word /counter again (in a conversation for EG or in the Automessage when i am AFK) it shell say "I am AFK since [ x Hours x Minutes and x seconds]) so that the one who wanted to communikate with me knows (because i would type the automessage as /counter) how long i am afk ...
i hope u understand what i mean my english is not that good...
i already found this here as a counter???? i am completely new and want to learn plz help me to make a script for the AFK Time ...
function OnEvent_Initialize(bMessengerStart){
MsgPlus.AddTimer("RefreshPSM",60000);
}
function OnEvent_Timer(sTimerId){
if(sTimerId == "RefreshPSM"){
MsgPlus.AddTimer("RefreshPSM",60000);
}
}
greeez
RE: StopWatch (AFKTime Counter) by matty on 03-25-2009 at 06:15 PM
Something like this... I am at work can't test it.
js code: var bAway = false;
var h = 0;
var m = 0;
var s = 0;
function OnEvent_ChatWndSendMessage( pChatWnd, sMessage ){
if ( sMessage === '/counter' ) {
if ( bAway === true ) {
bAway = false;
h=0; m=0; s=0;
MsgPlus.CancelTimer( 'x' );
} else {
bAway = true;
MsgPlus.AddTimer('x', 1000);
}
return false;
}
}
function OnEvent_ChatWndReceiveMessage( pChatWnd, sMessage, sOrigin, nMessageKind ){
if ( bAway === true ) {
pChatWnd.SendMessage( 'I have been away from the computer for: '+parseTime( ) );
}
}
function OnEvent_Timer( sTimerId ){
if ( s === 59 ) {
s = 0;
if ( m === 59 ) {
m = 0;
h++;
} else m++
} else s++;
MsgPlus.AddTimer( sTimerId, 1000 );
}
function parseTime( ){
return h+'h '+m+'m '+s+'s';
}
RE: StopWatch (AFKTime Counter) by Matti on 03-25-2009 at 06:45 PM
What about this? I think it's much more useful to store the time rather than counting the time yourself.
I also implemented a workaround for a possible problem: when the AFK message is sent, it'll trigger the OnEvent_ChatWndReceiveMessage event and thus launching an infinite loop of AFK messages!
js code: var bAway = false;
var bOwnMessage = false;
var nCounterTime;
function OnEvent_ChatWndSendMessage( pChatWnd, sMessage ){
if ( sMessage === '/counter' ) {
if ( bAway === true ) {
bAway = false;
} else {
bAway = true;
nCounterTime = new Date().getTime();
}
return false;
}
bOwnMessage = true;
MsgPlus.AddTimer( 'OwnMessage', 1000);
}
function OnEvent_ChatWndReceiveMessage( pChatWnd, sMessage, sOrigin, nMessageKind ){
if ( bOwnMessage ) {
bOwnMessage = false;
MsgPlus.CancelTimer( 'OwnMessage' );
return;
}
if( bAway ) {
pChatWnd.SendMessage( 'I have been away from the computer for: '+parseTime( )+'.' );
}
}
function OnEvent_Timer( sTimerId ) {
if( sTimerId === "OwnMessage" ) {
bOwnMessage = false;
}
}
function parseTime( ){
var nSeconds = Math.floor( ( new Date().getTime() - nCounterTime ) / 1000 );
var s = nSeconds % 1000;
var m = Math.floor( nSeconds / 60 ) % 60;
var h = Math.floor( nSeconds / (60 * 60) );
return h+'hours, '+m+'minutes and '+s+' seconds';
}
RE: StopWatch (AFKTime Counter) by matty on 03-25-2009 at 06:50 PM
Much more efficent. I was lazy and didn't want to do it.
RE: StopWatch (AFKTime Counter) by NorteX on 03-25-2009 at 06:54 PM
woaaa... i tested the second one... if i type counter its very nice but it dont stop to send xD it sends 10000000 sentences with the AFK time xD
how can i fix this? that its only typed once?
RE: StopWatch (AFKTime Counter) by Matti on 03-25-2009 at 07:00 PM
quote: Originally posted by NorteX
woaaa... i tested the second one... if i type counter its very nice but it dont stop to send xD it sends 10000000 sentences with the AFK time xD
how can i fix this? that its only typed once?
You might want to try the updated code. After a brief look I saw that matty's code had an infinite loop in it, so I have implemented a simple workaround. When a message is sent by the user, a global variable "bOwnMessage" will be set to true for 1 second, and because of the nature of the OnEvent_ChatWndReceive event it'll immediately trigger that event. In our event, we then check the value of bOwnMessage to see whether this message was sent by the user or a contact and use that to decide whether to send a message or not.
So well, try the updated code!
RE: StopWatch (AFKTime Counter) by NorteX on 03-25-2009 at 07:01 PM
ah and it has no funktion that this script ends when i get back to ONLINE or change my Away status Message.... :/
RE: StopWatch (AFKTime Counter) by Matti on 03-25-2009 at 07:04 PM
quote: Originally posted by NorteX
ah and it has no funktion that this script ends when i get back to ONLINE or change my Away status Message.... :/
That was not in your initial request. You asked for something which allowed you to type /counter to start an AFK counter and type /counter again to stop it.
However it's not that hard to implement. You just have to set "bAway" to false to disable the AFK counter, so if you implement that in an OnEvent_MyStatusChange event after a check of the new status... Try it, nothing better to learn scripting than experimenting with it yourself and make your idea come to life!
RE: StopWatch (AFKTime Counter) by matty on 03-25-2009 at 07:05 PM
At this point your code becomes a bit more difficult.
js code: var bAway = false;
var dtTime;
var oChatWnd = {};
function OnEvent_ChatWndDestroyed ( pChatWnd ){
delete oChatWnd[ pChatWnd.Handle ];
}
function OnEvent_ChatWndSendMessage( pChatWnd, sMessage ){
oChatWnd[ pChatWnd.Handle ] = sMessage
if ( sMessage === '/counter' ) {
if ( bAway === true ) {
bAway = false;
} else {
bAway = true;
dtTime = new Date().getTime();
}
return false;
}
}
function OnEvent_ChatWndReceiveMessage( pChatWnd, sOrigin, sMessage, nMessageKind ){
if ( oChatWnd[ pChatWnd.Handle] !== sMessage && bAway === true ) {
pChatWnd.SendMessage( 'I have been away from the computer for: '+parseTime( )+'.' );
}
}
function parseTime( ){
var nSeconds = Math.floor( ( new Date().getTime() - dtTime ) / 1000 );
var s = nSeconds % 1000;
var m = Math.floor( nSeconds / 60 ) % 60;
var h = Math.floor( nSeconds / (60 * 60) );
return h+'hours, '+m+'minutes and '+s+' seconds';
}
RE: StopWatch (AFKTime Counter) by NorteX on 03-25-2009 at 07:21 PM
all works fine only the fact that the counter really starts first with the first automessage which says /counter... would it be possible to implent something that i can change to IDLE (away) and the counter started to count... because when im idle and nobody pms me... the first Automessage wont be written and the counter would first start for example after an hour if nobody requests an answer from me in this period of time... i hope u understant what i mean
hmm have to edit this... everytime i go to Away i set the automessage to /counter...but everytime when a person write me.... the counter starts from beginning o.O and sometimes its said and 1 minute and 132 seconds
i am overwhelmed -.- thats so hard for me as a newbie searched for some kind of solution but cant find anything
RE: StopWatch (AFKTime Counter) by matty on 03-25-2009 at 07:52 PM
why not allow /counter to change your status to away... that way you dont need to have an automessage...
RE: StopWatch (AFKTime Counter) by NorteX on 03-25-2009 at 08:05 PM
would also be nice when i type /afk or something that the counter starts - my status goes to Away and the Automessage would appear automatically... yeah that would be find but not possible i think or not?
what is the sMessage? where shell i type this /counter in a normal chat? oah im such a newbie
RE: StopWatch (AFKTime Counter) by NorteX on 03-25-2009 at 11:52 PM
hmm ok thx either
|