Page 1 of 1

#1 Help Hotfoot Run SilCORE

Posted: Fri Jan 01, 2010 10:36 pm
by Hotfoot
Okay, so I want to be able to run SilCORE through screenmonkey, but my coding skills have regressed to the point of suck.

Now the board has a good code for rolling SilCORE D6, but screenmonkey does not, and I was wondering if anyone could help me turn the following script into a SilCORE roller for screenmonkey.

Code: Select all

'Star Wars D6 Roller by theMagius
'Contact: theMagius@gmail.com
'For usage instructions, type "/roll help" in the chat window.
'Please report errors to theMagius@gmail.com

#register /jedi StarWarsD6
#register /sw StarWarsD6 Star Wars D6 by theMagius. Type "/roll help" to view help information.
 
' The format for the die rolls in Star Wars D6 is: <number>D<+><pip(s)>
'
' If the wild die rolls a 1, capture the highest-rolled number in the batch
' If the wild die rolls a 6, keep rolling it
'
' The total roll is <wild die> + <all other dice> + <pip(s)> - <die penalty>

Sub StarWarsD6()
    On Error Resume Next

    ' local variables
	cs = GetChatSession()
	ci = cs.GetLastItem()
	os = GetCurrentSession()
	pc = GetCurrentPlayer()

    ' get last entered command
    ci.Text = LCase(Ci.Text)

	RollAction = 0

    ' if first five characters are help, user is requesting text info
	ActionCheck = Left(ci.Text, 5)

	If ActionCheck = " help" Then
		RollAction = 2
	End If

	If RollAction = 2 Then
        ' if user requested help info, show info
		ci.PlayerTo = ci.PlayerFrom
		ci.Action = "requested help information for /sw"
		ci.Text = "<DD>All <B>/sw</b> commands can also be called with <B>/jedi</B>."
		ci.Text = ci.Text + "The format is: <i>1D</i>, <i>2D</i>, <i>1D+1</i>, <i>2D+1</i>, etc."

		ElseIf RollAction = 0 Then
        ' else, if rolling dice
        ' find the D character in the string
		DInd = inStr(ci.Text, "d")

        ' if the command was not formatted correctly, tell user
		If DInd = 0 Then
					ci.PlayerTo = ci.PlayerFrom
					ci.Action = "attempted to use the /sw command"
					ci.Text = "Invalid command."
		Else
		' find the + character in the string
		PlusInd = inStr(ci.Text, "+")

			If PlusInd >< 0 Then
				ModInd = PlusInd
				ModType = "+"
			End If

			' find the - character in the string
			MinInd = inStr(ci.Text, "-")

			If MinInd >< 0 Then
				ModInd = MinInd
				ModType = "-"
			End If

			' get the number of dice being rolled
			MidLen = DInd - 1
			DiceNum = Mid(ci.Text, 1, MidLen)

			If ModInd >< 0 Then
				' if there's a + or - in the die roll
				' get the number of characters for the die type
				MidLen = ModInd - 1 - DInd                                
			Else
				' else, we're just rolling a plain number
				' get the number of characters for the die type
				MidLen = Len(ci.Text) - DInd
			End If

			If ModInd >< 0 Then
				' if there's a + or -
				' capture the + or - modifier
				MidLen = Len(ci.Text) - ModInd
				MidStart = ModInd + 1
				ModNum = Mid(ci.Text, MidStart, MidLen)
			Else
				' else, there's no + or -   
				ModNum = "0"
			End If

            ' now that we've captured all the + and - numbers, set up the expression
			Dice = CInt(DiceNum - 1)                ' ???
			SingleDie = "1d6"
			Sides = 6
            Penalty = 0
            Tame = 0
            Highest = 0
			Modifier = CInt(ModNum)
                       
			If ModNum = "0" Then
				Expression = DiceNum + "D" + SidesNum
			End If
		   
			If ModNum >< "0" Then
				Expression = DiceNum + "D" + SidesNum + ModType + ModNum
			End If
   
            ' start with a fresh roll result line
			ci.Text = ""
   
            ' no matter what, we ALWAYS roll a wild die
			RollNow = EvalDice(SingleDie)

			If RollNow = 1 Then
				Penalty = 1
			End If
			
			AddTimes = 1
			BestRoll = AddTimes * Sides

			' continue rolling the wild die if it was a 6
			Do While RollNow = BestRoll
				If RollNow = BestRoll Then
							RollNew = EvalDice(SingleDie)
							RollNow = RollNow + RollNew
				End If
			   
				AddTimes = AddTimes + 1
				BestRoll = AddTimes * Sides
			Loop

            ' keep track of what we rolled on the wild die
            Wild = RollNow				
 
            ' loop until all dice are rolled
			Do While Dice > 0
				' roll a single die, without any modifiers
				ci.Text = ci.Text + " "
				RollNow = EvalDice(SingleDie)
   
				' mark off that a single die was rolled
				Dice = Dice - 1
	
				' keep track of the highest roll (for penalty purposes)
				If RollNow > Highest Then
					Highest = RollNow
				End If   
		   
				' update the total roll result
				Tame = Tame + RollNow
			Loop
			
			' apply penalty if we rolled a 1 on the wild die
            If Penalty = 1 Then
				Tame = Tame - Highest
			End If
   
            ' now that all the dice have been rolled and tallied, +/- any modifiers
			If ModType = "+" Then
				RollTotal = Wild + Tame + Modifier
			ElseIf ModType = "-" Then
				RollTotal = Wild + Tame - Modifier
			Else
				RollTotal = Wild + Tame
			End If
			
			' in case we went negative (2d case with high tame die)
			If RollTotal < 1 Then
				RollTotal = 1
			End If
   
            ' print the original roll expression to the screen
			ci.Action = "rolls " + Expression
			ci.Text = ci.Text

			' format the output line
'			ci.Text = ci.Text + "Wild is: " + CStr(Wild)
'			ci.Text = ci.Text + ", Tame is: " + CStr(Tame)   
'			ci.Text = ci.Text + ", Modifier is: " + CStr(Modifier)   
'			ci.Text = ci.Text + ", Highest is: " + CStr(Highest)   
'			ci.Text = ci.Text + ", Total is: " + CStr(RollTotal)

			ci.Text = ci.Text + "(<font color=red>" + Cstr(Wild) + "</font>"
			
			If Tame >< 0 Then
				ci.Text = ci.Text + "+" + CStr(Tame)
			End If
			
			If Modifier >< 0 Then
				If ModType = "+" Then
					ci.Text = ci.Text + "+" + Cstr(Modifier)
				Else
					ci.Text = ci.Text + "-" + Cstr(Modifier)
				End If
				
			End If
			
			if pc.isGM = True Then
				ci.Text = ci.Text + ") <b><font color=green>=> " + Cstr(RollTotal) + " <=</font></b>"
			Else
				ci.Text = ci.Text + ") => <b>" + Cstr(RollTotal) + "</b>"
			End If
			
		End If
	End If 
End Sub
Anyone?

#2

Posted: Mon Jan 11, 2010 11:22 am
by Brother-Captain Gaius
hissssssss it has no bracketses precious, burns it, BURNS IT

Seriously though, you may have to be more specific. I can recognize the code but I'm not exactly sure what you're trying to do. I see a big huge script with eye-bleeding formatting which I can reasonably assume rolls dice. How exactly do you want to modify this?

#3

Posted: Mon Jan 11, 2010 11:56 am
by Hotfoot
Right now the script runs under the mechanic of "roll Xd6 as (X-1)d6 + 1d6 with a chance of exploding or removing one of the highest dice, plus or minus modifiers".

SILCORE rules are "roll Xd6, pick highest, add or remove modifiers, if rolling 0d6, roll 2 and pick lowest, with a trend of -1d6 = 3d6 pick lowest and so on. Each 6 past the first adds +1 to the overall total*"

*If a cinematic variant is possible with adding +1 for the highest double, that would be awesome but uncessary

#4

Posted: Mon Jan 11, 2010 12:40 pm
by Brother-Captain Gaius
*Note - don't mind me, just doodling out the algorithm here all C-like so I can translate it over to this scripting language (poorly formatted languages make me nauseous to work with). WIP, will edit and add to as I have time.


if (standard Xd6 roll)

Code: Select all

int highRoll = 0;
int result = 0;
int bonus = -1;

for (int i = 0; i < numDice; i++)
{
     int roll = RollD6();

     if (roll == 6)
     {
          bonus++;
     }
     
     if (roll > highRoll)
     {
          highRoll = roll;
     }
}

// modifier assumed to be entered by user previously
// string parsed, reads modifier, multiplied by -1 if '-' token found
result = highRoll + modifier;

if (bonus > 0)
{
     result = result + bonus;
}

else if (zero or negative d6 roll)

Code: Select all

int lowRoll = 6;
int result = 0;
int bonus = -1;

numDice = (numDice * -1) + 2;

for (int i = 0; i < numDice; i++)
{
     int roll = RollD6();

     if (roll == 6)
     {
          bonus++;
     }
     
     if (roll < lowRoll)
     {
          lowRoll = roll;
     }
}

// modifier assumed to be entered by user previously
// string parsed, reads modifier, multiplied by -1 if '-' token found
result = lowRoll + modifier;

if (bonus > 0)
{
     result = result + bonus;
}
That should cover all the rolling logic, except for the cinematic variant which can be added later.

Next step: putting this into the script.

#5

Posted: Fri Jan 15, 2010 10:10 pm
by Destructionator XV
Work has been crazy recently, but I just took a quick look at this.

edit: replies posted since I last looked, yay. I think I know where to take it, just need to find the time to write it up.

#6

Posted: Wed Mar 03, 2010 10:23 pm
by Hotfoot
It's been a while, and while I've not exactly been very well, I'm interested in knowing if there has been any movement here.

#7

Posted: Wed Mar 03, 2010 10:29 pm
by Destructionator XV
I got busy and forgot all about it :S

It isn't really my area of expertise though.

#8

Posted: Sat Mar 13, 2010 4:25 pm
by Brother-Captain Gaius
Sorry - I too have been pretty busy with other things. The good news is I am on my (pitifully short) break and might find some time to finish the job in the next few days!

Basically it's a battle between my own boredom and my loathing for the language it uses.

#9

Posted: Tue Mar 30, 2010 11:02 pm
by Brother-Captain Gaius
Update; I apologize for the continued wait. I still plan on finishing it, I just haven't found the time. This week has been very busy so it may still be awhile yet.