' Title: Fudge Dice Roller for ScreenMonkey
' Author: Patrick Benson
' Date Created: July-01-2007.
' Version: 1.1
' Description: This script will roll the number of Fudge dice specified by the user and display the results. Fudge dice are 6 sided dice that have 2 plus signs (+), 2 negative signs (-), and 2 blank sides (o). For every plus sign (+) the roll is read as a 1, for every negative sign (-) the roll is read as a -1, and for every blank (o) the roll is read as a zero. Besides displaying the results of the actual roll itself, the results for every die rolled are then added up and the total numerical value is displayed. (Example: If 4 Fudge dice are rolled the reult may be any combination between +4 to -4. A +4 result would be displayed as "(++++) +4" and a -4 would be displayed as "(----) -4" to the users.)
' Contact: VV_GM@Comcast.net
' ---History---
' July-01-2007 - Initial version of the script written. (P.Benson)
' July-02-2007 - Dice roll generator added. Help feature modified. (P.Benson)
' September-07-2007 - Randomizer set to generate a seed once for multiple fudge dice rolls, and to use the timer for greater randomness.
' Registers the command "/dF" with the ScreenMonkey API so that the command is avialable to users within chat. Establishes that the command calls the subprocedure FudgeDice and provides a simple description of what the command does.
#register /dF FudgeDice Rolls the number of Fudge dice specified by the user. Type "/dF ?" to see a detailed help message.
' Creates the subprocedure FudgeDice.
Sub FudgeDice()
' VBscript error handler that has the script continue to process even if an error occurs.
On Error Resume Next
' Declare local variables.
' Objects
oChat = GetChatSession() ' Returns a reference to the current Chat Session object. This will allow you to access the session.
oLine = oChat.GetLastItem() ' Returns the last Chat Item object that was added to chat. Needed to retrieve the information passed by the user with the command.
oSession = GetCurrentSession ' Returns a reference to the current session object. Once you have a reference to the session object, you can access it's properties and methods.
oPlayer = GetCurrentPlayer ' Returns the Player object that corresponds to the player that is making the request.
' Strings
sCommand = oLine.Text ' Takes the text of the oLine object and populates the string sCommand with it.
sError = "false" ' An error flag. The default value is false.
sHelpFlag = "false" ' A flag used to determine if the user has requested a detailed help message. The default value is false.
sResult = "(" ' The final result string that will be appended as needed.
' Integers
iDice = 0 ' The number of Fudge dice to be rolled.
iLen = 0 ' The length of the command given.
iTotal = 0 ' The total value of the dice roll.
iResult = 0 ' The result of a die roll
' Flag if the user requested the help feature if a question mark.
If Right(sCommand, 1) = "?" Then
sHelpFlag = "true"
End If
' Retrieve the number of Fudge dice to be rolled from the command line given by the user.
If sHelpFlag = "false" Then
RTrim(sCommand) ' Removes all trailing spaces from the sCommand string.
iLen = Len(sCommand) ' To remove the first four characters ("/dF ") of the command we need to know the total number of characters in the string and subtract four from that amount.
iDice = Right(sCommand, iLen) ' The number of dice to be rolled is the number given at the end of the command line.
End If
' Check to make sure that the user supplied a number for how many dice are to be rolled.
If IsNumeric(iDice) = False Then
sError = "true" ' Sets the error flag to true.
oLine.PlayerTo = oLine.PlayerFrom ' Sends the help message to the player who requested it.
oLine.Action = "entered an invalid /dF command"
oLine.Text = "Invalid /dF command. Please enter /dF ? to see a detailed help message on usage."
End If
' Check to make sure that the number of dice to be rolled is an integer.
If InStr(sCommand, ".") > 0 Then
sError = "true" ' Sets the error flag to true.
oLine.PlayerTo = oLine.PlayerFrom ' Sends the help message to the player who requested it.
oLine.Action = "entered an invalid /dF command"
oLine.Text = "Invalid /dF command. Please enter /dF ? to see a detailed help message on usage."
End If
' If the user requested the help message display it.
If sHelpFlag = "true" Then
oLine.PlayerTo = oLine.PlayerFrom ' Sends the help message to the player who requested it.
oLine.Action = "requested usage for the /dF command"
oLine.Text = "Enter /df followed by an integer. Decimals and non-numeric characters will not be accepted. Example: /df 4 rolls 4 Fudge dice."
' If the command syntax given is valid perform the requested command.
ElseIf sError = "false" Then
Randomize Timer ' Generate a new seed number for the Rnd function.
For i = 1 to iDice ' Perform the following once for every Fudge die to be rolled.
iHigh = 1 ' Sets the highest number desired from a roll.
iLow = -1 ' Sets the lowest number desired from a roll.
iResult = Int((iHigh - iLow + 1) * Rnd() + iLow) ' Generates a random number between -1 amd 1.
Select Case iResult ' Display a +, -, or o symbol based on the die roll result.
Case 1
sDie = "+"
Case 0
sDie = "o"
Case -1
sDie = "-"
End Select
sResult = sResult & sDie ' Append the sResult string with the die roll.
iTotal = iTotal + iResult ' Add the die roll to the total for all die rolls.
Next
If iTotal > 0 Then ' Append a positive symbol before the dice roll total for easy reading and append the dice roll to the sResult string.
sResult = sResult & ") " & "+" & iTotal
Else ' Append the dice roll total to the sResult string.
sResult = sResult & ") " & iTotal
End If
oLine.Action = "rolls " & iDice & "dF" ' Set the action.
oLine.Text = sResult ' Display the sResult string.
End If
End Sub