RavenStar Posted September 1, 2010 Author Share Posted September 1, 2010 This is an update of the previous tutorial I wrote, which I left at the very bottom of this post for reference, I recommend you use this new version :)This tutorial will show you how to implement a dynamic friends list into your game. The friends list is now stored on the server and each character has a different friends list. The player is able to bring up the friends list, click a name and it will start a PM to that person. You are also able to define the maximum friends a character is allowed.**CLIENT SIDE**Open up the IDE of frmMainGame.Find your picInventory panel, copy and paste it. When it asks if you want to make a control array, click no.Now name this new panel to picFriendsAdd a label inside this new panel and call it lblFriendAdd, this label is used to add new friends so give it a caption aswell.Your panel should look something like this;>! ![](http://i46.photobucket.com/albums/f142/onfiya/newfl1.gif)Now double click lblFriendAdd and add this code;```Dim n As Long strinput = InputBox("Friend's Name : ", "Add Friend") If StrPtr(strinput) = 0 Or strinput = vbNullString Then Exit Sub n = CLng(Trim$(strinput)) Call SendAddFriend(n)```Now goto modClientTCP and add this to the very bottom;```'RavenStar'Add new friendPublic Sub SendAddFriend(ByVal Name As String) Dim Buffer As clsBuffer Set Buffer = New clsBuffer Buffer.WriteLong CAddFriend Buffer.WriteLong Name SendData Buffer.ToArray() Set Buffer = NothingEnd Sub```Next goto modConstants and find this;```' Bank constants```Add this code **above** it;' Friend List constants - RavenStarPublic Const FLTop As Byte = 32Public Const FLLeft As Byte = 32Public Const FLOffsetY As Byte = 24Open up modGlobals, add this at the very bottom;```' Used for friend list - RavenStarPublic FRIENDS_INDEX(1 To 8) As StringPublic FriendX As LongPublic FriendY As Long```Open modEnumerations, find this;``` ' Make sure SMSG_COUNT is below everything else SMSG_COUNTEnd Enum```Add this **above** it;```SFriendList 'RavenStar```Then find this;``` ' Make sure CMSG_COUNT is below everything else CMSG_COUNTEnd Enum```Add this **above** it;```CAddFriend 'RavenStar```Goto modHandleData, find this;```HandleDataSub(STradeStatus) = GetAddress(AddressOf HandleTradeStatus)```Add this below it;```HandleDataSub(SFriendList) = GetAddress(AddressOf HandleFriendsList) 'RavenStar```Then goto the very bottom of modHandleData and add this;```'Friends List - RavenStarPrivate Sub HandleFriendsList(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long) Dim Buffer As clsBuffer Dim ALL_FRIENDS As Long, I As Long, Y As Long, X As Long Dim FriendName As String Set Buffer = New clsBuffer Buffer.WriteBytes Data() frmMainGame.picFriends.Cls For I = 1 To UBound(FRIENDS_INDEX) Y = FLTop + (FLOffsetY * (I - 1)) X = FLLeft FriendName = Buffer.ReadString FRIENDS_INDEX(I) = FriendName DrawText frmMainGame.picFriends.hDC, X, Y, FriendName, QBColor(White) Next Set Buffer = NothingEnd Sub```Open the code for frmMainGame, add this to the very bottom;**I originally forgot to add this to the tutorial re-write, so if you used this tutorial before I added this, make sure you add it now.**```Private Sub picFriends_DblClick() Dim friendnum As Long friendnum = IsFriendName(FriendX, FriendY) If friendnum <> 0 Then txtMyChat.Enabled = True txtMyChat.text = "!" & FRIENDS_INDEX(friendnum) & " " txtMyChat.SetFocus txtMyChat.SelStart = Len(txtMyChat.text) Exit Sub End IfEnd SubPrivate Function IsFriendName(ByVal X As Single, ByVal Y As Single) As Long Dim tempRec As RECT Dim I As Long IsFriendName = 0 For I = 1 To UBound(FRIENDS_INDEX) With tempRec .Top = FLTop + (FLOffsetY * (I - 1)) .Bottom = .Top + 16 .Left = FLLeft .Right = .Left + (picFriends.width - .Left) End With If X >= tempRec.Left And X <= tempRec.Right Then If Y >= tempRec.Top And Y <= tempRec.Bottom Then IsFriendName = I Exit Function End If End If NextEnd Function```That's it for the client side, next is the server side, you're almost done!**SERVER SIDE**Open modHandleData and find;```HandleDataSub(CUntradeItem) = GetAddress(AddressOf HandleUntradeItem)```Add this below it;```HandleDataSub(CAddFriend) = GetAddress(AddressOf HandleAddFriend)```Goto modServerTCP, add this to the very bottom;```' Lets send their friend list - RavenStarSub SendFriendsList(ByVal Index As Long) Dim Buffer As clsBuffer Dim I As Long Dim fName As String Dim ff As Integer Dim RAW As String Dim Txt() As String fName = App.Path & "\data\friends\" & GetPlayerName(Index) & ".txt" If FileExist(fName, True) Then ff = FreeFile Open fName For Binary As #ff RAW = String$(LOF(ff), 32) Get #ff, 1, RAW Close #ff Txt$ = Split(RAW, vbCrLf) Set Buffer = New clsBuffer Buffer.WriteLong SFriendList For I = LBound(Txt$) To UBound(Txt$) Buffer.WriteString Txt$(I) Next SendDataTo Index, Buffer.ToArray() Set Buffer = Nothing Else ' Create the friend list if it doesn't exist.. Open App.Path & "\data\friends\" & GetPlayerName(Index) & ".txt" For Output As #1 Close #1 End IfEnd Sub```Open modPlayer and find this;```Call SendMapEquipment(Index)```Add this below it;```Call SendFriendsList(Index)```Open modEnumerations and find this;``` ' Make sure SMSG_COUNT is below everything else SMSG_COUNTEnd Enum```add this **above** it;``` SFriendList 'RavenStar```Woohoo you're all done!Here's a screenshot for all you kids!![](http://i46.photobucket.com/albums/f142/onfiya/coding/newflfinish.gif)**Old Friends List Tutorial (Not Recommended)**>! Hi again, I just finished writing this little code and thought I'd share it with you all.>! This tutorial will guide you through the process of adding a dynamic friends list to your game. The friends list is stored locally so there is no server-side edits required.>! What do I mean by dynamic? Basically this code will use a control array to create the extra labels (that store the friends name) for you, so if you want to adjust how many friends a player can store, you simply change 1 variable and done!>! Lets get started!>! **CLIENT SIDE**>! Goto frmMainGame and find your picCharacter, this is where your characters name & stats are displayed (or you can use any of the other panels if you'd like).>! Now copy and paste this panel, it will ask you if you want to create a control array, click no.Now delete everything inside that panel so it's blank (see picture for example) and change the name of the panel to picFriendsList.>! >! ![](http://i46.photobucket.com/albums/f142/onfiya/coding/FL1.gif)>! Next create a label inside the picFriendsList panel and call it lblFriendName.Copy this label then paste it inside the picFriendsList panel. It will ask you if you want to create a control array, click yes!Now delete the newly created label, so you're left with only one label inside the panel. (see picture for example)>! >! ![](http://i46.photobucket.com/albums/f142/onfiya/coding/FL2.gif)>! Next, change the visibility of the label to FALSE. (see picture for example)>! >! ![](http://i46.photobucket.com/albums/f142/onfiya/coding/FL3.gif)>! Goto frmMainGame code and find;```Private Sub Form_Load()```Add this within the Form_Load sub; (Note: In the middle of this code where it has "For I = 1 To 4" simply change the 4 to the maximum number of friends you want to appear on the Friends List)```Dim FileName As StringDim FriendsFile As IntegerDim TextOfLine As StringDim I As Integer>! FileName = App.Path & "\Data Files\friendslist.txt"FriendsFile = FreeFileOpen FileName For Input As FriendsFile For I = 1 To 4 ' <----- Change the 4 to the MAX number of friends a player can have! Load lblFriendName(I) Line Input #FriendsFile, TextOfLine With lblFriendName(I) .Left = lblFriendName(0).Left .Top = lblFriendName(I - 1).Top + lblFriendName(0).height + 6 .Caption = TextOfLine .AutoSize = True .Visible = True End With Next IClose FriendsFile```>! Next, double click the label we made earlier and add this code;``` txtMyChat.text = "! " & lblFriendName(Index).Caption & " " txtMyChat.Enabled = True txtMyChat.SetFocus>! ```>! You're all done!>! Now a few notes..-You'll need to figure out where you want to put the Friends List panel and add any hide/show code for it if you desire.-Make sure you create a text file called "friendslist.txt" inside your "data files" folder.-You will have to manually edit the friendslist.txt file, one name per line.-When you click a persons name on the Friends List it will populate your chat bar with-The friend names will appear under where you created the label earlier (even though it's not visible)>! **I may later on add a tutorial on how to allow the player to edit their friends list from within the game, so they don't have to manually do it… I'll reserve the next post for that tutorial.**>! Here's a screenshot of how mine ended up :)![](http://i46.photobucket.com/albums/f142/onfiya/coding/FL4.gif) Link to comment Share on other sites More sharing options...
RavenStar Posted September 1, 2010 Author Share Posted September 1, 2010 **Rewrote tutorial to use a new method for friends list, it's now stored server side.Edit: Crap I forgot to add a little code for the client-side, used to detect mouse click. Make sure you re-read the tutorial and add the missing part (if you haven't already got it).** Link to comment Share on other sites More sharing options...
erkro1 Posted September 1, 2010 Share Posted September 1, 2010 Wow, very thanks, i need that! :azn: Link to comment Share on other sites More sharing options...
Robin Posted September 1, 2010 Share Posted September 1, 2010 Having a variable store the max number of friends doesn't make it dynamic, it makes it static. If it were dynamic, it'd store the names in a dynamic array and would automatically changed the UBound when new strings were added.Client-side friends lists are fairly unhelpful. You simply need to re-download the client and *POOF*, there goes your friends list. I suggest you look into creating a few packets and store the lists server-side. You should also look at how I've handled things like conversations. It'll show you how to handle dynamic arrays.Also, using 1 label per friend in the list is a poor way of doing things. You should look at how I've handled things like the inventory. You can run through the array of friends and draw the text to the actual picturebox without having to use a label. This'll sort out the control mess you'll be left with from this tutorial. It'll also show you how to efficiently detect mouse events on a picturebox. Link to comment Share on other sites More sharing options...
RavenStar Posted September 1, 2010 Author Share Posted September 1, 2010 @Robin:> Having a variable store the max number of friends doesn't make it dynamic, it makes it static. If it were dynamic, it'd store the names in a dynamic array and would automatically changed the UBound when new strings were added.> > Client-side friends lists are fairly unhelpful. You simply need to re-download the client and *POOF*, there goes your friends list. I suggest you look into creating a few packets and store the lists server-side. You should also look at how I've handled things like conversations. It'll show you how to handle dynamic arrays.> > Also, using 1 label per friend in the list is a poor way of doing things. You should look at how I've handled things like the inventory. You can run through the array of friends and draw the text to the actual picturebox without having to use a label. This'll sort out the control mess you'll be left with from this tutorial. It'll also show you how to efficiently detect mouse events on a picturebox.I agree it isn't truly dynamic, what I meant by this was it uses object controls to create labels to store the friend name.As for storing them server-side, this is something I've already started to work on however I thought I'd leave this short tutorial here for those that don't care.Thanks for the tip on drawing the text instead of using labels, this never crossed my mind. I'll check out the code.Cheers.Edit:I was aware of the control mess, but as mentioned it never crossed my mind to directly draw the text inside of my used method. ^_^ ty Link to comment Share on other sites More sharing options...
Ertzel Posted September 1, 2010 Share Posted September 1, 2010 You might want to change it so you add the friends ingame instead of having to manually do it. If your changing it to be stored server side you deff will have to. Link to comment Share on other sites More sharing options...
RavenStar Posted September 2, 2010 Author Share Posted September 2, 2010 Yeah, I've started on a completely different method where the friendslist is stored server-side.It's all working, just need to add ability to add/edit friends then I'll write up a tutorial for it. I'll edit the first post with the new tutorial once I'm done. Link to comment Share on other sites More sharing options...
Robin Posted September 2, 2010 Share Posted September 2, 2010 Personally I'd add a GUI button to the friends list called 'Add Friend' which pops up a little dialogue box which you can type the player's name into. Link to comment Share on other sites More sharing options...
Coolguy6318 Posted September 3, 2010 Share Posted September 3, 2010 How do you make this work in eclipse stable? Link to comment Share on other sites More sharing options...
Robin Posted September 3, 2010 Share Posted September 3, 2010 @Coolguy6318:> How do you make this work in eclipse stable?You don't. You might as well leave this section if you're using Stable. Link to comment Share on other sites More sharing options...
Coolguy6318 Posted September 3, 2010 Share Posted September 3, 2010 Is there a section just for stable? Link to comment Share on other sites More sharing options...
Robin Posted September 3, 2010 Share Posted September 3, 2010 @Coolguy6318:> Is there a section just for stable?Yes, it's called the bin. Link to comment Share on other sites More sharing options...
Mulkaar Posted September 3, 2010 Share Posted September 3, 2010 "Yes, it's called the bin."Zing!Looks like a wrothy edit. Link to comment Share on other sites More sharing options...
Ertzel Posted September 3, 2010 Share Posted September 3, 2010 This new code looks a lot nicer, good job :D Link to comment Share on other sites More sharing options...
tmoney Posted September 4, 2010 Share Posted September 4, 2010 I'm having a bit of a problem with this script, the client side went great no problems. Then I got to the server side and followed the guide exactly how it said to. But im getting 2 errors.I HIGHLIGHTED WHERE IM GETTING THE ERRORS IN YELLOW! ALSO HERE IS 2 SCREENSHOTS:ModhandleData Error:![](http://runeworld.site11.com/1.bmp)ModserverTCP Error:![](http://runeworld.site11.com/2.bmp)HERE IS MY SOURCE CODE TO MY SERVERDOWNLOAD MY SERVER FILE WITH THE 2 ERRORS:[http://runeworld.site11.com/HELP.rar](http://runeworld.site11.com/HELP.rar) Link to comment Share on other sites More sharing options...
RavenStar Posted September 4, 2010 Author Share Posted September 4, 2010 @tmoney,There, I added an extra step to the tutorial in the first post, it's at the end highlighted in red.I was crazy tired when I wrote this so I forgot to add that :PAlso, from what I gather in your first screenshot, you're using the wrong code.You've put```HandleDataSub(SFriendList) = GetAddress(AddressOf HandleFriendsList) 'RavenStar```when that is only meant for the client-side.Try re-reading the tutorial and figure out where you went wrong. Link to comment Share on other sites More sharing options...
tmoney Posted September 4, 2010 Share Posted September 4, 2010 I've repeated this tutorial to it's exact words at least 5 times + and every outcome seems to have an error. It needs to be a bit more user friendly because ive done everything right then some of the code snipplets dont belong in certain areas then you get it setup and it doesnt want to work or it gives you a Mismatch runtime error.Very buggy IMO it could just be me, but im pretty sure ive ran through this tutorial enough to know im not the one messing up.Re-Look it raven and maybe make the code a bit more user friendly that already has variables set, defined and code snipplets placed in the right place. Or maybe even add screenies, thanks for the hope though i thought i had myself a friends list :) but ill figure one out some day. Link to comment Share on other sites More sharing options...
westin444 Posted September 4, 2010 Share Posted September 4, 2010 There is an error ravenstar.The fact is the enums on client and server must be identical.you need to add this server sidein modEnumerations find```' Make sure CMSG_COUNT is below everything else CMSG_COUNT```and add this before it```CAddFriend```You also are issing the HandleAddFriend sub server side.Add this to the bottom of modHandleData (Server)```Sub HandleAddFriend(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim name As StringDim F As LongDim fname As StringDim Buffer As clsBufferSet Buffer = New clsBuffer Buffer.WriteBytes Data() name = Buffer.ReadString Set Buffer = Nothingfname = App.Path & "\data\friends\" & GetPlayerName(Index) & ".txt" F = FreeFile Open fname For Append As #F Print #F, name Close #F Call SendFriendsList(Index)End Sub```You also need to create the friends directory if it doesn't existin modGeneral (server)find```If LCase$(Dir(App.Path & "\data\accounts", vbDirectory)) <> "accounts" Then Call MkDir(App.Path & "\data\accounts") End If```add after```If LCase$(Dir(App.Path & "\data\friends", vbDirectory)) <> "friends" Then Call MkDir(App.Path & "\data\friends") End If```also… (client)```Dim n As Long strinput = InputBox("Friend's Name : ", "Add Friend") If StrPtr(strinput) = 0 Or strinput = vbNullString Then Exit Sub n = CLng(Trim$(strinput)) Call SendAddFriend(n)```should be```Dim n As LongDim strinput As String strinput = InputBox("Friend's Name : ", "Add Friend") If StrPtr(strinput) = 0 Or strinput = vbNullString Then Exit Sub Call SendAddFriend(Trim$(strinput))```andthis```'RavenStar'Add new friendPublic Sub SendAddFriend(ByVal Name As String) Dim Buffer As clsBuffer Set Buffer = New clsBuffer Buffer.WriteLong CAddFriend Buffer.WriteLong Name SendData Buffer.ToArray() Set Buffer = NothingEnd Sub```should be```Public Sub SendAddFriend(ByVal Name As String) Dim Buffer As clsBuffer Set Buffer = New clsBuffer Buffer.WriteLong CAddFriend Buffer.WriteString Name SendData Buffer.ToArray() Set Buffer = NothingEnd Sub``` I think that solves most of the problems.EDIT:If you've already installed this make sure remove the Exit Sub from HandleAddFriend Link to comment Share on other sites More sharing options...
shadowchris Posted September 4, 2010 Share Posted September 4, 2010 Cool system. I will be sure to add this later Link to comment Share on other sites More sharing options...
erkro1 Posted September 4, 2010 Share Posted September 4, 2010 When I click on Add Friend, there comes and window, I put in name of my friends account.But when I press Ok, nothing happensSomeone? Link to comment Share on other sites More sharing options...
westin444 Posted September 4, 2010 Share Posted September 4, 2010 Actually there are a couple things more to do.in ModServerTCP change the current sub SendFriendsList to this one:```' Lets send their friend list - RavenStarSub SendFriendsList(ByVal Index As Long) Dim Buffer As clsBuffer Dim I As Long Dim fname As String Dim ff As Integer Dim RAW As String Dim Txt() As String fname = App.Path & "\data\friends\" & GetPlayerName(Index) & ".txt" If Not (FileExist(fname, True)) Then ' Create the friend list if it doesn't exist.. Open App.Path & "\data\friends\" & GetPlayerName(Index) & ".txt" For Output As #1 Close #1 End If ff = FreeFile Open fname For Binary As #ff RAW = String$(LOF(ff), 32) Get #ff, 1, RAW Close #ff Txt$ = Split(RAW, vbCrLf) Set Buffer = New clsBuffer Buffer.WriteLong SFriendList For I = LBound(Txt$) To UBound(Txt$) Buffer.WriteString Txt$(I) Next SendDataTo Index, Buffer.ToArray() Set Buffer = NothingEnd Sub```ALSO: MADE AN EDIT TO MY ABOVE POST, YOU NEED TO CHANGE IT FOR IT TO WORK. Link to comment Share on other sites More sharing options...
erkro1 Posted September 4, 2010 Share Posted September 4, 2010 Doesn't work, when I put that in ModServerTCP, nothing happens again.And when I start client (when server is online), i see an weird message :![](http://i757.photobucket.com/albums/xx220/erkro1/naamloos.jpg) Link to comment Share on other sites More sharing options...
westin444 Posted September 4, 2010 Share Posted September 4, 2010 dang… i forgot to remove the debugging msgbox. Recopy the above post Link to comment Share on other sites More sharing options...
erkro1 Posted September 4, 2010 Share Posted September 4, 2010 Fixed, but I still can't add friends… Link to comment Share on other sites More sharing options...
westin444 Posted September 4, 2010 Share Posted September 4, 2010 did you add all my code? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now