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

[EO] Simple Chat Above a Player's Head


Justn
 Share

Recommended Posts

**EDIT: Don't Use This Until Its Fixed (Unless you want a ~~shitty~~ unprofessional game)**  :P
Well my friend Bonk was asking about this and it's something I have wanted also. Rob Janes wrote this code and it works perfectly… There is no chat bubble its just text (which I happen to like). All credits go to **Rob Janes** for the message code and to **Ryoku Hasu** for the text wrapping =)

Server

**modTypes**
Under **Private Type PlayerRec** (before 'End Type') add the following:
```
    'Message
    Message As String

```(you will have to do this to the client side as well)

**modHandleData**
In **Public Sub HandleSayMsg** find this line:
```
Call SayMsg_Map(GetPlayerMap(index), index, Msg, QBColor(White))
```Replace the whole line with this:
```
If Msg <= vbNullString Then Player(index).message = ""
    If Msg > vbNullString Then
    Call SayMsg_Map(GetPlayerMap(index), index, Msg, QBColor(White))
    End If

        Player(index).message = Msg
    Call SendPlayerData(index)
```(this simply changes it so that when the client sends the wipe null string, it doesn't show 'Name:' and a blank message in the chat box)

**modPlayer**
At the bottom of **Sub JoinGame** find where it says:
```
SendInGame index
```Under it add this :
```
Player(index).Message = ""

```(It simply makes sure we don't log in and have a message above our head from before)

**modServerTCP**
In **Function PlayerData** find this line:
```
Buffer.WriteLong GetPlayerPK(index)
```Under it add this:
```
Buffer.WriteString Player(index).Message

```

Client
**modHandleData**
In **Public Sub HandlePlayer** find this line:
```
SetPlayerPK(i, Buffer.ReadLong)
```Under it add this:
```
'Load the Players Message
Player(i).Message = Buffer.ReadString

```
**modText**
In **Public Sub DrawPlayerName** find this line:
```
Dim Name As String
```Under it add:
```
Dim x As Integer
Dim y As Integer
Dim wrapy As Integer
Dim wrap As Integer
Dim text As String
Dim SubString As String
    x = 1
    y = 1
```
Still in  **Public Sub DrawPlayerName** towards the bottom find:
```
' Draw name
    Call DrawText(TexthDC, TextX, TextY, Name, color)
```Under it add this:
```
text = Player(Index).Message
    Do While Len(text) > 45
        If y = 1 Then
        wrap = Len(text) Mod 45
        Else
        wrap = 45
    End If

    'We are going to split the string by spaces

    Dim ChatArray() As String
    ChatArray = Split(text, " ")

    'If our Array is larger than 1, we'll word wrap
    If UBound(ChatArray) > 0 Then
        Do Until Asc(Mid$(text, Len(text) - wrap, 1)) = 32
        wrap = wrap + 1
        Loop
  'If the Array has only 1 value, kill our loop and just skip ahead
    ElseIf UBound(ChatArray) <= 0 Then
        Exit Do
        wrap = 1
    End If

        SubString = Right$(text, wrap)
        TextX = ConvertMapX(GetPlayerX(Index) * PIC_X) + Player(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(SubString)))
        wrapy = TextY - (x * 20)
        'Draw the Message
        Call DrawText(TexthDC, TextX, wrapy, SubString, QBColor(BrightGreen))
        text = Left$(text, Len(text) - wrap)
        x = x + 1
        y = y + 1
    Loop
    TextX = ConvertMapX(GetPlayerX(Index) * PIC_X) + Player(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(text)))
    wrapy = TextY - (x * 20) 'Draw the Message
    Call DrawText(TexthDC, TextX, wrapy, text, QBColor(BrightGreen))
    ' Error handler
    Exit Sub
```(feel free to change BrightGreen to whatever color you need too)

**modInput**
In **HandleKeyPresses** find this:
```
' Say message
        If Len(ChatText) > 0 Then
            Call SayMsg(ChatText)
        End If
```Under it add this:
```
frmMain.tmrChat.Enabled = True

```
**modTypes**
Under **Private Type PlayerRec** (before 'End Type') add the following:
```
    'Message
    Message As String

```
Now open your **frmMain**
Add a new timer (yes we are using timers here) somewhere on the form.
Open the properties menu for the timer
[![](http://www.freemmorpgmaker.com/files/imagehost/pics/8f5e66b03d0c24211129fac489161cd3.bmp)](http://www.freemmorpgmaker.com/files/imagehost/#8f5e66b03d0c24211129fac489161cd3.bmp)
Name it : **tmrChat**
Set interval: **10000**(this can be changed depending on how long you want the text to display)
Set the enable to **false**

Click the timer and add this code:
```
Call SayMsg(vbNullString)
tmrChat.Enabled = False

```
And that should be it. =) Thanks to Rob Janes and Ryoku for their help (and patience) on making this work.

Here is a screenshot of how the text wrapping works..(smaller sentences look alot better)
[![](http://www.freemmorpgmaker.com/files/imagehost/pics/3fb93ea96137f2bdc607c2c5e020ea36.bmp)](http://www.freemmorpgmaker.com/files/imagehost/#3fb93ea96137f2bdc607c2c5e020ea36.bmp)
Link to comment
Share on other sites

Hey bonk I added it to the original post sorry I meant to add it but i just put it in parentheses 
hope you got it working =p

@jekeke123:

> awesome script

your just going around random pages on the forums and saying "looks great, nice job" did you even bother to read it?
Link to comment
Share on other sites

@SnowGear:

> Nice code Justn, you all should try using the leak-free text rendering with this code, it looks better with it.

Oh is that lightnings tutorial? I haven't even added that yet =/ can you change fonts with it too?

@Bonk:

> Elsewhere, now when I type, the text won't go off the screen. Do you get what I meant when I said I was a crap programmer?

Did you add a timer to frmMain and set it up right? It should all be there i'll look to see if i missed anything =/
Link to comment
Share on other sites

@Justn:

> Oh is that lightnings tutorial? I haven't even added that yet =/ can you change fonts with it too?
> Did you add a timer to frmMain and set it up right? It should all be there i'll look to see if i missed anything =/

Yes, lightnings tutorial. I THINK you can, if you change some code here and there, to change the font to your likings. Haven't tried it since I like Georgia font, but it shouldn't be too hard.
Link to comment
Share on other sites

@Justn:

> Oh is that lightnings tutorial? I haven't even added that yet =/ can you change fonts with it too?
> Did you add a timer to frmMain and set it up right? It should all be there i'll look to see if i missed anything =/

Yeah, the timer's set up properly and everything. Do you have a blank EO with this in it?
Link to comment
Share on other sites

@Bonk:

> Yeah, the timer's set up properly and everything. Do you have a blank EO with this in it?

I changed the tutorial a bit it was kinda confusing on a couple parts and my HandleSayMsg was a little different in my source than the stock EO.. I added it to fresh copy and it works.. Try to do it again if you still cant get it to work let me know and ill pm it to you =)))
Link to comment
Share on other sites

I knew that **exact** picture was going to posted here sooner or later about the timer  :P I wasn't even going to post it cause I knew how bad you dislike timers I tried to make it work in the serverloop but it deleted all players messages at the same time =( The only reason I did post it is cause one of your friends told me this

> there is absolutely nothing wrong with timers if they're used correctly.
>
> I'll defend that to the death.  Robin also bad mouthed INI files for a long time and I had defended those as well, now he uses them himself. ;)

If someone can please explain to me why I shouldn't use it ill get rid of it :)
Link to comment
Share on other sites

I've never 'bad mouthed' INI files. I bad mouthed the people who misused them to the point where the entire community was having looped harddrive checks and dragging the FPS in to the floor. It just so happens that some idiots took that as a warning not to use INI files at all.

Timers are not acceptable. Games are all about structured events. You want one thing to happen then another and then another. That's how the game loop works. We loop through the game logic, we render the tiles, we render the players, we render the fringe and then we render the interface.

When you add a timer you've got a completely uncontrollable event happening. It's not structured, it's not part of the order and it's not even accurate. Not only that but you should _never_ have data-controlling events like this client-side.

You can listen to Rob all you want, but you've got to remember that this is the guy who had a shooting system where the actual game projectiles were controlled by the client. You could literally hijack the physics system and turn all your bullets in to heat-seaking missiles. He does what works and leaves it at that. Sure, that's fine for him. But not being prepared to improve yourself when you haven't even started is just going to leave you with no skill, no understanding and no position.

This isn't about timers, this is about you giving up on doing a system properly because you couldn't get it to work the first time around. That's not the kind of mentality which you can get away with when it comes to game design. You either do your best or you do nothing at all. Mediocrity is rife in the industry, it's up to indy productions to give games their soul back. If you're not part of the solution then you're part of the problem. Especially the problem of people using this community to learn.

If someone comes on to this forum not understanding how to use the looped timer system and you come in posting some bullshit about a timer control then it's on your head when they take that as an acceptable method of timing events.

Hell, go download EE and ES and look at how they used timers. Now post how well _those_ engines run. The reason I can get my engine so stable and optimised is because I cut out all the bullshit like this.

> If someone can please explain to me why I shouldn't use it ill get rid of it

You already know the answer to that question. You knew how to do it properly, you couldn't get it to work so you gave up and did it the cheap, unoptimised, exploitable way. More than anything you simply need to learn how to use the structured timer system which is set in place for you and you need to learn how to handle data properly through the server. If you have one timer for this event what happens when you want to set up your next timed event? Or the one after that? Personally I have to add them for new systems all the time. What would happen if I decided to add all my systems through client-side timers? The entire game would play like shit.

If you're never going to learn then you're going to end up with a form literally covered in these shitty little controls and eventually the unordered events are going to cause a data conflict and you'll come back to this forum asking people why it doesn't work. I'll be here to point out the issue and tell you how to fix it. So we can avoid all that I'll tell you well in advance how this shit isn't acceptable.
Link to comment
Share on other sites

Cool I just didn't really know what the cons were.. Thanks for explaining it. I'm not too good at this kinda stuff. I was just given another suggestion and went with it instead.. I will redo this to work without a timer and try to make the txt look nicer =)

this wasn't the exact code I used but it was something like:

> If msg_Timer + (10000) < GetTickCount Then
>     call zeromemory() 
>     Player(i).Message = vbNullString
>         msg_Timer = GetTickCount
>         End If

I hope this was a good starting point but if im using the looping wrong completely please let me know…

For everyone else DO NOT use this and sorry I wasted everyone's time =p I'll update it when its finished
Link to comment
Share on other sites

Robin is correct on one sense, we're both thick headed people.  In this regard there's no problem with a timer sending a command to the server, it doesn't affect rendering, or gameplay, that's why I opted for a timer.  I think the point Robin is trying to make is that they should only be used when appropriate and if there's a better way to do something that do it the proper way.  Timers exist for a reason, and this is a very easy method that doesn't affect performance.  With a chat system like this, there is no need for structure heh.  My intent by the statement about ini files was to point out they had a bad reputation and I recall even robin posting the tommy lee pic for the use of an ini file before ;) people just need to understand when and where to use things.  For a simple project this tutorial and the use of timers is not a bad thing, just not the most professional way of doing something, but seeing as it's not a professional game, who cares ;)

And robin is right, I did use tuners in an old client for the wrong functions and it sucked so the key thing to learn here is use them when they're appropriate.

See, isn't this better than fighting about something haha, I have a lot of respect for Robin, we can butt heads on things like this but still remain civilized about it and at the end of the day, it makes no difference.  People should study us lol
Link to comment
Share on other sites

Thanks guys for the info I'm looking at the CS:DE source now to come up with ideas though Im confused about where the destroying of the chat bubble is =p.. Yes Rob my project isn't professional more of a hobby for me and some friends. Still though I will post a fix for everyone as soon as I find it. Cause I know bonk still really wants this =)
Link to comment
Share on other sites

PS I'm not saying your game isn't professional, Robin is a perfectionist and he will admit to that I'm sure.  He's rewritten several things over and over so that it functions better for him, and he's right about my methods, once I have things working as intended I don't continue to tweak it, that's just my own personal preference but it works for me and I know when and where to use the appropriate controls.  If you're learning, follow Robins advice
Link to comment
Share on other sites

@Justn:

> Thanks guys for the info I'm looking at the CS:DE source now to come up with ideas though Im confused about where the destroying of the chat bubble is =p.. Yes Rob my project isn't professional more of a hobby for me and some friends. Still though I will post a fix for everyone as soon as I find it. Cause I know bonk still really wants this =)

Look at the timer in the game loop.
Link to comment
Share on other sites

@Rob:

> PS I'm not saying your game isn't professional, Robin is a perfectionist and he will admit to that I'm sure.  He's rewritten several things over and over so that it functions better for him, and he's right about my methods, once I have things working as intended I don't continue to tweak it, that's just my own personal preference.

We should have children. Then we'd have someone who isn't so extreme and was a bit of both. xD
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...