This stock allows you to play a sound to all clients as if some player is saying it through his microphone. It shows the voice activation on the right side of the screen.
You can only play one sound at a time. If there is currently a sound played or a bot is voicechatting the playing is stopped and your sound is played instead.
Huge thanks to javalia, who helped finding out the struct of the RawAudio user message.
PHP Code:
/**
* Plays a soundfile as if the player is using voicecomm.
*
* The voiceindicator is shown on the right, as if the players is talking.
*
* @param emitter The player who's speaking.
* @param soundfile Path to the soundfile relative to the sound/ folder.
* @param length Length in seconds how long the hud "voiceindicator" is shown.
* @param pitch The pitch of the audiofile.
* @return True on success, false on failure.
*/
stock bool:SendVoiceCommAll(const emitter, const String:soundfile[], Float:length = 0.0, pitch = 100)
{
new Handle:hBf = StartMessageAll("RawAudio");
if(hBf != INVALID_HANDLE)
{
BfWriteByte(hBf, pitch);
BfWriteByte(hBf, emitter);
BfWriteFloat(hBf, length);
BfWriteString(hBf, soundfile);
EndMessage();
return true;
}
return false;
}
__________________