Other great resources: Official JS API docs, Scripting Forum
audioAlert(filename,pos,despam)
Aubergine
Â
Code
/* #######################################################################################
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: Throttle 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
// 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);
}
}
Availability
Requires:
- Warzone 3.1 Beta 1 and above.
See also
Related articles:
- Audio (Sound) – guide to modding game audio and a complete directory of all audio bundled with Warzone
- Enhanced SitRep Mod – a mod that makes extensive use of the audioAlert() function
- playSound() – the JS API function for playing audio files
Â