Author Topic: Random choice script  (Read 6787 times)

udhelp

  • Guest
Random choice script
« on: July 31, 2006, 02:32:52 AM »
Hi again :)

For a game some friends and i are playing w need a way to make someone choose something. the problem is, i dont know how to make the script choose a set of commands at random.

What i need is if someone types !command for it to choose 1 of 2 responses only. Once i get how to make it randomly choose one of the commands ill get the rest. so something like:

Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)

if lcase(Message) = "!command" then
...
end if

End Sub

where the "..." is whatever it would be to make it randomly choose 1 of 2 commands. Thanks alot.

udhelp

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Random choice script
« Reply #1 on: July 31, 2006, 11:51:45 AM »
Just generate a random number using the RND command. Then use an IF statement to do your command.

Go to www.microsoft.com/scripting/ and choose VB Script for VB Script help.
The IceChat God

udhelp

  • Guest
Re: Random choice script
« Reply #2 on: July 31, 2006, 09:57:35 PM »
Okay, I got this code off of the website:

Code: [Select]
Rnd[(number)]
But it doesnt give any information about how to implement it.
and none of the links on the page even work (like the "See Also" toggle, doesnt do anything.)

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Random choice script
« Reply #3 on: August 01, 2006, 06:28:52 AM »
Code: [Select]
Randomize
RandNum = Int(Rnd * 2) + 1

The Randomize function makes sure that the random number generator , generates a new seed of random numbers.
You will have a value of 1 or 2 , in the RandNum variable.
The IceChat God

udhelp

  • Guest
Re: Random choice script
« Reply #4 on: August 01, 2006, 10:23:21 PM »
okay, that seems to work, except after a hundred tries i didnt once get the first command to come up.

heres my code:

Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)

if lcase(Channel) = "#rr" then
if lcase(Message) = "!roulette" then
if RandNum = "1" then
SendCommand "/msg " & Channel & " test 1", ServerNumber
end if
if RandNum = "2" then
SendCommand "/msg " & Channel & " test 2", ServerNumber
end if
end if
else
if lcase(Message) = "!roulette" then
SendCommand "/msg " & Channel & " You have to be in #rr to use this feature.", ServerNumber
SendCommand "/invite " & Nickname & " #rr", ServerNumber
end if
end if

End Sub

Randomize
RandNum = Int(Rnd * 2) + 1

this just produces the second command, or "test 2" apears in the channel. notice anything i did wrong?

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Random choice script
« Reply #5 on: August 02, 2006, 03:17:34 AM »
You need the RandNum code inside the ONTEXT sub, of course, or it only runs it that single time.
The IceChat God

udhelp

  • Guest
Re: Random choice script
« Reply #6 on: August 02, 2006, 03:59:09 AM »
yay, it works, it works good :) Thanks man.