What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » StopWatch (AFKTime Counter)

Pages: (2): « First [ 1 ] 2 » Last »
StopWatch (AFKTime Counter)
Author: Message:
NorteX
New Member
*


Posts: 8
Joined: Mar 2009
O.P. StopWatch (AFKTime Counter)
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

This post was edited on 03-25-2009 at 04:52 PM by NorteX.
03-25-2009 04:49 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: StopWatch (AFKTime Counter)
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';
}

This post was edited on 03-25-2009 at 06:15 PM by matty.
03-25-2009 06:15 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: StopWatch (AFKTime Counter)
What about this? I think it's much more useful to store the time rather than counting the time yourself. :P
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! :O
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';
}

This post was edited on 03-25-2009 at 06:59 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
03-25-2009 06:45 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: StopWatch (AFKTime Counter)
Much more efficent. I was lazy and didn't want to do it.
03-25-2009 06:50 PM
Profile E-Mail PM Find Quote Report
NorteX
New Member
*


Posts: 8
Joined: Mar 2009
O.P. RE: StopWatch (AFKTime Counter)
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?
03-25-2009 06:54 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: StopWatch (AFKTime Counter)
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! :P
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
03-25-2009 07:00 PM
Profile E-Mail PM Web Find Quote Report
NorteX
New Member
*


Posts: 8
Joined: Mar 2009
O.P. RE: StopWatch (AFKTime Counter)
ah and it has no funktion that this script ends when i get back to ONLINE or change my Away status Message.... :/
03-25-2009 07:01 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: StopWatch (AFKTime Counter)
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! :D
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
03-25-2009 07:04 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: StopWatch (AFKTime Counter)
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';
}
03-25-2009 07:05 PM
Profile E-Mail PM Find Quote Report
NorteX
New Member
*


Posts: 8
Joined: Mar 2009
O.P. RE: StopWatch (AFKTime Counter)
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 :S


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 :(

This post was edited on 03-25-2009 at 07:44 PM by NorteX.
03-25-2009 07:21 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On