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

Loop Through All Users Online and Look for a Match


Rob Janes
 Share

Recommended Posts

This is just a quick way to check to see if a person on your friend list is online.  This is under the presumption that your friend list is a string array for your character, ie Friends(MAX_FRIENDS).

Anyway, someone was asking about how to compare to see if someone is online, this is a simple server side loop that will compare a string to all the users online and if it's a match, do something…

```
Public Const MAX_FRIENDS = 10
Public strFriendName(MAX_FRIENDS) As String

Public Sub CheckFriends()

'Variables
Dim LoopFriend As Integer
Dim LoopUsers As Integer
Dim tmpUserName As String
Dim tmpFriendName As String

'The first loop, will look through our friend list array (10) above
For LoopFriend = 1 To MAX_FRIENDS

    'Load the Friend's name into Memory so we can compare it when we loop through users
    tmpFriendName = strFriendName(LoopFriend)
    'Now that we're checking the friend, lets compare this friend string to every player online and if it found a match...make it do whatever
    For LoopUsers = 1 To MAX_PLAYERS
        'Is the User Playing
        If IsPlaying(loopuser) Then
            'Get the Users Player Name
            tmpUserName = GetPlayerName(loopuser)
            If tmpUserName = tmpFriendName Then
                'Congrats! Your friend is online! Do something here!

            End If

        'Closing the IsPlaying()
        End If
    'Next User Online
    Next LoopUsers

'Next friend in your array
Next LoopFriend

End Sub

```
Link to comment
Share on other sites

There most likely are ;) I'm still new to the Eclipse Engine it's just an easy way to quickly search through all of the users online.  I'm sure there's probably a feature already in the engine that would cut down the process quite a bit.  Ce La Vie.

One thing I've learned over the years.  You will always find ways to streamline and improve functions and still get the same end result just with shorter and cleaner code however, is it worth your time redesigning a function to get the same results if that time could be spent on another more important function?  To this day I still have to look at a piece of code and say "Ok, it works. Done. Leave it alone, it works…No seriously...stop looking at it....It works, you don't need to tweak it...move on already..."
Link to comment
Share on other sites

By the way, thanks on the comment about Artifact, it's been online almost 13 years now, it's population is slowly getting smaller sadly, only 30-40 people online at any given time now, thankfully though, still enough subscribers to keep paying the bills.  I've started some advertising campaigns which are becoming fairly costly for Artifact, but we'll see, hopefully it brings in new players.  To encourage 'indies' out there, Artifact has made enough money over the years to pay for a house in full.  Just an FYI to encourage people not to give up on their dreams!
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...