{"name":"playSound","operator":null,"title":"playSound","type":"command","url":"https://community.bistudio.com/wiki/playSound","revid":349659,"updated":"2023-11-18T17:02:31Z","groups":["Sounds"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":"local","server_exec":false},"exec":null,"description":"Plays a sound from CfgSounds. Sound can be defined in missionConfigFile, configFile or campaignConfigFile.","syntaxes":[{"syntax":"playSound soundName","since":null,"effect":null,"exec":null,"params":[{"name":"soundName","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"soundName: String"}],"returns":{"type":"Object","types":["Object"],"description":"the speaker object (Nothing before Arma 3 v2.00)","text":"Object - the speaker object (Nothing before Arma 3 v2.00)"},"form":"unary","operator":null,"left":null,"right":{"text":"soundName","types":["String"]}},{"syntax":"playSound [soundName, isSpeech, offset]","since":null,"effect":null,"exec":null,"params":[{"name":"soundName","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"soundName: String"},{"name":"isSpeech","type":"Boolean or Arma 3 v2.04 Number","optional":true,"default":"false","description":"0/false = play as sound (fadeSound applies)\n- 1/true = play as speech (fadeSpeech applies), filters are not applied to it (i.e. house or vehicle interior one)\n- 2 = play as sound (fadeSound applies) without interior/vehicle muffling","types":["Boolean","Number"],"since":null,"text":"isSpeech: Boolean or Arma 3 v2.04 Number - (Optional, default false)\n- 0/false = play as sound (fadeSound applies)\n- 1/true = play as speech (fadeSpeech applies), filters are not applied to it (i.e. house or vehicle interior one)\n- 2 = play as sound (fadeSound applies) without interior/vehicle muffling"},{"name":"offset","type":"Number","optional":true,"default":"0","description":"offset in seconds. Same as playMusic","types":["Number"],"since":"arma3 2.00","text":"offset: Number - (Optional, default 0) offset in seconds. Same as playMusic"}],"returns":{"type":"Object","types":["Object"],"description":"the speaker object (Nothing before Arma 3 v2.00)","text":"Object - the speaker object (Nothing before Arma 3 v2.00)"},"form":"unary","operator":null,"left":null,"right":{"text":"[soundName, isSpeech, offset]","types":["Array"]}}],"examples":[{"text":"```sqf\nplaySound \"soundname\";\n```","code":["playSound \"soundname\";"]},{"text":"Start a sound and then stop it after 1.2 second:\n\n```sqf\nplaySound \"AlarmCar\";\n0 spawn\n{\n    _sound = ASLToAGL [0,0,0] nearestObject \"#soundonvehicle\";\n    sleep 1.2;\n    deleteVehicle _sound;\n};\n\n// since Arma 3 v2.00\n_source = playSound \"AlarmCar\";\n_source spawn\n{\n    sleep 1.2;\n    deleteVehicle _this;\n};\n```","code":["playSound \"AlarmCar\";\n0 spawn\n{\n\t_sound = ASLToAGL [0,0,0] nearestObject \"#soundonvehicle\";\n\tsleep 1.2;\n\tdeleteVehicle _sound;\n};\n\n// since Arma 3 v2.00\n_source = playSound \"AlarmCar\";\n_source spawn\n{\n\tsleep 1.2;\n\tdeleteVehicle _this;\n};"]},{"text":"Start a sound and wait until it is finished:\n\n```sqf\nplaySound \"Alarm\";\nhint \"Started!\";\n0 spawn\n{\n    _sound = ASLToAGL [0,0,0] nearestObject \"#soundonvehicle\";\n    waitUntil {isNull _sound};\n    hint \"Finished!\";\n};\n\n// since Arma 3 v2.00\nprivate _source = playSound \"Alarm\";\n_source spawn\n{\n    waitUntil { isNull _this };\n    hint \"Finished!\";\n};\n```","code":["playSound \"Alarm\";\nhint \"Started!\";\n0 spawn\n{\n\t_sound = ASLToAGL [0,0,0] nearestObject \"#soundonvehicle\";\n\twaitUntil {isNull _sound};\n\thint \"Finished!\";\n};\n\n// since Arma 3 v2.00\nprivate _source = playSound \"Alarm\";\n_source spawn\n{\n\twaitUntil { isNull _this };\n\thint \"Finished!\";\n};"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["playSound3D","sideRadio","say","playMusic","say2D","say3D","createSoundSource","playSoundUI"],"notes":[{"user":"Hardrock","date":"2006-08-04T10:57:00Z","text":"*Notes from before the conversion:*\n\nFor dialogue involving living units it is better to use say,\nplaySound will play a sound at the location of the player,\nsay will play a sound at the location of the unit that is speaking, and it will only play that sound if the unit is alive."},{"user":"PiZZADOX","date":"2014-12-28T08:22:00Z","text":"As you may have noticed, the parameter for playsound/say3d that deals with the \"volume\" of the sound played has little to do with the effective loudness heard in game. What it is alters is the drop off for fading the sound at a distance. A higher decibel or integer value will increase the distance before any sort of fading will take place. The actual volume of the sound file played will factor in to this, as it does throughout the playing action.\n==== Amplifying the Sound ====\nModifying the effective volume of sounds played by the engine is possible by \"spamming\" the sounds. By quickly playing the sounds overtop of one another, you can effectively amplify the volume\n\nThis example\n\n```sqf\nplaySound \"soundname\";\nplaySound \"soundname\";\n```\n\nWill effectively amplify the sound by a sensed 2x. The volume of the sound file itself will still affect the sound volume as it appears as though the arma engine has no normalization for sound files added to it.\n\n> [!NOTE]\n> This technique may cause issues in sound quality in large multiplayer servers. I observed multiple instances when a triggered sound amplified with this method was out of sync with each other. Timing of the individual commands sent over the network is probably the issue. Recommend you compile your amplification code into a single finished function for better syncing for clients not activating the action/far away from the activation position."}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Sounds","Introduced with Operation Flashpoint version 1.00","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Scripting Commands: Local Effect","Take On Helicopters: Scripting Commands"]}