http://web.miragesource.com/forums/viewtopic.php?f=120&t=3719&start=500#p60658Rian 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?