[Request] /afk command

Hello i want to ask if someone could help me out there.

If a player types in the chat /afk i want that his color turns grey and next to his name schould be [AFK]

I hope you guys can help me thank you alot :)!

Server and Client

! Look for “PlayerRec”. At the bottom, put there this
! ```
! afk as byte

Look for "Public Enum ServerPackets" and at the bottom of the enum, put there
>! ```
>! SPlayerToggledAfk
>! ```
Look for "Public Enum ClientPackets" and at the bottom of the enum, put there
>! ```
>! CToggleAfk
>! ``` 

Server 
>! Look for "Public Sub InitMessages()" and anywhere in that sub, put there
>! ```
>! HandleDataSub(CToggleAfk) = GetAddress(AddressOf HandleToggleAfk)
>! ```
Now, go to the bottom of modHandleData and put there
>! ```
>! Sub HandleToggleAfk(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    If Player(index).afk = 1 Then
        Player(index) = 0
    Else
        Player(index).afk = 1
    End If

    SendPlayerToggledAfk (index)
End Sub
>! ```
Go to the bottom of modServerTCP and put this there
>! ```
>! Public Sub SendPlayerToggledAfk(ByVal index As Long)
Dim Buffer As clsBuffer
>!     Set Buffer = New clsBuffer
    Buffer.WriteLong SPlayerToggledAfk
    Buffer.WriteLong index
    Buffer.WriteLong Player(index).afk
    SendDataToMap Player(index).Map, Buffer.ToArray()
    Set Buffer = Nothing
End Sub
>! ```
Lastly, look for "Function PlayerData(ByVal index As Long) As Byte()" and put this
>! ```
>! Buffer.WriteLong Player(index).afk
>! ```
above
>! ```
>! PlayerData = Buffer.ToArray()
>! ``` 

Client 
>! Look for "Public Sub InitMessages()" and put there this
>! ```
>! HandleDataSub(SPlayerToggledAfk) = GetAddress(AddressOf HandlePlayerToggledAfk)
>! ```
Go to the bottom of modHandleData, and put there this
>! ```
>! Sub HandlePlayerToggledAfk(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
Dim Buffer As clsBuffer
Dim playerIndex As Long
>!     Set Buffer = New clsBuffer
    Buffer.WriteBytes Data()
    playerIndex = Buffer.ReadLong
    Player(Index).afk = Buffer.ReadLong
    Set Buffer = Nothing
End Sub
>! ```
Look for "Public Sub DrawPlayerName(ByVal Index As Long)" and look for the chunk that looks like this
>! ```
>!         Select Case GetPlayerAccess(Index)
            Case 0
                color = RGB(255, 96, 0)
            Case 1
                color = QBColor(DarkGrey)
            Case 2
                color = QBColor(Cyan)
            Case 3
                color = QBColor(BrightGreen)
            Case 4
                color = QBColor(Yellow)
        End Select
>! ```
Replace it with this
>! ```
>!         If Player(Index).afk = 0 Then
            Select Case GetPlayerAccess(Index)
                Case 0
                    color = RGB(255, 96, 0)
                Case 1
                    color = QBColor(DarkGrey)
                Case 2
                    color = QBColor(Cyan)
                Case 3
                    color = QBColor(BrightGreen)
                Case 4
                    color = QBColor(Yellow)
            End Select
        Else
            color = RGB(65, 65, 65)
        End If
>! ```
Look for "Select Case Command(0)" and put this under it
>! ```
>!                 Case "/afk"
                    SendToggleAfk
>! ```
Now go to modClientTcp, and put this at the bottom
>! ```
>! Public Sub SendToggleAfk()
Dim Buffer As clsBuffer
>!     Set Buffer = New clsBuffer
    Buffer.WriteLong CToggleAfk
    SendData Buffer.ToArray()
    Set Buffer = Nothing
End Sub
>! ``` 

I think that should be everything. Save, compile, and enjoy. **Remember that you need to delete all old accounts, or make a data converter.** I haven't tested it, but I'll go through it now.

Thank you! I will be patient !

Look for “Public Sub InitMessages()” and anywhere in that sub, put there


HandleDataSub(CToggleAfk) = GetAddress(AddressOf HandleToggleAfk)

you put CToggleAfk here, which is right, but you use SToggleAfk in the rest of the code…  :x


Sub HandleToggleAfk(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    If Player(index).afk = 1 Then
        Player(index) = 0 <-- didn't you mean Player(index).afk = 0 ?
    Else
        Player(index).afk = 1
    End If

    SendPlayerToggledAfk (index)
End Sub

🙂

Awh. Good eye Slasher. In my defense, I wrote this up fifteen minutes before I had class. I’ll fix and finish it now. Cheers!

EDIT: Finished.

Thank you alot, sadly I’m currently in bed tho. I will test it tomorrow! But if I may ask you for another help. Is it possible to show the actual damage, crit chance in a text label in the character window?

Well again thanks for the code, but sadly

my character has no name anymore  😛 ( yes deleted account)

/EDIT -> I fixxed it


If Player(Index).afk = 0 Then
            Select Case GetPlayerAccess(Index)
                Case 0
                    color = RGB(255, 96, 0)
                Case 1
                    color = QBColor(DarkGrey)
                Case 2
                    color = QBColor(Cyan)
                Case 3
                    color = QBColor(BrightGreen)
                Case 4
                    color = QBColor(Yellow)
            End Select
        Else
            color = RGB(65, 65, 65)
        End If 

i changed it with this cause QBColor etc ( using Directx8 😛

If Player(Index).afk = 0 Then
            Select Case GetPlayerAccess(Index)
            Case 0
                color = Orange
            Case 1
                color = DarkGrey
            Case 2
                color = Cyan
            Case 3
                color = BrightGreen
            Case 4
                color = Yellow
        End Select
        Else
            color = DarkGrey
        End If 

also you got a little mistake in the code nothing important

Sub HandleToggleAfk(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    If Player(index).afk = 1 Then
        Player(index) = 0
    Else
        Player(index).afk = 1
    End If

    SendPlayerToggledAfk (index)
End Sub 
If Player(index).afk = 1 Then
        Player(index) = 0
    Else 

instead of

Player(index).afk = 0

you wrote

Player(index) = 0

Ah, shoot. Glad you figured it out though! I assure you, it wasn’t intentional. It was only rushed. ^_^

Ah no problem, thank you atleast for helping me out there you can close this thread i gonna change it to Solved :)!

Log in to reply