What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Help with code

Pages: (4): « First « 1 2 [ 3 ] 4 » Last »
Help with code
Author: Message:
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: Help with code
Because they load the file on startup, so you can not add any words to the file during runtime.

And the second thing: you'll have to specify " hi " in your files if you want to.

[offtopic] ooh 400 posts :o) [/offtopic]

This post was edited on 11-08-2008 at 07:53 PM by SmokingCookie.
11-08-2008 07:51 PM
Profile PM Find Quote Report
Jonte135
Junior Member
**


Posts: 57
– / – / Flag
Joined: Aug 2007
O.P. RE: Help with code
Well the loading thingy solved itself, it was just when I talked with the bot that it took a long time.

Instead of adding every single possibility like " hi " can't you do so it will only react if it matches the first word? Nothing else.

[offtopic] Congratulations :) [/offtopic]

This post was edited on 11-08-2008 at 07:57 PM by Jonte135.
11-08-2008 07:56 PM
Profile E-Mail PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: Help with code
I might be able to do that, but it's ben a busy day so.. |-) might take a while :P

[offtopic] Thx :) [/offtpoic]

EDIT:: Okay, I've got it, but the message must not end with a dot (.)

JScript code:
var FileSys = new ActiveXObject("Scripting.FileSystemObject");
var BasePath = MsgPlus.ScriptFilesPath + "\\"; // I like when stuff ends with a backslash
var TXTNAME = ""; // store for later use
 
function OnEvent_Initialize(bMsgStart) {
    if(!bMsgStart) {
        TXTNAME = BasePath + "text.txt";
    }
}
 
function OnEvent_ChatWndReceiveMessage(objChatWnd,strOrigin,strMessage,intMsgKind) {
    if(strOrigin != Messenger.MyName) {
        var objTextFile, strAllText, arrMessages; // variables for later usage
        if(!FileSys.FileExists(TXTNAME)) {
            objTextFile = FileSys.CreateTextFile(TXTNAME,false /* don't overwrite */,true /* Save as Unicode */ ); // If it doesn't exist, save empty file
        } else {;
            objTextFile = FileSys.OpenTextFile(TXTNAME,1 /* read */); // if it does exists, open
        }
        strAllText = objTextFile.ReadAll(); // read contents
        objTextFile.Close(); // close file
        arrMessages = strAllText.split("\r\n"); // get the array of newline characters
        var Pattern; // declare a variable
        var Words = strMessage.split(" ");
        for(var i = 0 /* declare a variable */ ; i < arrMessages.length /* make sure it's not beyond the end of the array */ ; i++ /* and increment it by 1 */ ) {
            Pattern = new RegExp(arrMessages[i],"gim"); // Global, (case) Insensitive, Multiline
            var Chunk = strMessage.substr(0,arrMessages[i].length); // Get the first chunk of text
//          var Chunk = Words[0]; // Get the first word
            if(Chunk.toLowerCase() == arrMessages[i].toLowerCase()) { /* is the beginning of the message arrMessages[i]? */
                objChatWnd.SendMessage(arrMessages[Math.round(Math.random()%(arrMessages.length - 1 /* devide by number of lines */) )]);
                return strMessage; // suspend execution
            }
        }
        return strMessage; // suspend execution
    }
}


This post was edited on 11-08-2008 at 08:32 PM by SmokingCookie.
11-08-2008 07:58 PM
Profile PM Find Quote Report
Jonte135
Junior Member
**


Posts: 57
– / – / Flag
Joined: Aug 2007
O.P. RE: Help with code
Sure I can wait :) It will take way longer if I try to do it myself :D

This post was edited on 11-08-2008 at 08:03 PM by Jonte135.
11-08-2008 08:03 PM
Profile E-Mail PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: Help with code
Okay, you may not have noticed it (email?), but I've updated the code again, after the first edit. Now it uses your email as text file (for eample "my@email.com.txt").
11-08-2008 08:07 PM
Profile PM Find Quote Report
Jonte135
Junior Member
**


Posts: 57
– / – / Flag
Joined: Aug 2007
O.P. RE: Help with code
Why should I have it like that? ^o) *confused*
11-08-2008 08:14 PM
Profile E-Mail PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: Help with code
To allow for multiple users :P

EDIT:: if it'd work at all (which is doesn't).. Changed back tot "text.txt" again :P

This post was edited on 11-08-2008 at 08:18 PM by SmokingCookie.
11-08-2008 08:15 PM
Profile PM Find Quote Report
Jonte135
Junior Member
**


Posts: 57
– / – / Flag
Joined: Aug 2007
O.P. RE: Help with code
I don't get it :s
11-08-2008 08:18 PM
Profile E-Mail PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: Help with code
Never mind, it works now. :P

What the script does:

  • Read the file Text.txt
  • Searches for all the nearest match of the current word (done in a loop), in a string from the beginning of the received message, all the way to the last character position of the current word in the loop ("hello" means char 1 to 5)
  • Sends a random message from the same file
  • Returns the received message to break the loop and suspend execution

Make sure you're not on 2 accounts at the same time. Sending "hello" will result in the script responding to its own messages. Your PC will not be made any faster by this..

This post was edited on 11-08-2008 at 08:38 PM by SmokingCookie.
11-08-2008 08:35 PM
Profile PM Find Quote Report
Jonte135
Junior Member
**


Posts: 57
– / – / Flag
Joined: Aug 2007
O.P. RE: RE: Help with code
quote:
Originally posted by SmokingCookie
Your PC will not be made any faster by this..
Lol.

Thanks a lot! Do you know if it's possible to have different script settings for different users if you are logged in at the same time with two accounts?
11-08-2008 09:10 PM
Profile E-Mail PM Find Quote Report
Pages: (4): « First « 1 2 [ 3 ] 4 » 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