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

[ES] Better Away Status


Joyce
 Share

Recommended Posts

**Full Tutorial Name :** Away Status Tag
**Originally Designed for :** EO, but Ported to ES
**Tutorial Revision :** 1.0.1
**Difficulty :** 2/5
**General Information :**
A simple tutorial that'll allow you to have a fancy tag rather then the silly old eclipse scripted command that messed up your name. It's a fairly easy and simple edit, but also rather effective. Do note that I haven't added it so that moving or doing anything switches you back to non-AFK, that's up to you to add.

[![](http://www.freemmorpgmaker.com/files/imagehost/pics/c4d2edcfe65c2032f29f38a17fb4ed1b.png)](http://www.freemmorpgmaker.com/files/imagehost/#c4d2edcfe65c2032f29f38a17fb4ed1b.png)

**Tutorial :**

First of all, we're going to edit some things on the **Client-Side**, it's not a lot but it has to be done.;) Now, in ModGlobals add this piece of code anywhere you want.. I myself added it to the bottom.
```
'Away Status Array
Public AwayStatus() As Long
```
Now, in ModHandleData go into Sub Packet_MaxInfo and add this code AFTER it sets the MAX_PLAYERS value but BEFORE this : "AllDataReceived = True", which is located at the end of the sub.
```
    'Away Status Redimming/Clearing
    ReDim AwayStatus(1 To MAX_PLAYERS) As Long

    For I = 1 To MAX_PLAYERS
        AwayStatus(I) = 0
    Next I
```
Now that that's done, we'll need to add the command into the client, so in ModGameLogic, in Sub HandleKeyPresses, find this bit of text "' Whos Online" and add the following code above it:
```
'Away Status Command
        If LCase$(Mid$(MyText, 1, 5)) = "/away" Then
            If AwayStatus(MyIndex) = 0 Then
                Call SendAwayStatus(1)
            Else
                Call SendAwayStatus(0)
            End If
            Exit Sub
        End If
```
Now that bit of code is calling a sub you don't get with the default Stable release, so let's go into ModClientTCP and add the following sub at the bottom:
```
Sub SendAwayStatus(ByVal State As Long)
    Call SendData("awaystat" & SEP_CHAR & State & SEP_CHAR & END_CHAR)
End Sub
```
Now in modGameLogic, find this piece of code:
```
' Draw player name and guild name
                    If frmStable.chkPlayerName.value = 1 Then
                        For I = 1 To MAX_PLAYERS
                            If IsPlaying(I) Then
                                If GetPlayerMap(I) = GetPlayerMap(MyIndex) Then
                                    Call BltPlayerGuildName(I)
                                    Call BltPlayerName(I)
                                End If
                            End If
                        Next I
                    End If
```
And replace it with this piece of code:
```
      ' Draw player name, guild name or away status
                    If frmStable.chkPlayerName.value = 1 Then
                        For I = 1 To MAX_PLAYERS
                            If IsPlaying(I) Then
                                If GetPlayerMap(I) = GetPlayerMap(MyIndex) Then
                                    If AwayStatus(I) = 0 Then
                                        Call BltPlayerGuildName(I)
                                    Else
                                        Call BltAwayStatus(I)
                                    End If
                                    Call BltPlayerName(I)
                                End If
                            End If
                        Next I
                    End If
```
Now in the same Module, find BltPlayerGuildName and paste this below that sub:
```
Sub BltAwayStatus(ByVal Index As Long)
    Dim TextX As Long
    Dim TextY As Long

    TextX = GetPlayerX(Index) * PIC_X + sx + Player(Index).xOffset + Int(PIC_X / 2) - ((Len("") / 2) * 8)

    If SpriteSize = 1 Then
        TextY = GetPlayerY(Index) * PIC_Y + sx + Player(Index).yOffset - Int(PIC_Y / 2) - 44
    Else
        TextY = GetPlayerY(Index) * PIC_Y + sx + Player(Index).yOffset - Int(PIC_Y / 2) - 12
    End If

    Call DrawText(TexthDC, TextX - (NewPlayerX * PIC_X) - NewXOffset, TextY - (NewPlayerY * PIC_Y) - NewYOffset, "", QBColor(BRIGHTRED))
End Sub

```
Now that we've done all the sending and handling data over here, we've forgot that we'll need to RECEIVE the data from the server as well! But no worries, that's an easy fix ;) We're simply going to have to go into modHandleData, and inside Sub HandleData add this code above the "Case "maineditor" bit.
```
'Away Status Packet
        Case "awaystat"
            Call Packet_AwayStat(Parse(1), Parse(2))
            Exit Sub
```
Now aaaaaaall the way at the bottom of modHandleData add the following bit of code:
```
Public Sub Packet_AwayStat(ByVal Index As Long, ByVal Status As Long)
    AwayStatus(Index) = Status
End Sub
```
And that'll be it on the Client-Side!

–------------------------------------

Now let's continue on the **Server-Side**! Apparrently Stable removed the horrible /away command Eclipse used for ages.. So I'm glad we don't need to remove that bugger.. Anyways,  inside modGlobals add the following pieces of code, I put them at the end but they can be put pretty much anywhere..
```
'Away Status Array
Public AwayStatus() As Long
```
Now in modGeneral, find this piece of code:
```
ReDim Guild(1 To MAX_GUILDS) As GuildRec
    ReDim Emoticons(0 To MAX_EMOTICONS) As EmoRec
    ReDim Element(0 To MAX_ELEMENTS) As ElementRec
```
And add this below it:
```
'Away Status Redimming
    ReDim AwayStatus(1 To MAX_PLAYERS) As Long
```
Now I'm just going to be a goofball and not do this in the order I did it on the client, but instead I'm going to let you add the following code in modServerTCP, somewhere at the bottom would probably be the best.
```
Sub SendAwayStat(ByVal Index As Long)
    Call SendDataToAll("awaystat" & SEP_CHAR & Index & SEP_CHAR & AwayStatus(Index) & SEP_CHAR & END_CHAR)
End Sub

Sub SendAwayStatAllTo(ByVal Index As Long)
    Dim I As Long

    For I = 1 To MAX_PLAYERS
        If I <> Index Then
            Call SendDataTo(Index, "awaystat" & SEP_CHAR & Index & SEP_CHAR & AwayStatus(I) & SEP_CHAR & END_CHAR)
        End If
    Next I
End Sub
```
Note that those are TWO subs, one of them is used for when a single player updates his status and gets send to the entire server, the other one is for when a player logs in and he'll need every status sent to him, because otherwise he'd never see who is AFK and who isn't unless they change their status when he/she is logged on.

Now, in modHandleData, add the following code right above "Case "requesteditmain"".(I like keeping stuff on top in case selections, mostly because it makes it easier to find when editing..)
```
Case "awaystat"
            Call Packet_AwayStat(Index, Parse(1))
            Exit Sub
```
And at the bottom of modHandleData add this sub:
```
Public Sub Packet_AwayStat(ByVal Index As Long, ByVal Status As Long)
    AwayStatus(Index) = Status
    Call SendAwayStat(Index)
End Sub
```
And in Sub Packet_UseCharacter under "Call JoinGame(Index)" add this piece of code:
```
'Send All the Away Statusses
        Call SendAwayStatAllTo(Index)
```
Now as a final thing, in modServerTCP under Sub CloseSocket add the following piece of code right after "ClearPlayer(Index)"
```
AwayStatus(Index) = 0
        Call SendAwayStat(Index)
```
And that's it! You now have a fancy tag where your guild name would be! Note that I haven't designed this to make the AFK tag dissapear when you move, chat or attack.. That's up to you really, I'm not going to chew out everything for you guys ;) Also note that I originally made this to work with Origins, and ported it to Stable in a few minutes, I highly doubt it's bugged since I tested it and all, but you never know.. Just a warning :P

EDIT : Fixed a little issue that it never reset the away status when a player logged off.
Link to comment
Share on other sites

I just added a last bit of code to it I forgot about, if you just added it all simply do the last step to fix the issue.. Having new players that logged in take over the Away Status of an old player isn't supposed to happen. ;D
Link to comment
Share on other sites

  • 4 weeks later...
I get an error with your script when i run the server this happens every 3 seconds or so what have i done wrong :P

![](http://i30.tinypic.com/midgr6.jpg)

Also when i turn scripting errors off all of my scripts i do in the script editor don't work.
Link to comment
Share on other sites

You had to change nothing related to that code, so either you're an idiot and copied something over to a bit where it's not supposed to be, or you've messed up your code some other way.

Also, sounds like you simply ducked up your timedevent.ess script, not anything in the source.
Link to comment
Share on other sites

nm fixed ages ago. it wasnt my falt or yours it was zamins quest system. When ever you save a source edit server sided it glitches… (i didn't know that at the time) now i am useing the real ES and it works fine. Nice source edit.
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...