Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with code
#1
I've been trying to get spell buffs to work for some time now but to no avail. Setting up the spell and adjusting the stats I can do, but there needs to be some sort of timer so that the stat goes back to normal, and an on/off flag to tell the code that the spell is currently active (So it can't be used again until the timer runs out).

Any help would be much appreciated. Thanks.
Reply
#2
Add a variable to the temp player rec to store the timer for the buffer. Make it an array or w/e, so you can set a max amount of buffs per player.

Then check that timer in the loop and if it's true, give it the stat bonuses, if it's not, take them away.
Reply
#3
not sure I understand you.

I want them to activate the buff using a spell, then after 30 seconds, it goes back to normal again. I want these spells to be used on other players as well as yourself.
Reply
#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
#5
Steve, I think learning more about GetTickCount will solve most of the problems you're having.

http://www.codebeach.com/tutorials/high ... -basic.asp
Reply
#6
Very true Rian, thanks lol.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)