Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sex Determines Name Color
#1
Okey, This is only my first tutorial so don't yell at me. Tongue Basically, this tutorial will check to see whether the person logging in is a male or female, and then blt their name to the Male color or Female color. This wasn't hard to figure out but since I did it on my own, I thought I would share it. Big Grin I'm not sure if there is already a tutorial on this, but if there is then this one can be deleted. Okey, on to the tutorial.

Server Side:
First, you should add these two functions at the bottom of modGameLogic.

Code:
Function GetPlayerSex(ByVal Index As Long) As Long
    GetPlayerSex = Player(Index).Char(Player(Index).CharNum).Sex
End Function

Sub SetPlayerSex(ByVal Index As Long, ByVal Sex As Byte)
    Player(Index).Char(Player(Index).CharNum).Sex = Sex
End Sub

Once you have those two functions added, head over to modServerTCP and search for "Sub SendStats(ByVal Index As Long)". Change that entire sub to:
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 & GetPlayerSex(Index) & SEP_CHAR & END_CHAR
    Call SendDataTo(Index, Packet)
End Sub

Done with Server!

Client Time!
Now that we are in the client, we need to make changes to the SendStats packet so that we can receive the player's sex. To do this we need to search for, "' :: Player stats packet ::" in modHandleData. Change this entire packet to:
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 SetPlayerSex(MyIndex, Val(Parse(5)))
        Exit Sub
    End If


Now that our client recieves the player's sex, it still doesn't have the function to actually make the client know what sex they have. So we need to two functions to the client. In modGameLogic add these two functions at the bottom.
Code:
Sub SetPlayerSex(ByVal Index As Long, ByVal Sex As Byte)
    Player(Index).Sex = Sex
End Sub

Function GetPlayerSex(ByVal Index As Long) As Long
    GetPlayerSex = Player(Index).Sex
End Function

There, now our client receives the player's sex and knows what to do with it. Finally we need to make the client check if the player is Male or Female and then blt their name. Go to modGameLogic and search for, "Sub BltPlayerName(ByVal Index As Long)" and change the entire sub to:

Code:
Sub BltPlayerName(ByVal Index As Long)
Dim TextX As Long
Dim TextY As Long
Dim Color As Long
    
    ' Check access level
    If GetPlayerPK(Index) = NO Then
        Select Case GetPlayerAccess(Index)
            Case 0
                Select Case GetPlayerSex(Index)
                    Case SEX_MALE
                        Color = RGB(255, 123, 60)
                    Case SEX_FEMALE
                        Color = RGB(190, 70, 193)
                End Select
            Case 1
                Color = QBColor(DarkGrey)
            Case 2
                Color = QBColor(Cyan)
            Case 3
                Color = QBColor(Blue)
            Case 4
                Color = QBColor(Pink)
        End Select
    Else
        Color = QBColor(BrightRed)
    End If
    
    ' Draw name
    TextX = GetPlayerX(Index) * PIC_X + Player(Index).XOffset + Int(PIC_X / 2) - ((Len(GetPlayerName(Index)) / 2) * 8)
    TextY = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - Int(PIC_Y / 2) - 4
    Call DrawText(TexthDC, TextX, TextY, GetPlayerName(Index), Color)
End Sub

In that sub, we check to see if the person is a male or female. If the player is a male, then their name will show up to be Orange. If they're a female then it will be a purplish color. To change the color of the names, find the RGB(Blah, Blah, Blah) beside the SEX_MALE or SEX_FEMALE and change it to the desired color.

That should be it for this tutorial so if there is any problems, post back! I'll try to help as much as I can and I'm sure the community will help also!

Edit: I forgot to add the Sex to the Player Type. Go into modTypes and go to Type PlayerRec and under, "Name As String * NAME_LENGTH" add, "Sex as Byte".
Also, go into frmNewChar and change all three Label3, optMale, and optFemale's visibility to True instead of false.
Reply
#2
Hmm, I'm not sure. I haven't tested it with more than one person on. I'll test it when I get home from college. Tongue Thanks Dave.
Reply
#3
It should work on all players.
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
Kuja
Robin


Big tutorial done by a new user :]
Great way to start off!
Reply
#5
Holy shit, I can see Dave's avatar and sig. o.O


I did something like this for human - vampire(transformed)
But took it off cus it annoyed me immensely.
Reply
#6
So, has anyone tried this with multiple user's on at the same time? I would try to get more than one on at the same time but I don't know how to do that multiple logging because when I log in the second character I get an automation error. But anyway, thanks for all the replies! Tongue
Reply
#7
No, it should work fine.

I know once I messed up displaying player names on the GUI, and it showed whoever the last person was that logged on instead of the actual player's name though.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)