What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » randome phrase reply script provlem

randome phrase reply script provlem
Author: Message:
asnopus
New Member
*

Avatar

Posts: 1
Joined: Nov 2009
O.P. Dodgy  randome phrase reply script provlem
Im working on a code that has an array of phrases and wen someone types the activation command (apply) its supposed to choose a phrase at random from "sArray" and post it into the chat window, but instead it posts and nothing else, why does it do this?, please help me Thank you in advance. the code is:
code:
function OnEvent_Initialize(MessengerStart)
{
}


var sArray = new Array();
sArray[0] = "*";
sArray[1] = "**";

var dArray = new Array();
dArray[0] = "***";

   
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
    if(Message.substr(0,8).toLowerCase()=="apply"){
        var i = Math.floor((Math.random()*(sArray.length-1)));
        return "[b][c=red]"+sArray[i]+"[/c]
";
    }
   
        if(Message.substr(0,7).toLowerCase()=="applyver"){
        var h = Math.floor((Math.random()*(dArray.length-1)));
        return "[c=blue]"+dArray[h]+"[/c]";
    }

}

function OnGetScriptCommands(){
    var commands = '<ScriptCommands>';
        commands+='<Command>';
            commands+='<Name>apply</Name>';
            commands+='<Description>Sends a "apply" sentence</Description>';
        commands+='</Command>';
                commands+='<Command>';
            commands+='<Name>applyver</Name>';
            commands+='<Description>Sends Script Version Information</Description>';
        commands+='</Command>';

        commands+='</ScriptCommands>';
    return commands;
}

function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd){
    if(MenuItemId=="ym"){
        OriginWnd.SendMessage(OnEvent_ChatWndSendMessage("", "apply"));
    }
        if(MenuItemId=="i"){
        OriginWnd.SendMessage(OnEvent_ChatWndSendMessage("", "applyver"));
    }

}

function OnGetScriptMenu(nLocation){
    var ScriptMenu = "<ScriptMenu>\n";
    if(nLocation===2){
        ScriptMenu    +=    "<MenuEntry Id=\"ym\">apply</MenuEntry>";
        ScriptMenu    +=    "<MenuEntry Id=\"i\">Version Information</MenuEntry>";
    }
    ScriptMenu    += "</ScriptMenu>";
    return ScriptMenu;
}

function OnEvent_Uninitialize(MessengerExit)
{
}


I was using * for examples in the code so it was shorter
11-01-2009 09:38 AM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: randome phrase reply script provlem
It appears you're counting is wrong. You're retrieving the first 8 characters from Message and then you compare that to "apply" which is only 5 characters in length. Same happens for your "applyver" check.
js code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
>>>    if(Message.substr(0,5).toLowerCase()=="apply"){<<<
        var i = Math.floor((Math.random()*(sArray.length-1)));
        return "[b][i][c=red]"+sArray[i]+"[/c][/i][/b]";
    }

>>>    if(Message.substr(0,8).toLowerCase()=="applyver"){<<<
        var h = Math.floor((Math.random()*(dArray.length-1)));
        return "[b][i][c=blue]"+dArray[h]+"[/c][/i][/b]";
    }
}
Fix that and see if it works better now? :)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-01-2009 10:25 AM
Profile E-Mail PM Web Find Quote Report
« 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