| Mirage Source http://miragesource.net/forums/ |
|
| Score Board http://miragesource.net/forums/viewtopic.php?f=201&t=599 |
Page 1 of 1 |
| Author: | Shadow Dragon [ Thu Oct 05, 2006 2:42 pm ] |
| Post subject: | Score Board |
Hey guys I'm writting a score board code but I have no clue how to make it work, I was wondering if someone could look over it and tell me if they see something that needs to be diffrent. Serverside; moddatabase Code: Sub LoadScore Dim FileName As String Dim i As Long Call CheckScore FileName = App.Path & "\data\score.ini Max_Score = Val(GetVar(FileName, "INIT", "MaxScore")) ReDim Class(0 To Max_Score) As ScoreRec Call ClearScore For i = 0 To Max_Score Score(i).Char(i).Name = GetVar(FileName, "CHAR" & i, "Name") Score(i).Score = GetVar(FileName, "SCORE" & i, "Score") DoEvents Next i End Sub Sub SaveScore() Dim FileName As String Dim i As Long FileName = App.Path & "\data\score.ini" For i = 0 To Max_Score Call PutVar(FileName, "SCORE" & i, "Name", Trim(Player(index).Char(i).Score(i).Name)) Call PutVar(FileName, "SCORE" & i, "Score", STR(Score(i).Score)) Next i End Sub Sub CheckScore() If Not FileExist("data\score.ini") Then Call SaveScore End If End Sub serverside modhandledata Code: ' ::::::::::::::::: ' :: Score list :: ' ::::::::::::::::: If LCase(Parse(0)) = "scorelist" Then 'Stop Call SendScoreList Exit Sub End If serverside modservertcp Code: Sub SendScoreList(ByVal index As Long) Dim packet As String Dim i As Long Dim n As Long packet = "" n = 0 For i = 1 To MAX_SCORE If IsPlaying(i) Then packet = packet & SEP_CHAR & GetPlayerName(i) & SEP_CHAR & GetScore(i) & SEP_CHAR n = n + 1 End If Next i packet = "SCORELIST" & SEP_CHAR & n & packet & END_CHAR Call SendDataToAll(packet) End Sub serverside modtypes Code: type ScoreRec Name as string * NAME_LENGTH Score as string end type CLIENT SIDE; modclienttcp Code: Sub SendScoreList() Dim packet As String packet = "SCORELIST" & SEP_CHAR & END_CHAR Call SendData(packet) End Sub CLIENTSIDE; modhandledata Code: ' :::::::::::::::::::::::::: and that's as far as I have gotten, I know alot of you scim over these but does this look atleast kind of right? thanks for any input laterz
' :: Get Score List :: ' :::::::::::::::::::::::::: If LCase(Parse(0)) = "Scorelist" Then Dim z As Long frmMirage.lstScore.Clear n = 2 z = Val(Parse(1)) For x = n To (z + 1) frmMirage.lstScore.AddItem Trim(Parse(n)) n = n + 2 Next x Exit Sub End If |
|
| Author: | Dark Echo [ Thu Oct 05, 2006 2:52 pm ] |
| Post subject: | |
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.. 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.. Thanks dude.. |
|
| Author: | Leighland [ Thu Oct 05, 2006 4:13 pm ] |
| Post subject: | |
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 note: you'll most likely get a couple of duplicate declaration errors, just delete the highlighted lines if this occurs. |
|
| Author: | Shadow Dragon [ Fri Oct 06, 2006 1:09 am ] |
| Post subject: | |
Sorry didn't work at all. |
|
| Author: | William [ Fri Oct 06, 2006 1:25 pm ] |
| Post subject: | |
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. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|