Shoutbox

randome phrase reply script provlem - 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: randome phrase reply script provlem (/showthread.php?tid=92754)

randome phrase reply script provlem by asnopus on 11-01-2009 at 09:38 AM

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
RE: randome phrase reply script provlem by Matti on 11-01-2009 at 10:25 AM

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.

Javascript 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? :)