Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Player Messages
#1
http://web.miragesource.com/forums/viewt...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?
Reply
#2
This is how most "big" game companies do things with messages, menus and errors.
Reply
#3
Any other thoughts?

Think I should add it to MS4 so you guys know what I mean?
Reply
#4
Sure, I'd like to see it.
Reply
#5
Dugor would never do 1337 damage. Sorry. >.>
Reply
#6
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.
Reply
#7
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?
Reply
#8
Very good idea. I WILL implement them asap.
Reply
#9
I'll probably add it to MS4 next week. Going on a vacation this weekend.
Reply
#10
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)