Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with code
#4
I suggest doing something like this...all pseudo code I just typed up in this post.

Make an array for much easier server looping. Like this:

Code:
Public SpellBuff(1 To 1) As SpellBuffRec

Type SpellBuffRec
    Alive As Boolean
    Owner As Long
    Timer As Long
End Type

Then when the player casts the spell, do something like this:

Code:
If UBound(SpellBuff) > 1 Then
    ReDim Preserve SpellBuff(1 To UBound(SpellBuff) + 1)
End if

With SpellBuff(UBound(SpellBuff))
    .Alive = True
    .Owner = Index
    .Timer = GetTickCount + Spell(SpellNum).BuffTime
End With

Something like that?

Then the server would loop like this:

Code:
For i = 1 to UBound(SpellBuff)
    If SpellBuff(i).Alive Then
        If SpellBuff(i).Owner > 0 Then
            If SpellBuff(i).Timer < GetTickCount Then
                'set the players stats to normal, destroy the spell buff array
                If UBound(SpellBuff) > 1 Then
                    ReDim Preserve SpellBuff(UBound(SpellBuff) - 1)
                Else
                    ReDim SpellBuff(1)
                End If
            End If
        End If
    End If
Next

Of course there's problems with taking down a piece of the array...example: Spell buff 1 finishes, but there's a spell buff 2 and 3...since the UBound is 3 for the array, spell buff 3 gets taken down. You'll need to make some adjusting code that moves all the array data down a notch to fix the problem. Eh I'm bored...something like this:

Code:
Sub AdjustBuffArray(ByVal Index As Long)
Dim I As Long

    If Index  UBound(SpellBuff) Then
        For I = Index To UBound(SpellBuff) - 1
            SpellBuff(I) = SpellBuff(I + 1)
        Next
    End If
    
    ReDim Preserve SpellBuff(UBound(SpellBuff) - 1)

End Sub

Something like that maybe? Then:

Code:
If UBound(SpellBuff) > 1 Then
                    AdjustBuffArray i
                Else
                    ReDim SpellBuff(1)
                End If

Not sure about it all but I hope you get the idea.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)