You can use the 'goto' command to go to a label, which is a text string beginning with a colon. You could do something like:

====
if ( $rand(1,2) ) == 1 goto goodbean
else goto badbean

:badbean
code goes here
goto label123

:goodbean
code goes here
goto label123

:label123
code goes here
==========
obviously, you didn't need the "goto badbean" since that label was on the next line. and same goes for the goto at the end of the goodbean code.

You can simplify your script by keeping your messages either in separate text files, or in a hashtable. hashtable has the advantage of being kept in memory, so you don't need a disk read each time. text file has the advantage of being easy to /play the text file and see a list of all your messages.

Also, the $read command has the random feature built into it, when you don't give it a line number to read. This example uses the 'n' switch because that prevents any word beginning with $ or % from being replaced by how they evaluate. i.e. a line in the text file containing $me would print the literal "$me" instead of using your nick.

var %message $read(goodbean.txt,nt) $+ 1,0Enjoy The Bean

This fills a variable with a random line from the text file. This way you don't need to keep adjusting your script each time you add another message. Notice how I appended the final portion of the 'good bean' message, so you don't need to put that on every line of the text. If you find it harder to put the Ctrl+K symbol into the text file when using something like notepad, you can choose a character that will never be used in any of your messages, and use that in place of the color code. For example, assume the character will be the asterisk, the text file would contain lines like:

Black Pepper *15,1( *4Black*15 *4Pepper*15 )
Garlic *30,1( *4Garlic*30 )

and then you can fetch random lines like this, while changing the asterisk back to the Ctrl+K symbol:

msg %beanch Hands %victem a $replace($read(badbean.txt,nt),*,$chr(3)) $+ 1,0 Ohhh You've Been BeanBoozeled

After you read a random line, if you need to know which line was most recently read from any disk file, the line number is contained in $readn

Something else you should change in your script is that your variables are being created as global variables which continue to be saved in your vars tab of the scripts editor long after your script is used, even though they aren't needing to be saved for later. You can make them be local by either using /set -l or using /var

var %victem $nick
var %beanch #PoulsKitchen


It looks like
set -kl %badcount + 1
is supposed to be a counter for how many times the bad routine has been hit. By using the -l flag, this creates the variable as a local variable which doesn't exist outside the ON TEXT event. What this is doing is defining the variable as the literal string "+ 1". If you want to increment a global variable, you can do it like: /inc %badcount