Bonk Posted October 12, 2011 Author Share Posted October 12, 2011 Hey :)I'm trying to rip the chat bubbles from CS:DE, except I don't want the picture of the bubble behind it. I thought I'd gather some information about how it works before copying and pasting tonnes of code.Here's the code I found in ModDirectx8:```Public Sub DrawChatBubble(ByVal index As Long)Dim theArray() As String, x As Long, y As Long, i As Long, MaxWidth As Long, x2 As Long, y2 As Long, colour As Long With chatBubble(index) If .targetType = TARGET_TYPE_PLAYER Then ' it's a player If GetPlayerMap(.target) = GetPlayerMap(MyIndex) Then ' change the colour depending on access colour = DarkBrown ' it's on our map - get co-ords x = ConvertMapX((Player(.target).x * 32) + Player(.target).xOffset) + 16 y = ConvertMapY((Player(.target).y * 32) + Player(.target).yOffset) - 32 ' word wrap the text WordWrap_Array .Msg, ChatBubbleWidth, theArray ' find max width For i = 1 To UBound(theArray) If EngineGetTextWidth(Font_Default, theArray(i)) > MaxWidth Then MaxWidth = EngineGetTextWidth(Font_Default, theArray(i)) Next ' calculate the new position x2 = x - (MaxWidth \ 2) y2 = y - (UBound(theArray) * 12) ' render each line centralised For i = 1 To UBound(theArray) RenderText Font_Georgia, theArray(i), x - (EngineGetTextWidth(Font_Default, theArray(i)) / 2), y2, colour y2 = y2 + 12 Next End If End If ' check if it's timed out - close it if so If .timer + 5000 < GetTickCount Then .active = False End If End WithEnd Sub```Is anything sent back and forwards from the server? Is there any extra code I need to move about in order to make it work properly? Link to comment Share on other sites More sharing options...
Robin Posted October 12, 2011 Share Posted October 12, 2011 Yes. Search 'ChatBubble' and you'll find all the code yourself. Link to comment Share on other sites More sharing options...
Rob Janes Posted October 12, 2011 Share Posted October 12, 2011 I probably wouldn't try and build it off of this code, rather than using the ChatBubbles and trying to copy the whole ChatBubble Array. Look at the way it does 'DrawPlayerName' in EO. Give each player a 'Message' variabe in their PlayerRec. Then on the client, under the HandleSayMsg, make the Player(index).Message = the chat string. Then under the DrawPlayerName, you can simply copy the code for DrawText to also Draw the Message.Simply do an engine check timer afterwards to clear the message after x number of ticks. Link to comment Share on other sites More sharing options...
PD Posted October 12, 2011 Share Posted October 12, 2011 @Rob:> I probably wouldn't try and build it off of this code, rather than using the ChatBubbles and trying to copy the whole ChatBubble Array. Look at the way it does 'DrawPlayerName' in EO. Give each player a 'Message' variabe in their PlayerRec. Then on the client, under the HandleSayMsg, make the Player(index).Message = the chat string. Then under the DrawPlayerName, you can simply copy the code for DrawText to also Draw the Message.> > Simply do an engine check timer afterwards to clear the message after x number of ticks.Yes I'd do what Rob said but mind you what he said doesn't take into account the string's lenght so text wrapping would also be needed. Link to comment Share on other sites More sharing options...
Rob Janes Posted October 12, 2011 Share Posted October 12, 2011 Copy/Paste the WordWrap function from CS:DE should suffice ;) Link to comment Share on other sites More sharing options...
PD Posted October 12, 2011 Share Posted October 12, 2011 @Rob:> Copy/Paste the WordWrap function from CS:DE should suffice ;)What's with the face? I was only pointing it out :P Link to comment Share on other sites More sharing options...
Robin Posted October 12, 2011 Share Posted October 12, 2011 Yeah, unless you have the DX8 font system in EO it's not going to work out very well.You'll need to change it to use the GetWidth function from EO. Link to comment Share on other sites More sharing options...
Rob Janes Posted October 12, 2011 Share Posted October 12, 2011 Touchez indeed! I forgot about that. I haven't touched EO in a long time now, I went from memory lol. Link to comment Share on other sites More sharing options...
Bonk Posted October 12, 2011 Author Share Posted October 12, 2011 Large generalisation, but in theory, everything in CS:DE is the same as EO, except for the graphics. So if I'm not drawing the bubble shape behind the text, will I have to modify it much? Link to comment Share on other sites More sharing options...
Robin Posted October 12, 2011 Share Posted October 12, 2011 Just go and try instead of asking us all these questions.If you come across any problems then feel free to post, but asking all this shit before you even attempted it is just silly. Link to comment Share on other sites More sharing options...
Rob Janes Posted October 12, 2011 Share Posted October 12, 2011 You would need a method to transfer the 'message' above a players head between the client/server. This is already done via HandleSayMessage. So the easiest method is addSayMsg as String inside the PlayerRec.On the HandleSayMessage, make Player(index).SayMsg = Message. Then under DrawName, where it does DrawText (String, blah blah blah blah), copy and paste that and rather than make it Draw Player(index).name, make it Draw Player(index).SayMsg.There are significant differences between CS:DE and EO, the graphics engine, text engine. The packet engine is the same, but above that, everything is improved upon and better in CS:DE (compared to EO) Link to comment Share on other sites More sharing options...
Bonk Posted October 12, 2011 Author Share Posted October 12, 2011 On compiling the client, VB highlights this line, at Font_Default.``` 'Add up the size size = size + Font_Default.HeaderInfo.CharWidth(Asc(Mid$(Text, i, 1)))```D'ya have any idea what I did wrong? Link to comment Share on other sites More sharing options...
Robin Posted October 12, 2011 Share Posted October 12, 2011 -_- Link to comment Share on other sites More sharing options...
Bonk Posted October 12, 2011 Author Share Posted October 12, 2011 TBH, I'm really not that good at programming, as you can probably tell. I'm going to use a really bad chat bubble tutorial I found that's specific to EO and focus on improving that. Should be fun, right? Sorry to have wasted your time, people. :( Link to comment Share on other sites More sharing options...
Rob Janes Posted October 12, 2011 Share Posted October 12, 2011 In the Server AND the Client, in modTypes, under Private Type PlayerRec add the following``` 'Message Message As String```On the Server, in modHandleData, in the Public Sub HandleSayMsg after the line that reads Call SayMsg_Map(GetPlayerMap(index), index, Msg, QBColor(White)) Add the following```Player(index).Message = MsgCall SendPlayerData(index)```In the server, go to modServerTCP and find Function PlayerData, after the line that says Buffer.WriteLong GetPlayerPK(index). Add the following```Buffer.WriteString Player(index).Message```In the client, in modHandleData, find Public Sub HandlePlayer. Below the line that says SetPlayerPK(i, Buffer.ReadLong), Add the following```'Load the Players MessagePlayer(i).Message = Buffer.ReadString```In the Client, in modText, under DrawPlayerName, Add this below where it draws the name```'Draw the Message Call DrawText(TexthDC, TextX, TextY - 20, Player(Index).Message, QBColor(BrightGreen))```I have to run for now i'll post a fix to make it center and word wrap as soon as I can ;) Link to comment Share on other sites More sharing options...
Rob Janes Posted October 12, 2011 Share Posted October 12, 2011 The missus wanted to run out so I'm on my phone now, once I get back I'll give ya the code to make it centered and word wrap, and disappear after 30 seconds or so. Link to comment Share on other sites More sharing options...
Bonk Posted October 13, 2011 Author Share Posted October 13, 2011 Seriously, Rob, I think I love you. Would you mind if I wrote this up in the tutorials? With credit, of course. Link to comment Share on other sites More sharing options...
Rob Janes Posted October 13, 2011 Share Posted October 13, 2011 Go for it, I forgot to fix up center/word-wrap for you last night, got caught up doing projectiles for CS:DE, I'll update this post soon. Link to comment Share on other sites More sharing options...
Bonk Posted October 13, 2011 Author Share Posted October 13, 2011 I tried implementing it again, but when I typed it all in, nothing happed. Is there anything specific I need to paste from CS:DE or is it just me being an idiot? Link to comment Share on other sites More sharing options...
Rob Janes Posted October 13, 2011 Share Posted October 13, 2011 All the code above works fine for a stock EO2.0, perhaps you missed something? Link to comment Share on other sites More sharing options...
Rob Janes Posted October 13, 2011 Share Posted October 13, 2011 Here's a change so that it centers.In the client, modText, in the Sub DrawName, after the line that reads' Draw name Call DrawText(TexthDC, TextX, TextY, Name, color)Add the following```'Message Position TextX = ConvertMapX(GetPlayerX(Index) * PIC_X) + Player(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(Player(Index).message))) TextY = TextY - 20 'Draw the Message Call DrawText(TexthDC, TextX, TextY, Player(Index).message, QBColor(White))```You would need to add a timer in the ServerLoop to clear the Player(index).message if you wanted it to disappear after a while ;) 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