Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Improve Server Saving
#4
Sweet tutorial Big Grin

I modified it so that it uses the existing SavePlayer sub using an optional variable.

Basically, change your tmrPlayerSave code to

Code:
Private Sub tmrPlayerSave_Timer()
Static MinPassed As Long
Dim i As Byte 'make it long if MAX_PLAYERS > 255

    MinPassed = MinPassed + 1
  
    If MinPassed >= 5 And MinPassed < 10 Then
        If TotalOnlinePlayers > 0 Then
            Call GlobalMsg("Saving 1/2 of the player..", Yellow)
            For i = 1 To max_players 'use High_Index if you added that tut
                If IsPlaying(i) Then
                    Call SavePlayer(i, 1)
                    DoEvents
                End If
            Next i
        End If
        MinPassed = 10
    End If

    If MinPassed >= 15 Then
        If TotalOnlinePlayers > 0 Then
            Call GlobalMsg("Saving 2/2 of the player..", Yellow)
            For i = 1 To max_players 'use High_Index if you added that tut
                If IsPlaying(i) Then
                    Call SavePlayer(i, 2)
                    DoEvents
                End If
            Next i
        End If
        MinPassed = 0
    End If
End Sub

and then modify your save player code to look like this :

Code:
Sub SavePlayer(ByVal Index As Long, Optional IsHalf As Byte)
Dim FileName As String
Dim i As Long
Dim n As Long

    FileName = App.Path & "\Accounts\" & Trim$(Player(Index).Login) & ".ini"
    
    Call PutVar(FileName, "GENERAL", "Login", Trim$(Player(Index).Login))
    Call PutVar(FileName, "GENERAL", "Password", Trim$(Player(Index).Password))

    For i = 1 To MAX_CHARS
        
            If IsHalf = 0 Or IsHalf = 1 Then
                ' General
                Call PutVar(FileName, "CHAR" & i, "Name", Trim$(Player(Index).Char(i).Name))
                Call PutVar(FileName, "CHAR" & i, "Class", STR(Player(Index).Char(i).Class))
                Call PutVar(FileName, "CHAR" & i, "Sex", STR(Player(Index).Char(i).Sex))
                Call PutVar(FileName, "CHAR" & i, "Sprite", STR(Player(Index).Char(i).Sprite))
                Call PutVar(FileName, "CHAR" & i, "Level", STR(Player(Index).Char(i).Level))
                Call PutVar(FileName, "CHAR" & i, "Exp", STR(Player(Index).Char(i).Exp))
                Call PutVar(FileName, "CHAR" & i, "Access", STR(Player(Index).Char(i).Access))
                Call PutVar(FileName, "CHAR" & i, "PK", STR(Player(Index).Char(i).PK))
                Call PutVar(FileName, "CHAR" & i, "Guild", STR(Player(Index).Char(i).Guild))
                
                ' Vitals
                Call PutVar(FileName, "CHAR" & i, "HP", STR(Player(Index).Char(i).HP))
                Call PutVar(FileName, "CHAR" & i, "MP", STR(Player(Index).Char(i).MP))
                Call PutVar(FileName, "CHAR" & i, "SP", STR(Player(Index).Char(i).SP))
                
                ' Stats
                Call PutVar(FileName, "CHAR" & i, "STR", STR(Player(Index).Char(i).STR))
                Call PutVar(FileName, "CHAR" & i, "DEF", STR(Player(Index).Char(i).DEF))
                Call PutVar(FileName, "CHAR" & i, "SPEED", STR(Player(Index).Char(i).SPEED))
                Call PutVar(FileName, "CHAR" & i, "MAGI", STR(Player(Index).Char(i).MAGI))
                Call PutVar(FileName, "CHAR" & i, "POINTS", STR(Player(Index).Char(i).POINTS))
                
                ' Worn equipment
                Call PutVar(FileName, "CHAR" & i, "ArmorSlot", STR(Player(Index).Char(i).ArmorSlot))
                Call PutVar(FileName, "CHAR" & i, "WeaponSlot", STR(Player(Index).Char(i).WeaponSlot))
                Call PutVar(FileName, "CHAR" & i, "HelmetSlot", STR(Player(Index).Char(i).HelmetSlot))
                Call PutVar(FileName, "CHAR" & i, "ShieldSlot", STR(Player(Index).Char(i).ShieldSlot))
            End If
        
            ' Check to make sure that they aren't on map 0, if so reset'm
            If IsHalf = 0 Then
                If Player(Index).Char(i).Map = 0 Then
                    Player(Index).Char(i).Map = START_MAP
                    Player(Index).Char(i).X = START_X
                    Player(Index).Char(i).y = START_Y
                End If
            End If
            
        ' Position
            If IsHalf = 0 Or IsHalf = 2 Then
                Call PutVar(FileName, "CHAR" & i, "Map", STR(Player(Index).Char(i).Map))
                Call PutVar(FileName, "CHAR" & i, "X", STR(Player(Index).Char(i).X))
                Call PutVar(FileName, "CHAR" & i, "Y", STR(Player(Index).Char(i).y))
                Call PutVar(FileName, "CHAR" & i, "Dir", STR(Player(Index).Char(i).Dir))
                
                ' Inventory
                For n = 1 To MAX_INV
                    Call PutVar(FileName, "CHAR" & i, "InvItemNum" & n, STR(Player(Index).Char(i).Inv(n).Num))
                    Call PutVar(FileName, "CHAR" & i, "InvItemVal" & n, STR(Player(Index).Char(i).Inv(n).Value))
                    Call PutVar(FileName, "CHAR" & i, "InvItemDur" & n, STR(Player(Index).Char(i).Inv(n).Dur))
                Next n
                
                ' Spells
                For n = 1 To MAX_PLAYER_SPELLS
                    Call PutVar(FileName, "CHAR" & i, "Spell" & n, STR(Player(Index).Char(i).Spell(n)))
                Next n
            End If

    Next i
End Sub

Basically this does it so that there is an optional byte added. If you do not put any value in it, it will save everything for the player. If you put a 1, it will save the first half. If you put a 2, it will save the second half. Don't worry, this will work with your existing Call SavePlayer calls, so you don't have to change them.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)