Skip to content

Conversation

@powerlord
Copy link
Contributor

This is an updated version of the code from bug 5942

Basically, it consists of two natives: PrecacheScriptSound and GetGameSoundParams.

native bool:PrecacheScriptSound(const String:soundname[]);
PrecacheScriptSound caches all sounds associated with a game sound that aren't already cached.

native bool:GetGameSoundParams(const String:gameSound[],
                &channel,
                &soundLevel,
                &Float:volume,
                &pitch,
                String:sample[],
                maxlength,
                entity=SOUND_FROM_PLAYER);

GetGameSoundParams takes a game sound name and fetches the fields from game_sounds.txt (and a game's other game_sound files) into the channel, soundLevel, volume, pitch, and sample fields. entity is used to determine the gender of the sound if a particular sound has genders. It will return false if the sound wasn't found. Note that sample will be random on game_sounds that have a rndwave section.

In addition, there are several new stocks that serve as wrappers for GetGameSoundParams:
EmitGameSound, EmitGameSoundToAll, EmitGameSoundToClient, and EmitAmbientGameSound. These are all based on the EmitSound wrappers of the same name and take roughly the same arguments, but with the game sound name instead of the sample.

These wrap GetGameSoundParams andEmitSound/EmitAmbientSound as appropriate. All of them return false if GetGameSoundParams returns false.

Standard expected usage is something like this:

public OnMapStart()
{
    PrecacheScriptSound("Announcer.MVM_Bonus");
}

// Later on
    EmitGameSoundToClient(client, "Announcer.MVM_Bonus");

Note: Most game sounds are precached by the game itself on map start, but this isn't guaranteed. For instance, TF2 doesn't cache the above sound on non-MvM maps. Therefore, it's recommended to use PrecacheScriptSound, which checks if a sound is precached before precaching it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overwrote the wrong line when I was adding natives actually... copy/pasted the GetDistGainFromSoundLevel line twice, overwrote the second one with {"PrecacheScriptSound", smn_PrecacheScriptSound}, then overwrote that with {"GetGameSoundParams", smn_GetGameSoundParams},

Not sure if I can append a Pull Request or if I have to make a new one... guess I'll find out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently making a new commit automatically updates the pull request... I hated that behavior in bitbucket, I'm certainly not hating it any less here.

@powerlord
Copy link
Contributor Author

Fixed an issue where I'd left a second copy of the GetDistGainFromSoundLevel native instead of the PrecacheScriptSound native.

@psychonic
Copy link
Member

Apparently making a new commit automatically updates the pull request... I hated that behavior in bitbucket, I'm certainly not hating it any less here.

If you use a branch per PR, rather than master, it's actually a very nice feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be wise to also check !edict->IsFree().

return GetParametersForSoundEx's return value instead of always true.
@powerlord
Copy link
Contributor Author

@psychonic Well, if I knew it would do that in advance, then maybe. Problem is, I didn't... and it's unexpected behavior if you don't know it's going to happen.

@voided
Copy link
Contributor

voided commented Jul 3, 2014

Surely there's a similar message on master?

@psychonic
Copy link
Member

Let not head too far offtopic 😺

@powerlord
Copy link
Contributor Author

@voided There is (assuming I saw it), but it's too late to change it by the time you see it, because you've already opened the pull request.
spycon (I was expecting this to be smaller, whoops)

@psychonic
Copy link
Member

Oops. I didn't notice the last commit. Looks alright enough to me. Let's give it a go on master.

psychonic added a commit that referenced this pull request Jul 4, 2014
New functions for SDKTools to get information from game_sound files (r=psychonic).
@psychonic psychonic merged commit ffa1887 into alliedmodders:master Jul 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants