1.

Solve : Help with VBScript?

Answer»

Hello,

This would probably be a pretty easy fix for a knowledgeable individual but it isn't for a beginner like me.

I simply would like the output of the following game script to DISPLAY on two columns.

Many thanks to anyone who would take time to help me out.

MX

Code: [Select]Sub Init
cs = GetChatSession()
ci = cs.GetLastItem()

ci.Text = Trim( ci.Text)
If Len( ci.Text) > 0 Then
RollInit
Else
ShowInits
End If
End Sub


Sub RollInit
cs = GetChatSession()
ci = cs.GetLastItem()

sLine = ci.Text
ci.Text = sLine & "<i>[Command not understood<br> - use<br><ul><li>/init<li>/init player_name<li>/init player_name<li>dice_expression<li>/init player_name, number</ul>]</i>"

sChar = ""
nBonus = 0
sBonus = ""



n = InStr( sLine, ",")
If n > 0 Then
sChar = Trim( Left( sLine, n-1))
sBonus = Trim( Mid( sLine, n+1))
If Len( sBonus) > 0 Then
nBonus = EvalDice( sBonus)
End If
'If IsNumeric( sBonus) Then
' nBonus = CInt( sBonus)
'End If
Else
sChar = Trim( sLine)
End If

oPlayer = GetCurrentPlayer()
'If oPlayer <> NULL Then
If NotNull( oPlayer) Then
oChar = oPlayer.GetCharacter( sChar)
If NotNull( oChar) Then
If Len( Trim( sBonus)) < 1 Then
sBonus = "1d20"
End If
nInit = EvalDice( sBonus)
oChar.SetField "initroll", CStr( nInit)

If InStr( LCase(sBonus), "d") < 1 Then
ci.Text = sChar & " SETS initiative to <b>" & CStr( nInit) & "</b>"
Else
ci.Text = sChar & " rolls <b>" & CStr( nInit) & "</b> for initiative (" & sBonus & ")"
End If
Else
ci.Text = "init " & sLine & "<i>Unknown Character '" & sChar & "'</i>"
End If
Else
ci.Text = "init " & sLine & "<i>No Current Player</i>"
End If
End Sub


Sub ShowInits
cs = GetChatSession()
ci = cs.GetLastItem()
os = GetCurrentSession()

DIM aInitList(200)
Dim nInitCount

nInitCount = 0

os.Sync
n = os.GetSyncCharCount()
For i = 1 to n
c = os.GetSyncChar( i)
sInit = c.GetField( "initroll")
If Len( Trim( sInit)) > 0 Then
sInit = String(3 - Len( sInit), "0") & sInit
aInitList(nInitCount) = sInit & "  " & c.Name
nInitCount = nInitCount + 1
End If
Next

If nInitCount > 0 Then
QuickSort aInitList, nInitCount+1, false
End If


r = r & "<br><font color='" & os.GM.ChatColor & "'>"

sInitDice = os.GetField( "initdice")
If Len( sInitDice) > 0 Then
r = r & "(init dice set to: " & sInitDice & ")<br>"
End If


'r = r & "<br>Current Inits are...<br>"
For i = 1 to nInitCount
'trim away leading zeros
sInit = Left( aInitList(i-1), 3)
If Left( sInit, 1) = "0" Then
sInit = " " & Mid( sInit, 2)
End If

If Left( sInit, 2) = " 0" Then
sInit = "  " & Mid( sInit, 3)
End If

r = r & sInit & Mid( aInitList(i-1), 4) & "<br>"
Next
r = r & "</font>"

ci.PlayerTo = ci.PlayerFrom
ci.PlayerFrom = "Current Initiatives are"
ci.Action = ""
ci.Text = r
End Sub

Sub ClearInits
cs = GetChatSession()
ci = cs.GetLastItem()
os = GetCurrentSession()

op = GetCurrentPlayer()
If op.IsGM Then
os.Sync
n = os.GetSyncCharCount()
For i = 1 to n
c = os.GetSyncChar( i)
sInit = c.GetField( "initroll")
If Len( Trim( sInit)) > 0 Then
c.SetField "initroll", ""
End If
Next

ci.Action = "reports"
ci.Text = "initiatives cleared"
Else
ci.PlayerTo = ci.PlayerFrom
ci.Text = "<i>[Sorry, only the GM can clear the initiatives!]</i>"
End If

End Sub



Sub SetInitModifier
cs = GetChatSession()
ci = cs.GetLastItem()

sChar = ""
sMod = ""
bSet = False


'Get command line
aLine = Split( ci.Text, ",")
If UBound( aLine) > -1 Then
sChar = Trim( aLine(0))
End If
If UBound( aLine) > 0 Then
sMod = Trim( aLine(1))
End If


oPlayer = GetCurrentPlayer()
If NotNull( oPlayer) Then
oChar = oPlayer.GetCharacter( sChar)
If NotNull( oChar) Then
oChar.SetField "initmod", sMod
bSet = true
End If
End If

If bSet Then
ci.Text = sChar & " sets init modifier to " & sMod
Else
ci.Text = ci.Text & "<i>[Command not understood, or you're trying to set the initiative modifier for a character that is not yours]</i> " & sChar & sMod
End If


End Sub

Sub InitSelected
RollInitsSelected( False)
End Sub

Sub InitAll
RollInitsSelected( True)
End Sub

Sub RollInitsSelected( bAll)
cs = GetChatSession()
ci = cs.GetLastItem()
os = GetCurrentSession()
sLine = ""
sInitDice = ""


sInitDice = os.GetField( "initdice")
If Len( sInitDice) < 1 Then
sInitDice = "1d20"
End If

op = GetCurrentPlayer()
If op.IsGM Then
os.Sync
n = os.GetSyncCharCount()
For i = 1 to n
c = os.GetSyncChar( i)
If (bAll = true) or (c.Selected = true) Then
sMod = c.GetField( "initmod")
nMod = 0
If IsNumeric( sMod) Then
nMod = CInt( sMod)
End If
nInit = EvalDice( sInitDice)
nInit = nInit + nMod
c.SetField "initroll", CStr( nInit)
'sLine = sLine & CStr( nInit) & " " & c.Name & " (" & CStr( nMod) & " modifier)<br>"
End If
Next
ShowInits
ci.PlayerFrom = "TheGM rolls for initiative"
'ci.Action = "reports"
'ci.Text = "<br>Initiative(s) rolled<br>" & sLine
Else
ci.PlayerTo = ci.PlayerFrom
ci.Text = "<i>[Sorry, only the GM can do that!]</i>"
End If

End Sub


Sub SetInitDice
cs = GetChatSession()
ci = cs.GetLastItem()
os = GetCurrentSession()
sLine = ""

op = GetCurrentPlayer()
If op.IsGM Then
os.SetField "initdice", ci.Text
ci.Action = "sets initiative dice type to " + ci.Text
Else
ci.PlayerTo = ci.PlayerFrom
ci.Text = "<i>[Sorry, only the GM can do that!]</i>"
End If

End Sub

'==== Sorting Routines found on Usenet =====
'Just call QuickSort with Array and its size
'and True for Ascending False for descending
Function QuickSort(strAr, nSize, bAscending)
 rc = TRUE
 If (nSize > 1) Then
  low = 0
  high = nSize
  'Call the QuickSort Recursive Function
  QuickSortRecursive strAr,low,high,bAscending
 Else
  rc = FALSE
 End If
 QuickSort =  rc
End Function

'==================== QUICK SORT RECURSIVE
Function QuickSortRecursive(strAr,  d, h, bAscending)
 i = h
 j = d

 str = strAr(((d+h) / 2))
 do
  If (bAscending) Then
   while (strAr(j) < str)
    j = j + 1
   wend
   while (strAr(i) > str)
    i = i - 1
   wend
  Else
   while (strAr(j) > str) j = j + 1
   wend
   while (strAr(i) < str) i = i - 1
   wend
  End If

  If ( i >= j ) Then
   If ( i <> j ) Then
    zal = strAr(i)
    strAr(i) = strAr(j)
    strAr(j) = zal
   End If

   i = i - 1
   j = j + 1
  End If
 loop while (j <= i)

 If (d < i) Then
  QuickSortRecursive strAr,d,i,bAscending
 End If
 If (j < h) Then
  QuickSortRecursive strAr,j,h,bAscending
 End If
End Function

I could probably help you if this was a normal vbs, but I can't figure out how to run it. Can you explain how this works? Should it be in a web PAGE or something? Quote from: Linux711 on January 14, 2012, 01:00:01 PM

I could probably help you if this was a normal vbs, but I can't figure out how to run it. Can you explain how this works? Should it be in a web page or something?

Yes actually, the output displays in a chat window of a web browser.

Thank you for TAKING the time whether you do find a solution or not.


Discussion

No Comment Found