Raised This Month: $ Target: $400
 0% 

How to play custom sound?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Master Cake
Junior Member
Join Date: May 2020
Location: Planet Earth
Old 05-16-2020 , 16:14   How to play custom sound?
Reply With Quote #1

Hello there! I decided to make simple plugin for playing my custom sounds.

Here is code [SourceMod 10 build, TF2]:
Code:
public OnPluginStart()
{
	RegConsoleCmd("sm_soundcheck", S_Command); //Reg console commnd for all
}

public OnMapStart()
{
	PrecacheSound("custom/w_sound.wav"); //Pre-cache sound
	AddFileToDownloadsTable("sound/custom/w_sound.wav"); //Add to donwloads
}

public Action:S_Command(myClient, args)
{
    	ReplyToCommand(myClient, "[SM] Can you hear sound?"); //Reply
    	EmitSoundToClient(myClient, "custom/w_sound.wav"); //Play sound with Emit func
}
But that's doesn't work. IF I put file into tf/download/sound/custom/ directory on my dedi server. What am I doing wrong? Thanks

Last edited by Master Cake; 05-16-2020 at 16:15.
Master Cake is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 05-16-2020 , 20:19   Re: How to play custom sound?
Reply With Quote #2

Here's how I would do it for TF2. When an Admin types !makesound it will play the voice of the Announcer saying 'Amazing!'.

Code:
#pragma semicolon 1
#include <sourcemod>
#include <tf2_stocks>

#define PLUGIN_VERSION			"1.0"

#define SOUND1	"vo/announcer_am_killstreak03.mp3"

public Plugin:myinfo = {
	name		= "Test a Sound",
	author		= "PC Gamer",
	description	= "Plays a Sound for All Players",
	version		= PLUGIN_VERSION,
	url = "https://forums.alliedmods.net"
}

public OnPluginStart()
{
	RegAdminCmd("sm_makesound", Command_makesound, ADMFLAG_SLAY, "Play a Sound");
}

public OnMapStart()
{
	PrecacheSound(SOUND1);
}

public Action:Command_makesound(client, args)
{
	EmitSoundToAll(SOUND1);
	
	return Plugin_Handled;
}
PC Gamer is offline
Master Cake
Junior Member
Join Date: May 2020
Location: Planet Earth
Old 05-17-2020 , 09:34   Re: How to play custom sound?
Reply With Quote #3

Quote:
Originally Posted by PC Gamer View Post
Here's how I would do it for TF2. When an Admin types !makesound it will play the voice of the Announcer saying 'Amazing!'.

Code:
public OnMapStart()
{
	PrecacheSound(SOUND1);
}

public Action:Command_makesound(client, args)
{
	EmitSoundToAll(SOUND1);
	
	return Plugin_Handled;
}
It seems you don't use function to add download table. But my problem is that I don't quite understand where I have to store my custom files on dedicated server.
Master Cake is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 05-17-2020 , 11:06   Re: How to play custom sound?
Reply With Quote #4

You need to put your sounds to tf/sound/ (tf/sound/custom in your case) directory of your server.
tf/download/sound/ is used only by client as i know.
__________________

Last edited by MAGNAT2645; 05-17-2020 at 11:07.
MAGNAT2645 is offline
Master Cake
Junior Member
Join Date: May 2020
Location: Planet Earth
Old 05-17-2020 , 11:48   Re: How to play custom sound?
Reply With Quote #5

Quote:
Originally Posted by MAGNAT2645 View Post
You need to put your sounds to tf/sound/ (tf/sound/custom in your case) directory of your server.
tf/download/sound/ is used only by client as i know.
Ok, I will check
Master Cake is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 05-17-2020 , 16:21   Re: How to play custom sound?
Reply With Quote #6

I didn't add the sound of the Announcers voice to the downloads table since it already exists on the players computer. It was installed with the game.

As MAGNAT2645 stated, you will need to place your .wav file in tf/sound/custom/ folder. You will also need a way to send the sound files to the players, either by adding it with the AddFileToDownloadsTable or using a fastdl server and plugin like: https://forums.alliedmods.net/showthread.php?p=602270

With a properly configured fastdl server you don't need to use the AddFileToDownloadsTable command.
PC Gamer is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 05-18-2020 , 09:38   Re: How to play custom sound?
Reply With Quote #7

Quote:
Originally Posted by PC Gamer View Post
I didn't add the sound of the Announcers voice to the downloads table since it already exists on the players computer. It was installed with the game.

As MAGNAT2645 stated, you will need to place your .wav file in tf/sound/custom/ folder. You will also need a way to send the sound files to the players, either by adding it with the AddFileToDownloadsTable or using a fastdl server and plugin like: https://forums.alliedmods.net/showthread.php?p=602270

With a properly configured fastdl server you don't need to use the AddFileToDownloadsTable command.
You could say sound is built into game.

Also actually you always need to use AddFileToDownloadsTable to send files from server to clients (only if sound is not built into game). As PC Gamer said, AddFileToDownloadsTable can be placed manually into code (if you use your own sounds) or you can use any Auto-Precacher plugin.
__________________

Last edited by MAGNAT2645; 05-18-2020 at 09:43.
MAGNAT2645 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:28.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode