What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [help needed] randomly send a word from a list

[help needed] randomly send a word from a list
Author: Message:
skyserpent
Junior Member
**

Bacon

Posts: 96
32 / Male / –
Joined: Aug 2006
O.P. [help needed] randomly send a word from a list
hey people,

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

thanks for any help

This post was edited on 09-16-2006 at 10:38 PM by skyserpent.
09-16-2006 10:17 PM
Profile E-Mail PM Web Find Quote Report
NanaFreak
Scripting Contest Winner
*****


Posts: 1476
Reputation: 53
32 / Male / Flag
Joined: Jul 2006
RE: [help needed] randomly send a word from a list
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]
09-16-2006 10:58 PM
Profile PM Find Quote Report
phalanxii
Full Member
***


Posts: 146
Reputation: 5
32 / Male / Flag
Joined: Aug 2006
Status: Away
RE: [help needed] randomly send a word from a list
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. :)

This post was edited on 09-16-2006 at 11:17 PM by phalanxii.
09-16-2006 11:04 PM
Profile PM Find Quote Report
skyserpent
Junior Member
**

Bacon

Posts: 96
32 / Male / –
Joined: Aug 2006
O.P. RE: [help needed] randomly send a word from a list
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
09-17-2006 01:22 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