![]() |
Messaging - author: [neural9] | ||||
Messages are so fundementally important to good persona games that no mod should ever be without. This simple tutorial covers the basics of sending messages to players in the game. As a note, please realise that there are other and more simpler ways to do the functions explained in this tutorial. The point of this tutorial is to examine objects in the game so that a good understanding of how things work is elicited. Some 'other' methods are discussed at the end.
There are several reasons you would want to send messages to people in the game. Firstly, chatting to others enhances the experience. Messages to everyone, messaging to your team in a CTF or TF game, or perhaps personal messages to individual players. Secondly, many events that happen in the game require other players to be notified. Capturing a flag, dying or camping may be some examples. Whatever your particular requirements are, there are three modes of messaging; all, team & individual. By examing how these functions work, we can modify the code to suit any purpose. Broadcasting Broadcasting is sending a message to everyone in the current level. The code to do this (stolen from the actor class in the Unreal source) is :
What this function actually does is accept a message string and a boolean variable. It then cycles trough all of the pawns in the level, as it comes across one which is actually a player it calls the method of the pawn to display a message on their screen. The main body of the code starts with an IF statement. The if statement actually references the 'Level' object which in turn has a 'Game' object which in turn has a method which is called AllowsBroadcast(). The AllowsBroadcast takes two parameters, the object which is calling it, and the length of the message. If the game does allow broadcasting, i.e. it returns true, the code starts it's 'for' cycle. The 'for' loop utilizes a 'level' object list called 'PawnList'. This maintains all current pawns in the game. Remember though, that all objects in the game are pawns, not just the human players, so we need some way of checking if the pawns we're referencing are human. Well, we're in luck. Each pawn has a boolean property called 'bIsPlayer' which is set by the engine when a pawn is created. To cycle through the list, call the 'nextPawn' method of the current pawn. If the pawn is a player, then calling the pawn's 'ClientMessage' method will send the passed parameter (the message) to the actual client machine. Messaging Individuals Sending a message to individuals is similar to broadcasting. Sort of selective broadcasting you could say. Using the code :
The code to send individual messages differs only in adding an extra parameter to the function (which we have called by a different name) and adding an extra condition to the final IF statement. All we have done is added a reference to the name of the player, and ensuring that when we cycle through the pawns, we check that we we find a player, his or her name is the same one that is passed to the function.
Alternatively, you could attach the function to various events & other functions in the game code itself. For example, if you wanted to send the player who bumps into you a message, you could use the 'actor' objects' 'touch' function like this :
You could use the same method of selective broadcasting to send messages to teams in capture the flag or team fortress games. When you create a team actor object, you would have to add a 'teamname' property. By modifying the MesssageIndividual function to accept a teamname rather than a playername, you could select players to send the message to. |
||||
suggestions? questions? comments? please send them all to ray@beyondunreal.com |
copyright
2001 ray davis. this site and all content belongs to me unless
otherwise noted, with the exception of some tutorials. the authors
retain the rights to their material, and are hosted here with their
express permission. everything else is mine though, so don't steal
it. bastards. privacy |