Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread of questions
#6
Ok, thanks1

Next up is about adding a thing for the players that allows them to choose if they want to display there map coordinates. And it saves their choice and and loads it up everytime they play (it is by character, not player). I have it working so that they can either type /pos to switch it to the opposite of what is was before or they can type /pos on or /pos off to set it to that. But, it doesn't save or load it, which is what I want.

(Sorry if it is a lot of code - I have been searching through code for hours to find a solution)

Peices parts...
::Server Side::
In modHandle Data -> Sub HandleData
Code:
' :::::::::::::::::::::::::::::::::
    ' :: Update Can Display Position ::
    ' :::::::::::::::::::::::::::::::::
    If LCase(Parse(0)) = "updatecandisplayposition" Then
        If Val(Parse(1)) = NO Then Call SetPlayerCanUpdateDisplayPosition(Index, NO)
        If Val(Parse(1)) = YES Then Call SetPlayerCanUpdateDisplayPosition(Index, YES)
        Call SavePlayer(Index)
        Exit Sub
    End If

In modDatabase -> SavePlayer
Code:
Sub SavePlayer(ByVal Index As Long)
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
        ' 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))
        
        ' Check to make sure that they aren't on map 0, if so reset'm
        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
            
        ' Position
        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
        
        ' Options
        Call PutVar(FileName, "CHAR" & i, "CanUpdateDisplayPosition", STR(Player(Index).Char(i).CanUpdateDisplayPosition))
    Next i
End Sub

In modDatabase -> LoadPlayer
Code:
Sub LoadPlayer(ByVal Index As Long, ByVal Name As String)
Dim FileName As String
Dim i As Long
Dim n As Long

    Call ClearPlayer(Index)
    
    FileName = App.Path & "\Accounts\" & Trim(Name) & ".ini"

    Player(Index).Login = GetVar(FileName, "GENERAL", "Login")
    Player(Index).Password = GetVar(FileName, "GENERAL", "Password")

    For i = 1 To MAX_CHARS
        ' General
        Player(Index).Char(i).Name = GetVar(FileName, "CHAR" & i, "Name")
        Player(Index).Char(i).Sex = Val(GetVar(FileName, "CHAR" & i, "Sex"))
        Player(Index).Char(i).Class = Val(GetVar(FileName, "CHAR" & i, "Class"))
        Player(Index).Char(i).Sprite = Val(GetVar(FileName, "CHAR" & i, "Sprite"))
        Player(Index).Char(i).Level = Val(GetVar(FileName, "CHAR" & i, "Level"))
        Player(Index).Char(i).Exp = Val(GetVar(FileName, "CHAR" & i, "Exp"))
        Player(Index).Char(i).Access = Val(GetVar(FileName, "CHAR" & i, "Access"))
        Player(Index).Char(i).PK = Val(GetVar(FileName, "CHAR" & i, "PK"))
        Player(Index).Char(i).Guild = Val(GetVar(FileName, "CHAR" & i, "Guild"))
        
        ' Vitals
        Player(Index).Char(i).HP = Val(GetVar(FileName, "CHAR" & i, "HP"))
        Player(Index).Char(i).MP = Val(GetVar(FileName, "CHAR" & i, "MP"))
        Player(Index).Char(i).SP = Val(GetVar(FileName, "CHAR" & i, "SP"))
        
        ' Stats
        Player(Index).Char(i).STR = Val(GetVar(FileName, "CHAR" & i, "STR"))
        Player(Index).Char(i).DEF = Val(GetVar(FileName, "CHAR" & i, "DEF"))
        Player(Index).Char(i).SPEED = Val(GetVar(FileName, "CHAR" & i, "SPEED"))
        Player(Index).Char(i).MAGI = Val(GetVar(FileName, "CHAR" & i, "MAGI"))
        Player(Index).Char(i).POINTS = Val(GetVar(FileName, "CHAR" & i, "POINTS"))
        
        ' Worn equipment
        Player(Index).Char(i).ArmorSlot = Val(GetVar(FileName, "CHAR" & i, "ArmorSlot"))
        Player(Index).Char(i).WeaponSlot = Val(GetVar(FileName, "CHAR" & i, "WeaponSlot"))
        Player(Index).Char(i).HelmetSlot = Val(GetVar(FileName, "CHAR" & i, "HelmetSlot"))
        Player(Index).Char(i).ShieldSlot = Val(GetVar(FileName, "CHAR" & i, "ShieldSlot"))
        
        ' Position
        Player(Index).Char(i).Map = Val(GetVar(FileName, "CHAR" & i, "Map"))
        Player(Index).Char(i).x = Val(GetVar(FileName, "CHAR" & i, "X"))
        Player(Index).Char(i).y = Val(GetVar(FileName, "CHAR" & i, "Y"))
        Player(Index).Char(i).Dir = Val(GetVar(FileName, "CHAR" & i, "Dir"))
        
        ' Check to make sure that they aren't on map 0, if so reset'm
        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
        
        ' Inventory
        For n = 1 To MAX_INV
            Player(Index).Char(i).Inv(n).Num = Val(GetVar(FileName, "CHAR" & i, "InvItemNum" & n))
            Player(Index).Char(i).Inv(n).Value = Val(GetVar(FileName, "CHAR" & i, "InvItemVal" & n))
            Player(Index).Char(i).Inv(n).Dur = Val(GetVar(FileName, "CHAR" & i, "InvItemDur" & n))
        Next n
        
        ' Spells
        For n = 1 To MAX_PLAYER_SPELLS
            Player(Index).Char(i).Spell(n) = Val(GetVar(FileName, "CHAR" & i, "Spell" & n))
        Next n
        
        Player(Index).Char(i).CanUpdateDisplayPosition = Val(GetVar(FileName, "CHAR" & i, "CanUpdateDisplayPosition"))
    Next i
End Sub

in modGameLogic
Code:
Function GetPlayerCanUpdateDisplayPosition(ByVal Index As Long) As Byte
    GetPlayerCanUpdateDisplayPosition = Player(Index).Char(Player(Index).CharNum).CanUpdateDisplayPosition
End Function

Sub SetPlayerCanUpdateDisplayPosition(ByVal Index As Long, OnOff As Byte)
    If OnOff = NO Then
        Player(Index).Char(Player(Index).CharNum).CanUpdateDisplayPosition = NO
    ElseIf OnOff = YES Then
        Player(Index).Char(Player(Index).CharNum).CanUpdateDisplayPosition = YES
    End If
End Sub

In modGameLogic -> ClearChar
Code:
Sub ClearChar(ByVal Index As Long, ByVal CharNum As Long)
Dim n As Long
    
    Player(Index).Char(CharNum).Name = ""
    Player(Index).Char(CharNum).Class = 0
    Player(Index).Char(CharNum).Sprite = 0
    Player(Index).Char(CharNum).Level = 0
    Player(Index).Char(CharNum).Exp = 0
    Player(Index).Char(CharNum).Access = 0
    Player(Index).Char(CharNum).PK = NO
    Player(Index).Char(CharNum).POINTS = 0
    Player(Index).Char(CharNum).Guild = 0
    
    Player(Index).Char(CharNum).HP = 0
    Player(Index).Char(CharNum).MP = 0
    Player(Index).Char(CharNum).SP = 0
    
    Player(Index).Char(CharNum).STR = 0
    Player(Index).Char(CharNum).DEF = 0
    Player(Index).Char(CharNum).SPEED = 0
    Player(Index).Char(CharNum).MAGI = 0
    
    For n = 1 To MAX_INV
        Player(Index).Char(CharNum).Inv(n).Num = 0
        Player(Index).Char(CharNum).Inv(n).Value = 0
        Player(Index).Char(CharNum).Inv(n).Dur = 0
    Next n
    
    For n = 1 To MAX_PLAYER_SPELLS
        Player(Index).Char(CharNum).Spell(n) = 0
    Next n
    
    Player(Index).Char(CharNum).ArmorSlot = 0
    Player(Index).Char(CharNum).WeaponSlot = 0
    Player(Index).Char(CharNum).HelmetSlot = 0
    Player(Index).Char(CharNum).ShieldSlot = 0
    
    Player(Index).Char(CharNum).Map = 0
    Player(Index).Char(CharNum).x = 0
    Player(Index).Char(CharNum).y = 0
    Player(Index).Char(CharNum).Dir = 0
    
    ' Options
    Player(Index).Char(CharNum).CanUpdateDisplayPosition = NO
    End Sub

In modTypes -> PlayerRec
Code:
CanUpdateDisplayPosition As Byte

::Client Side::
In modClientTCP
Code:
Sub UpdateCanDisplayPosition(ByVal OnOff As Byte)
Dim Packet As String

    Packet = "CANUPDATEDISPLAYPOSITION" & SEP_CHAR & STR(OnOff) & END_CHAR
    Call SendData(Packet)
End Sub

In modGameLogic -> GameLoop
Code:
' Blit the player's map coordinates
        If GetPlayerCanUpdateDisplayPosition(MyIndex) = YES Then
            Call DrawText(TexthDC, 5, 20, "Map(x,y): " & GetPlayerMap(MyIndex) & "(" & GetPlayerX(MyIndex) & "," & GetPlayerY(MyIndex) & ")", QBColor(White))
        End If

in modGameLogic -> HandlKeyPresses
Code:
' Checking Coordinates
        If LCase$(Mid$(MyText, 1, 4)) = "/pos" Then
            ChatText = vbNullString
            If Len(MyText) > 4 Then
                ChatText = LCase$(Mid$(MyText, 6, Len(MyText) - 1))
            End If
            
            If ChatText = vbNullString Then
                If GetPlayerCanUpdateDisplayPosition(MyIndex) = NO Then
                    Call SetPlayerCanUpdateDisplayPosition(MyIndex, YES)
                ElseIf GetPlayerCanUpdateDisplayPosition(MyIndex) = YES Then
                    Call SetPlayerCanUpdateDisplayPosition(MyIndex, NO)
                End If
            Else
                If ChatText = "on" Then
                    Call SetPlayerCanUpdateDisplayPosition(MyIndex, YES)
                ElseIf ChatText = "off" Then
                    Call SetPlayerCanUpdateDisplayPosition(MyIndex, NO)
                End If
            End If
            
            Call UpdateCanDisplayPosition(GetPlayerCanUpdateDisplayPosition(MyIndex))
            
            MyText = vbNullString
            ChatText = vbNullString
            Exit Sub
        End If

In modGameLogic
Code:
Function GetPlayerCanUpdateDisplayPosition(ByVal Index As Long) As Byte
    GetPlayerCanUpdateDisplayPosition = Player(Index).CanUpdateDisplayPosition
End Function

Sub SetPlayerCanUpdateDisplayPosition(ByVal Index As Long, OnOff As Byte)
    If OnOff = NO Then
        Player(Index).CanUpdateDisplayPosition = NO
    ElseIf OnOff = YES Then
        Player(Index).CanUpdateDisplayPosition = YES
    End If
End Sub

In modGameLogic -> ClearPlayer
Code:
Sub ClearPlayer(ByVal Index As Long)
Dim i As Long
Dim n As Long

    Player(Index).Name = ""
    Player(Index).Class = 0
    Player(Index).Level = 0
    Player(Index).Sprite = 0
    Player(Index).Exp = 0
    Player(Index).Access = 0
    Player(Index).PK = NO
        
    Player(Index).HP = 0
    Player(Index).MP = 0
    Player(Index).SP = 0
        
    Player(Index).STR = 0
    Player(Index).DEF = 0
    Player(Index).SPEED = 0
    Player(Index).MAGI = 0
        
    For n = 1 To MAX_INV
        Player(Index).Inv(n).Num = 0
        Player(Index).Inv(n).Value = 0
        Player(Index).Inv(n).Dur = 0
    Next n
        
    Player(Index).ArmorSlot = 0
    Player(Index).WeaponSlot = 0
    Player(Index).HelmetSlot = 0
    Player(Index).ShieldSlot = 0
        
    Player(Index).Map = 0
    Player(Index).x = 0
    Player(Index).y = 0
    Player(Index).Dir = 0
    
    ' Client use only
    Player(Index).MaxHP = 0
    Player(Index).MaxMP = 0
    Player(Index).MaxSP = 0
    Player(Index).XOffset = 0
    Player(Index).YOffset = 0
    Player(Index).Moving = 0
    Player(Index).Attacking = 0
    Player(Index).AttackTimer = 0
    Player(Index).MapGetTimer = 0
    Player(Index).CastedSpell = NO
    
    ' Options
    Player(Index).CanUpdateDisplayPosition = NO
End Sub

In modTypes -> PlayerRec
Code:
CanUpdateDisplayPosition As Byte
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)