Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Score Board
#1
I browsed through quickly, and i found that you used a new function that you didnt provide the code for.. GetScore.. Also, you didnt declare a new player variable.. Score.. Look at the code for GetPlayerStr and look at your types module.. :wink: There might be a couple of other things..

In future, dont provide just code and tell us it doesnt work.. Explain the problems you are having and what errors are popping up.. It makes life easier for us.. :wink:

Thanks dude..
Reply
#2
Okay, think I've got it. This is basically what I thought you were trying to do, by having each player have a score, and then having a scoreboard to display it on. So here goes.

::::::::::::::::::::::
:: SERVER SIDE ::
::::::::::::::::::::::

In ModDatabase find "Sub LoadPlayer" and add this:
Code:
Player(Index).Char(Player(Index).CharNum).Score = GetVar(FileName, "CHAR" & i, "Score")

then find "Sub SavePlayaer" and add this:
Code:
Call PutVar(FileName, "CHAR" & i, "Score")

Now add the following subs to the bottom of your ModDatabase, delete any of the subs you have written previously:
Code:
Sub LoadScore()
Dim FileName As String
Dim i As Long

    Call CheckScore
  
    FileName = App.Path & "\data\score.ini"
  
    Call ClearScore
  
    For i = 0 To MAX_PLAYERS
        Score(i).Score = GetVar(FileName, "SCORE" & i, "Score")
        Score(i).Name = GetVar(FileName, "SCORE" & i, "Name")
        DoEvents
    Next i
End Sub

Sub SaveScore()
Dim FileName As String
Dim i As Long

    Call UpdateScores

    FileName = App.Path & "\data\score.ini"
  
    For i = 0 To MAX_PLAYERS
        Call PutVar(FileName, "SCORE" & i, "Name", Score(i).Name)
        Call PutVar(FileName, "SCORE" & i, "Score", Score(i).Score)
    Next i
End Sub

Sub CheckScore()
    If Not FileExist("data\score.ini") Then
        Call SaveScore
    End If
End Sub

In modGameLogic, Add these three subs:
Code:
Sub ClearScore()
Dim i As Long
    For i = 1 To MAX_PLAYERS
        Score(i).Name = vbNullString
        Score(i).Score = vbNullString
    Next i
End Sub

Sub UpdateScores()
Dim i As Long
    For i = 1 To MAX_PLAYERS
        Score(i).Name = Player(i).Char(Player(i).CharNum).Name
        Score(i).Score = Player(i).Char(Player(i).CharNum).Score
    Next i
End Sub

Function GetScore(ByVal Index As Long) As Long
    GetScore = Player(Index).Char(Player(Index).CharNum).Score
End Function

in modServerTCP, add this:
Code:
Sub SendScoreList(ByVal Index As Long)
Dim packet As String
Dim i As Long
Dim n As Long

    Call UpdateScores

    packet = "SCORELIST"
    
    n = 0
    
    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) Then
            packet = packet & SEP_CHAR & GetPlayerName(i) & SEP_CHAR & GetScore(i) & SEP_CHAR
        End If
    Next i

    packet = packet & END_CHAR

    Call SendDataToAll(packet)
End Sub

in modTypes, add this:
Code:
Type ScoreRec
    Name As String
    Score As String
End Type

Also in modTypes, find "Type PlayerRec", and add this line to it:
Code:
Score As String

in modGlobals add this:
Code:
Public Score(1 To MAX_PLAYERS) As ScoreRec

in modHandleData, add this: (you allready have it I'm assuming)
Code:
' :::::::::::::::::
    ' :: Score list ::
    ' :::::::::::::::::
    If LCase(Parse(0)) = "scorelist" Then
        'Stop
        Call SendScoreList
        Exit Sub
    End If

That's it for the server side. Now I'll explain it to you.

Basically what I did was remove the MAX_SCORE command all together. Because of how I chose to set this code up, if MAX_PLAYERS and MAX_SCORE weren't the same it would probably cause all kinds of errors, or just give undesired results. So I took it out, and Used MAX_PLAYERS as my "to" variable.

When LoadScores is called, it loads the saved scores from the ini file which is what we want it to do. When SaveScores is called, it makes a call to UpdateScores. This goes through every player in the game and reassigns the data to the .Name and .Score variables in the ScoreRec, then it saves them. This allows the scoreboard variables to be saved, and the players to each have their own personal scores recorded as well in their player file.

Now, the other things added up to this point do the sending and recieveing of the scoreboard from the server to the client.

So moving on...

:::::::::::::::::::::
:: CLIENT SIDE ::
:::::::::::::::::::::

in modTypes add this:
Code:
Public Type ScoreRec
    Name As String * NAME_LENGTH
    Score As String
End Type

in modGlobals add this:
Code:
Public Score(1 To MAX_PLAYERS) As ScoreRec

in modHandleData, add this: (you allready have it, so just rewrite)
Code:
' ::::::::::::::::::::::
' :: Get Score List ::
' ::::::::::::::::::::::
If LCase(Parse(0)) = "scorelist" Then
    Dim z As Long
    Dim x As Long

    frmMirage.lstScore.Clear

    n = 1
    
    For x = 1 To MAX_PLAYERS
        Score(x).Name = Parse(n)
        Score(x).Score = Parse(n + 1)
        
        n = n + 2
    Next x
    
    For x = 1 To MAX_PLAYERS
        frmMirage.lstScore.AddItem Score(x).Name & " (" & Score(x).Score & ")"
    Next x
    
    Exit Sub
End If

That's it. What this will do, or should do, is read the scoreboard list from the server and add it to the ScoreRec variables. Then it will display them on lstScore in the following fashion:
Quote:1. Harry (363)
2. Larry (9876234)
3. Moe (256374)

I didn't test this is any way so please tell me if it does what you had hoped. If not I'm willing to modify it, just tell me what you need Smile.

note: you'll most likely get a couple of duplicate declaration errors, just delete the highlighted lines if this occurs.
Reply
#3
Fix
Replace
Code:
Sub SendScoreList(ByVal Index As Long)
With
Code:
Sub SendScoreList()

Replace
Code:
Call PutVar(FileName, "CHAR" & i, "Score")
With
Call PutVar(FileName, "CHAR" & i, "Score", INSERTTHESCORETYPE)

Also you need to make it so it sends packet to the server that tells the server to send a packet to the client so the list updates itself. ANd also, shouldn't score be a long and not a string?

There are more things that needs to be fixed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)