Mirage Source
Player Messages - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51)
+----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44)
+----- Thread: Player Messages (/showthread.php?tid=2664)



Player Messages - Jacob - 31-03-2009

http://web.miragesource.com/forums/viewtopic.php?f=120&t=3719&start=500#p60658

Rian mentioned a different way to do the messages that are sent to players, such as "This is a safe zone!" and so on. Instead of doing different modules for each of those, it would be better to load in an external file with the messages. Each message would have an ID associated with it so you know what message is which. For messages like player damage and npc damage, I've come up with a way to send just what you need to fill in the message.

Pseudo
Code:
SendClientMessage(MessageID as long, Optional args as string)
MessageID would be the corresponding ID client side. The optional args would be for what that message needs.

This would be client side
Code:
Private StringConst() As String

' Load our strings - Would be a text file for the real thing
Private Sub LoadStrings()
    ReDim StringConst(0 To 4)
    StringConst(0) = "Just a test message."
    StringConst(1) = "A test message with a replace %1%."
    StringConst(2) = "%1% test messages %2%"
    StringConst(3) = "%1% Test is a mother %2% that will %3% you."
    StringConst(4) = "%1% hits you for %2% damage."
End Sub

Code:
' our function to replace strings
Private Function ReplaceStr(ByRef MessageID As Long, Optional ByRef nString As String) As String
Dim i As Long
Dim args() As String

    ReplaceStr = "Error!"
    
    ' First check if it's a valid id
    If MessageID < 0 Then Exit Function
    If MessageID > UBound(StringConst) Then Exit Function
    
    ' Set our return string
    ReplaceStr = StringConst(MessageID)
    
    ' Split the nString
    If LenB(nString) > 0 Then
        args() = Split(nString, ",")
        For i = 0 To UBound(args)
            ReplaceStr = Replace(ReplaceStr, "%" & i + 1 & "%", args(i))
        Next
    End If
End Function

Example of use:
Code:
Debug.Print ReplaceStr(2, "fucking,rock")
    Debug.Print ReplaceStr(3, "this,fucker,kill")
    Debug.Print ReplaceStr(4, "Dugor,1337")

Thoughts?


Re: Player Messages - Egon - 31-03-2009

This is how most "big" game companies do things with messages, menus and errors.


Re: Player Messages - Jacob - 01-04-2009

Any other thoughts?

Think I should add it to MS4 so you guys know what I mean?


Re: Player Messages - Tony - 01-04-2009

Sure, I'd like to see it.


Re: Player Messages - Matt - 01-04-2009

Dugor would never do 1337 damage. Sorry. >.>


Re: Player Messages - grimsk8ter11 - 01-04-2009

This is common practice and probably a good feature to have. It is actually called string tables to be formal, usually loaded from a file with a corresponding name or number to each so that once loaded into the table they can be easily referenced.

You could implement bloom filters for visual basic as well and name them by strings like "AttackMessage1" or however felt necessary, bloom filters can filter thousands of hits a second.

I have also been playing with bloom filters in Visual basic to use archives for large file sets. You can have over a thousand archives with thousands of files each in my C tests and still find if an archive has it and which one has it in under a few seconds. So it should handle a small group of strings very well, though hash tables may be more effective.


Re: Player Messages - Tony - 02-04-2009

grimsk8ter11 Wrote:This is common practice and probably a good feature to have. It is actually called string tables to be formal, usually loaded from a file with a corresponding name or number to each so that once loaded into the table they can be easily referenced.

You could implement bloom filters for visual basic as well and name them by strings like "AttackMessage1" or however felt necessary, bloom filters can filter thousands of hits a second.

I have also been playing with bloom filters in Visual basic to use archives for large file sets. You can have over a thousand archives with thousands of files each in my C tests and still find if an archive has it and which one has it in under a few seconds. So it should handle a small group of strings very well, though hash tables may be more effective.

What's bloom filters?


Re: Player Messages - Dragoons Master - 02-04-2009

Very good idea. I WILL implement them asap.


Re: Player Messages - Jacob - 02-04-2009

I'll probably add it to MS4 next week. Going on a vacation this weekend.


Re: Player Messages - Nean - 02-04-2009

Dugor Wrote:I'll probably add it to MS4 next week. Going on a vacation this weekend.

Awesome. You don't know how glad I am to hear, that MS4 will be making progress again.