-
Notifications
You must be signed in to change notification settings - Fork 40
ServerSide_GlobalSounds
The function G_GlobalSound was added in revision r33. This function allows for the server to tell all connected clients to play a sound.
In all honesty, the way sounds are played is pretty complex--local only sounds are triggered by clients directly, while most other sounds are triggered from events/player states/entity states contained in the snapshots sent out by the server.
This addition should significantly enhance the ability to add sounds to events in gameplay. It provides the "qagame" module direct control over what sounds to play, and when to play them.
The rationale for this feature is that, in all honesty, the gameplay experience can be significantly enhanced if certain gameplay events are announced globally--think of it like the TV/Radio announcer for a football (soccer) match, versus the announcer at the stadium. The TV/Radio announcer is much more engaging since he or she is actually describing what is happening, while the announcer at the stadium merely declares that an event has occurred.
There are some considerations however when employing this function--see the section below.
# G_GlobalSound first initializes a "game entity," "te." # G_GlobalSound aborts if there is a bad parameter passed to it. Continuing would cause the nasty crash described below. # Since the function can really cause problems, I added an error message when compiling a "DEBUG" build. # It then defines "te" as a temporary entity with the EV_GLOBAL_SOUND event. Temp entities are used for creating events at particular positions. # The code then defines the parameter for the EV_GLOBAL_SOUND event as the soundIndex passed to G_GlobalSound. # It then sets a broadcast flag for the entity, which is processed by the server executable on the next snapshot, where the server server executable will tell all the connected clients to play the sound.
The sound to be played must be assigned a "sound index" first. Then the call to G_GlobalSound can be made. To do this, initialize an `int` and then set it's value to the function G_SoundIndex. Then call G_GlobalSound with the `int` as a parameter.
- Note:*
Doing this can and will crash clients when they receive the instruction to play a sound that has not been indexed. It will leave them on their desktop with nothing more than an obscure "S_FindName" error message.
You can call G_SoundIndex with a reference to a "char" variable instead--however this provides for the possibility of the above client crash if you have not properly assigned the char a value.
Also, there is a limit to the maximum number of sounds a client can have, so this function must be used wisely.