Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Throttled alternative for playSound(). |
Code
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
/* ############################################################################################################################################################################### audioAlert.js v0.1 audioAlert(filename, pos despam) -- plays an audio alert to the human player * filename -- Required: Filename (including .ogg extension) of audio file to play * pos -- Optional: Display a beacon on mini map by passing in a game object * despam -- Optional: TimeThrottle (in ms) before this alert can be played again, default 2000 ########################################################################################the alert, default 2000ms before playing it again ####################################################################################### */ // Play an audio alert (de-spammed): function audioAlert(filename, pos, despam) { if ( (!(filename in audioAlert.despam)) || audioAlert.despam[filename] < gameTime ) { // define when this particular alert can next be played audioAlert.despam[filename] = gameTime + (despam || 2000); // default to 2 second despam // play sound and show beacom where the event occurred (!!pos) ? playSound(filename,pos.x,pos.y,pos.z) : playSound(filename); } } // Lookup table of time when an alert was last played audioAlert.despam = {}; |
Parameters
The audioAlert() function has the following parameters...
Parameter | Mandatory | Type | Notes |
---|---|---|---|
filename | String | The filename of the audio file to play, in quotes, for example "pcv476.ogg". The audio file must be properly defined in the game config files - for more details, Audio (Sound). A list of all audio included with Warzone can be found in the Audio Directory. | |
pos | Game object
| If you want to show a beacon on the mini map when the sound is played, pass in a game object (or any other object that has x,y,z properties). If you want a custom 'despam' (see below) but without a beacon, pass in | |
despam | Number | How long before this particular audio file can be played again? Defaults to 2000 milliseconds unless you specify otherwise. |
Example
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// welcome player to the game eventStartLevel() { audioAlert("pcv476.ogg"); } // tell me when a structure is destroyed (but no more than once per 5 seconds) eventDestroyed(victim) { if (victim.type == STRUCTURE && !victim.status) { audioAlert("pcv340.ogg", victim, 5000); } } |
Div | ||
---|---|---|
| ||
This function was created during development of the Enhanced SitRep Mod. |
Div | ||
---|---|---|
| ||
AvailabilityRequires:
|
Div | ||
---|---|---|
| ||
See alsoRelated articles:
|