Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Live/Visual Stats
#1
Hey I got bored and started writting a visual/live stats code and I can't get them to become live(AKA) they won't automatically update themselves. You have to log off to make them work. I was wondering if someone could help me with this. Or post a working tutorial for this such thing.

Thanks in advance.
Reply
#2
whenever the stats update, send the client the updated info. Duh Smile So find out where and add the packets
Reply
#3
DarkX Wrote:Hey I got bored and started writting a visual/live stats code and I can't get them to become live(AKA) they won't automatically update themselves. You have to log off to make them work. I was wondering if someone could help me with this. Or post a working tutorial for this such thing.

Thanks in advance.

In modHandleData, find any packets which have things like "player(index).STR =" etc. and underneath, have a label or something in frmMirage updated with that information.

If there isn't any packets which send this info, make one.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#4
Quote:In modHandleData, find any packets which have things like "player(index).STR =" etc. and underneath, have a label or something in frmMirage updated with that information.

If there isn't any packets which send this info, make one.

You mean like these?
Code:
If LCase(Parse(0)) = "playerstats" Then
Call SetPlayerSTR(MyIndex, Val(Parse(6)))
frmMirage.lblSTR.Caption = Player(MyIndex).STR
Call SetPlayerDEF(MyIndex, Val(Parse(5)))
frmMirage.lblDEF.Caption = Player(MyIndex).DEF
Call SetPlayerSPEED(MyIndex, Val(Parse(3)))
frmMirage.lblSPEED.Caption = Player(MyIndex).SPEED
Call SetPlayerMAGI(MyIndex, Val(Parse(4)))
frmMirage.lblMAGI.Caption = Player(MyIndex).MAGI
Call SetPlayerLevel(MyIndex, Val(Parse(2)))
frmMirage.lblLevel.Caption = Player(MyIndex).Level
Call SetPlayerExp(MyIndex, Val(Parse(1)))
frmMirage.lblEXP.Caption = Player(MyIndex).Exp
Exit Sub
End If

Sorry, still very new to this half of VB, how exactly would I do that. I tried something earlier on in the week, but I'm still not sure how you mean.
Reply
#5
That would work. The only thing is the stats will only be updated whenever you do something that calls the SendStats procedure on the server. So on the server, on frmServer, make a new timer and put this code in it:

Code:
Dim i As Byte

    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) And IsConnected(i) Then
            Call SendStats(i)
        End If
    Next i

Interval: 1000
Enabled: True

This will update every players stats every second.

EDIT: I also think you may have the code a little messed up.

Open the Server source code and change the following things. I'm just going to post the code for what I think you're trying to do.

in modServerTCP, find:

Code:
Sub SendStats(ByVal Index As Long)
Dim Packet As String
    
    Packet = "PLAYERSTATS" & SEP_CHAR & GetPlayerSTR(Index) & SEP_CHAR & GetPlayerDEF(Index) & SEP_CHAR & GetPlayerSPEED(Index) & SEP_CHAR & GetPlayerMAGI(Index) & SEP_CHAR & END_CHAR
    Call SendDataTo(Index, Packet)
End Sub

Replace it with this:
Code:
Sub SendStats(ByVal Index As Long)
Dim Packet As String
    
    Packet = "PLAYERSTATS" & SEP_CHAR & GetPlayerSTR(Index) & SEP_CHAR & GetPlayerDEF(Index) & SEP_CHAR & GetPlayerSPEED(Index) & SEP_CHAR & GetPlayerMAGI(Index) & SEP_CHAR & GetPlayerLevel(Index) & SEP_CHAR & GetPlayerExp(Index) & SEP_CHAR & END_CHAR
    Call SendDataTo(Index, Packet)
End Sub

Now right here I'll explain a little something, just because it doesn't seem you understand how parsing works Smile.

We send data to the client in a certain order. That order determines how we will later pick up the data on the client side. If you read it wrong on the client side, you could be displaying magi on your strength label, or displaying the players experience on the speed label... which we don't want. Lol.

So here's how the serve ris going to send that above data to the client:

0. "PLAYERSTATS"
1. GetPlayerSTR(Index)
2. GetPlayerDEF(Index)
3. GetPlayerSPEED(Index)
4. GetPlayerMAGI(Index)
5. GetPlayerLevel(Index)
6. GetPlayerExp(Index)

Now... open up the client source code and in modHandleData find the following:

Code:
' :::::::::::::::::::::::::
    ' :: Player stats packet ::
    ' :::::::::::::::::::::::::
    If LCase(Parse(0)) = "playerstats" Then
        Call SetPlayerSTR(MyIndex, Val(Parse(1)))
        Call SetPlayerDEF(MyIndex, Val(Parse(2)))
        Call SetPlayerSPEED(MyIndex, Val(Parse(3)))
        Call SetPlayerMAGI(MyIndex, Val(Parse(4)))
        Exit Sub
    End If

Replace it with this:

Code:
' :::::::::::::::::::::::::
    ' :: Player stats packet ::
    ' :::::::::::::::::::::::::
    If LCase(Parse(0)) = "playerstats" Then
        Call SetPlayerSTR(MyIndex, Val(Parse(1)))
        Call SetPlayerDEF(MyIndex, Val(Parse(2)))
        Call SetPlayerSPEED(MyIndex, Val(Parse(3)))
        Call SetPlayerMAGI(MyIndex, Val(Parse(4)))
        Call SetPlayerLevel(MyIndex, Val(Parse(5)))
        Call SetPlayerExp(MyIndex, Val(Parse(6)))
        Exit Sub
    End If

Notice how we read it on the client in the same order as we sent it from the server? This not only makes the code cleaner and easy to find bugs, but it also makes sure we know exactly which variable we are setting each stat too. The way your code looks, judging that your server side code sends the stats in the same order I have, you woudl be setting the players strength level to whatever the value of their experience was. Which isn't good, obviously.

Now, let's add the stuff to display that. Make sure you edit the following code to suit your labels.

Code:
' :::::::::::::::::::::::::
    ' :: Player stats packet ::
    ' :::::::::::::::::::::::::
    If LCase(Parse(0)) = "playerstats" Then
        Call SetPlayerSTR(MyIndex, Val(Parse(1)))
        Call SetPlayerDEF(MyIndex, Val(Parse(2)))
        Call SetPlayerSPEED(MyIndex, Val(Parse(3)))
        Call SetPlayerMAGI(MyIndex, Val(Parse(4)))
        Call SetPlayerLevel(MyIndex, Val(Parse(5)))
        Call SetPlayerExp(MyIndex, Val(Parse(6)))
        
        frmMirage.LblStrength = GetPlayerSTR(MyIndex)
        frmMirage.LblDefense = GetPlayerDEF(MyIndex)
        frmMirage.LblSpeed = GetPlayerSPEED(MyIndex)
        frmMirage.LblMagic = GetPlayerMAGI(MyIndex)
        frmMirage.LblLevel = GetPlayerLevel(MyIndex)
        frmMirage.LblExp = GetPlayerExp(MyIndex)
        Exit Sub
    End If

This will now send the stats, experience, and level of each player connected to your server every second and display it on the labels you make on frmMirage. If you ahve any problems just post.
Reply
#6
Leighland Wrote:That would work. The only thing is the stats will only be updated whenever you do something that calls the SendStats procedure on the server. So on the server, on frmServer, make a new timer

That's as bad as sending the HP, MP and SP every ten seconds!!!!

Using timers for something like that is really bad programming.

All you need to do is go to frmTraining, press the 'train' button, find out what packet is sent.

Go serverside, find that packet in handledata, then at the bottom add:

Code:
Call SendPlayerStats(index)

Then make a new sub in modServerTCP:

Code:
Public Sub SendPlayerStats(byval Index as long)
dim packet as string

Packet = "updatedstats" & SEP_CHAR & "have what ever stats you want here" & SEP_CHAR & END_CHAR
Call SendDataTo(index, packet)
end sub

Then in clientside modHandleData, add a new packet called "updatedstats" and have all your labels updated with the values recieved in the packet Smile

~Kite

(I did that all off the top of my head, so I didn't write down all the stat's etc.)
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#7
Ok Kite I know what your talking about, but I couldn't get it to work. Leighland's on the other hand, after a short amount of tweaking I got it to work... I thank both of you very much (I will try and figure out how to get yours working Kite)

Thanks!!!
Reply
#8
Sorry my post didn't give more information, but I don't have internet and VB6.0 on the same pc Sad

I'll see if I can write up a tutorial for it when I get a few minutes spare.

Glad to see you got Leigh's one working though!

~Kite
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#9
Well, I got yours somewhat working, but I had couldn't get it to where it automatically updates itself, you had to type /stats or press the stats button. Or find away to get the form your on to reload.
Reply
#10
I equally have had such problems with efficiently displaying stats >.
Reply
#11
Unfortunately had to deal with those tricky stats, but thanks to leighland and Kite here things are finally working, where I can't get Kites to work I got leighlands working and it perfectly updates every 5 seconds.
Reply
#12
The issue with that method is imagin when you have say 10 players online, think of the packet spamming! eeeek!

Has anyone tried adding to the packets? For instance, the client sends a packet to the server saying you just earnt 15 experience, why then can the server not reply with an experience update? Also another 'want' for me if this was working would be for it to then blt the experience just earnt onto the players sprite, i think i saw gsd do something similar once and it was quite neat :]
Reply
#13
Well couldn't you modify the bltPlayerDamage, to be bltPlayerEXP, so when the player gets some exp it blts that plus the letters EXP above there head?
Reply
#14
I got home, all ready to write up a tutorial for this, but when I got onto the source, I pressed the button in frmTraining, followed the string of packets, eventually came client side and just added:

Code:
If Index = MyIndex then
        frmMirage.lblW/e = val(Parse(w/e))
    end if

At the end of one of the stat's packets.

This packet is sent when you log in, or when you send training packets.

I don't know why it doesn't work for you.

ps. I did that on Mirage 3.03

~Kite
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#15
Yeah who knows if it'll work on MSE
Reply
#16
The stat's weren't changed in MSE Build 1. I'm just saying, I did it in 3.03.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#17
I know but I have a problem with installing certain codes, like that (for some odd reason I have trouble with installing small crap like that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)