Raised This Month: $51 Target: $400
 12% 

TF2: Playing announcer sounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mike_BoG
SourceMod Donor
Join Date: Jul 2011
Old 09-09-2011 , 14:03   TF2: Playing announcer sounds
Reply With Quote #1

Hi,

How would I go on playing the sounds "Success!, Good job" And all those sounds with SourceMod? Please post an example, like what events i need to hook and all that if its even possible.
Mike_BoG is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-09-2011 , 14:34   Re: TF2: Playing announcer sounds
Reply With Quote #2

Playing the sounds is easy. You'll need to PrecacheSound in OnMapStart or OnConfigsExecuted if reading from a config file and then EmitSoundToClient or EmitSoundToAll when the voice should be played (however, you haven't said when that is).

The files themselves are located in sound/vo/announcer_* including some currently unused ones.

For instance, if I wanted to play "Success!" to a player when they kill someone (and note that this is an extremely simplified version that doesn't detect multiple kills at the same time or anything else that could cause problems):

PHP Code:
// Emit TF2 Success! sound when someone gets a kill

#include <sourcemod>
#include <sdktools_sound>

#define SUCCESS "vo/announcer_success.wav"
public Plugin:myinfo 
{
    
name "Success",
    
author "Powerlord",
    
description "Play Announcer Success message to a player when they get a kill",
    
version "1.0",
    
url "<- URL ->"
}

public 
OnPluginStart()
{
    
HookEvent("player_death"KillEventHandler);
}

public 
OnMapStart()
{
    
PrecacheSound(SUCCESS);
}

public 
KillEventHandler(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"attacker"));
    if (
IsClientInGame(client))
    {
        
EmitSoundToClient(clientSUCCESS);
    }

Note: This code is untested... I just know that it compiles.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-09-2011 at 14:38.
Powerlord is offline
Mike_BoG
SourceMod Donor
Join Date: Jul 2011
Old 09-09-2011 , 14:39   Re: TF2: Playing announcer sounds
Reply With Quote #3

Hi. Aha, so the precaching must happen at mapstart, that can be one of the reason my script didn't work. Thanks for the explanation

Edit: How would I go on creating the sound when e.g test_command is triggered?

Code:
#include <sourcemod>
#include <sdktools_sound>

#define SUCCESS "vo/announcer_success.wav"

public OnPluginStart()
{
	RegServerCmd("test_command", Command_Test)
}

public OnMapStart()
{
    PrecacheSound(SUCCESS);
}

public Action:Command_Test(args)
{
    EmitSoundToAll(SUCCESS);
}
I hate being noob :s

Last edited by Mike_BoG; 09-09-2011 at 14:46.
Mike_BoG is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-09-2011 , 14:57   Re: TF2: Playing announcer sounds
Reply With Quote #4

Quote:
Originally Posted by Mike_BoG View Post
Hi. Aha, so the precaching must happen at mapstart, that can be one of the reason my script didn't work. Thanks for the explanation

Edit: How would I go on creating the sound when e.g test_command is triggered?

Code:
#include <sourcemod>
#include <sdktools_sound>

#define SUCCESS "vo/announcer_success.wav"

public OnPluginStart()
{
    RegServerCmd("test_command", Command_Test)
}

public OnMapStart()
{
    PrecacheSound(SUCCESS);
}

public Action:Command_Test(args)
{
    EmitSoundToAll(SUCCESS);
}
I hate being noob :s
RegServerCmd only adds a command that's accessed from the server console. If you want one any user can run via /test_command or !test_command, you'll need RegConsoleCmd (yes, Console Commands are chat commands, while Server Commands are console only...)

Alternatively, there is also RegAdminCmd which takes more arguments, but restricts it to admins with specific flags (including the reserved slot flag).

Other than that, it looks right.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Mike_BoG
SourceMod Donor
Join Date: Jul 2011
Old 09-09-2011 , 14:58   Re: TF2: Playing announcer sounds
Reply With Quote #5

Aha, does my code look okay by the way? Also, what program do you use to code? Notepad ++?

Edit: Got a error when i changed it to RegConsoleCmd. function prototypes does not match.

Edit2: Figured it out. It needs the same parameters as the Admin cmd.

Last edited by Mike_BoG; 09-09-2011 at 15:09.
Mike_BoG is offline
FlaminSarge
Veteran Member
Join Date: Jul 2010
Old 09-09-2011 , 17:28   Re: TF2: Playing announcer sounds
Reply With Quote #6

If you're just looking to play sounds on command, you can use the stock sourcemod sounds.smx plugin. sm_play <target> "soundfile"
__________________
Bread EOTL GunMettle Invasion Jungle Inferno 64-bit will break everything. Don't even ask.

All plugins: Randomizer/GiveWeapon, ModelManager, etc.
Post in plugin threads with questions.
Steam is for playing games.
You will be fed to javalia otherwise.
Psyduck likes replays.
FlaminSarge 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 09:46.


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