Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[EO] AFK Command


Beanie93
 Share

Recommended Posts

This is my second tutorial here, on Eclipse.
I've experimented with clsBuffer, and could get an AFK Command as the first thing I've ever done with clsBuffer, so the feature is not that big, nor so useful, but I thought I should post it in case someone wants it.

We will edit both client and server, so open your client.vbp and server.vbp.

**Client-side**

**modEnumerations**
Look for
```
    ' Make sure CMSG_COUNT is below everything else
```and above, add
```
    CAfk
    CBack
```
We're done here.

**modGlobals**
At the bottom, add
```
' afk
Public isAfk As Boolean
```Done here.

**modInput**
In **Public Sub CheckInputKeys()**, look for
```
    If Options.Debug = 1 Then On Error GoTo errorhandler
```and below, add
```
    If isAfk = True Then Exit Sub
```This will prevent the player to move if he/she is AFK.

Now, look for
```
                Case "/stats"
                    Set Buffer = New clsBuffer
                    Buffer.WriteLong CGetStats
                    SendData Buffer.ToArray()
                    Set Buffer = Nothing
```and below, add
```
                Case "/afk"
                    Dim pname As Long
                    If isAfk = False Then
                      isAfk = True
                      Set Buffer = New clsBuffer
                      Buffer.WriteLong CAfk
                      Buffer.WriteLong pname
                      SendData Buffer.ToArray()
                      Set Buffer = Nothing
                    Else
                      isAfk = False
                      Set Buffer = New clsBuffer
                      Buffer.WriteLong CBack
                      Buffer.WriteLong pname
                      SendData Buffer.ToArray()
                      Set Buffer = Nothing
                    End If
```We just used clsBuffer to send the Afk packet to the server if we are not Afk, and to send the Back packet if we are Afk.

Done here.

**modClientTCP**
We want that when the Player logs off, isAfk is false, so look for **Sub DestroyTcp()** and below
```
    frmMain.Socket.Close
```add
```
    isAfk = False
```
Client side is done.
Now, we want the server to receive the packet, and make an action.

**Server-side**

**modEnumerations**
Do exactly what you did  Client-side in here.

**modHandleData**
Look for
```
    HandleDataSub(CPartyLeave) = GetAddress(AddressOf HandlePartyLeave)
```and below, add
```
    HandleDataSub(CAfk) = GetAddress(AddressOf HandleAfk)
    HandleDataSub(CBack) = GetAddress(AddressOf HandleBack)
```
Then, at the bottom, add these 2 subs:
```
Private Sub HandleAfk(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddR As Long, ByVal ExtraVar As Long)
    Dim Buffer As clsBuffer
    Set Buffer = New clsBuffer
    Buffer.WriteBytes Data()

    Call TextAdd(GetPlayerName(index) & " has gone AFK.")
    Call GlobalMsg(GetPlayerName(index) & " has gone AFK!", Grey)
End Sub

Private Sub HandleBack(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddR As Long, ByVal ExtraVar As Long)
    Dim Buffer As clsBuffer
    Set Buffer = New clsBuffer
    Buffer.WriteBytes Data()

    Call TextAdd(GetPlayerName(index) & " is no longer AFK.")
    Call GlobalMsg(GetPlayerName(index) & " is no longer AFK!", Grey)
End Sub
```
There we go, all done. Type /afk in the chat, and you should have it working.
Hope this helped!

**NOTE:** _This is the first time I ever use clsBuffer, I didn't find any tutorial, so I learnt by looking at other subs that used clsBuffer, so this is maybe not done properly, but it works._

The _other_ way of doing it: (credit to King Butterfly/Carim):
Inside **KeyHandlePresses**, add:
```
                Case "/afk"

                    AFK = Not AFK

                    If AFK = True Then
                        EmoteMsg " is now AFK!"
                            Else
                        EmoteMsg " is no longer AFK!"
                    End If
```Anywhere at the declarations in modGlobal, add:
```
Public AFK As Boolean
```
Add, in Sub Main:
```
    AFK = False
```
Link to comment
Share on other sites

You don't need to go to such lengths, this can be done in a couple of lines of code, and without the need to edit anything server-side (The wonders of abusing EmoteMsg. <3)

* * *

EDIT: May as well share what I mean…

Inside HandleKeyPresses

```
                Case "/afk"

                    AFK = Not AFK

                    If AFK = True Then
                        EmoteMsg " is now AFK!"
                            Else
                        EmoteMsg " is no longer AFK!"
                    End If
```
Anywhere at the declarations in modGlobals

```
Public AFK As Boolean
```
And, in Sub Main

```
    AFK = False
```
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
@Serenade:

> You don't need to go to such lengths, this can be done in a couple of lines of code, and without the need to edit anything server-side (The wonders of abusing EmoteMsg. <3)
>
> * * *
>
> EDIT: May as well share what I mean…
>
> Inside HandleKeyPresses
>
> ```
>                 Case "/afk"
>                    
>                     AFK = Not AFK
>                    
>                     If AFK = True Then
>                         EmoteMsg " is now AFK!"
>                             Else
>                         EmoteMsg " is no longer AFK!"
>                     End If
> ```
> Anywhere at the declarations in modGlobals
>
> ```
> Public AFK As Boolean
> ```
> And, in Sub Main
>
> ```
>     AFK = False
> ```

Could you specify where you put the first bit of code for the noobs (points finger back at self)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...