Shoutbox

[help needed] randomly send a word from a list - 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: [help needed] randomly send a word from a list (/showthread.php?tid=66341)

[help needed] randomly send a word from a list by skyserpent on 09-16-2006 at 10:17 PM

hey people,

how can i make a script send a word picked randomly from a list when moo! is sent?

thanks for any help


RE: [help needed] randomly send a word from a list by NanaFreak on 09-16-2006 at 10:58 PM

ok here you go

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message)
{
  if(Message=='moo!')
  {
    g = new Array('word','something','stuff','goes','here'); //the words you want
    ran = g[Math.floor(Math.random()*g.length)]; //getting a random word
    ChatWnd.SendMessage(ran); //sending the word
  }
}

tested it as well and it works fine so have fun [Image: msn_happy.gif]
RE: [help needed] randomly send a word from a list by phalanxii on 09-16-2006 at 11:04 PM

It really depends on how you want the script to work. Here are three scripts.

Let's say you want it to send a random word when you send a message saying "moo!" (and only "moo!").

code:
var RandomWordList = new Array("box", "ship", "letter");

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   if(Message == "moo!") {
      return RandomWordList[Math.floor(Math.random() * RandomWordList.length)];
   }
}
The random words can be added to RandomWordList separated by commas and surrounded by quotation marks. There is no limit for how many words you want in the list. This script will send a random word when you send a message containing "moo!" exactly (case-sensitive), replacing "moo!".

Now, let's say you want it to replace all the "moo!"s in your message with a random word.
code:
var RandomWordList = new Array("box", "ship", "letter");

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   return Message.replace(/moo!/g, RandomWordList[Math.floor(Math.random() * RandomWordList.length)]);
}
Again, we use the RandomWordList array. This time, you can type whatever you want with a "moo!" in it and it will replace it with a random word. This is also case-sensitive

Finally, here is a code identical to the above, except it replaces "moo!" with different random words each time (if there is more that one "moo!' in a message).
code:
var RandomWordList = new Array("box", "ship", "letter");

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   while(Message.match(/moo!/) != null) {
      return Message.replace(/moo!/, RandomWordList[Math.floor(Math.random() * RandomWordList.length)]);
   }
}
This also uses the RandomWordList array. This is identical to the above, except if you send a message "I like moo! moo!", instead of seeing (for example) "I like box box", you will see something like "I like letter box".

Hope these are close to what you need. I haven't tested them, so look out for bugs or infinite loops. :S

EDIT: JayJay's random is better. :)
RE: [help needed] randomly send a word from a list by skyserpent on 09-17-2006 at 01:22 AM

thank you erm... the person who posted second... jay_jay, yours worked but for some reason not integrated with my script. so basically, thanks to everyone that helped