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

CS:DE to EO conversion


Bonk
 Share

Recommended Posts

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 With
End 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

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

@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

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 add

SayMsg 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

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

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

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 = Msg
Call 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 Message
Player(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

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

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...