Frictional Games Forum (read-only)

Full Version: Just Scripting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I trigger a sound to play when I collect an item?
Okay...

But I am a bit confused. Where do you want the sound to be played? At an object or at the player?
Screw it, I'll give you both.

SOUND PLAYS AT PLAYER
Spoiler below!

PHP Code:
void OnStart()
{
SetEntityCallbackFunc("ItemName""PlaySound");
}

void PlaySound(string &in asEntitystring &in type)
{
PlayGuiSound("SoundFile.snt"1); //1 is the volume. Change it to whatever volume you want



SOUND PLAYS AT AN OBJECT
Spoiler below!

PHP Code:
void OnStart()
{
SetEntityCallbackFunc("ItemName""PlaySound");
}

void PlaySound(string &in asEntitystring &in type)
{
PlaySoundAtEntity("SoundObject""SoundFile.snt""EntityWhereTheSoundWillBeFrom"0.1ffalse);


So there's no code for collecting the item or adding it to your inventory?
You trigger the sound with the SetEntityCallbackFunc. If the entity can be picked up, the type of this callback will be PickUp. It then runs the PlaySound function which runs the PlaySoundAtEntity function. Basically, the sound plays when you pick up the desired item.

If you wish to play the sound at the player itself, I prefer using PlayGuiSound. Look it up at the engine scripts page. https://wiki.frictionalgames.com/doku.ph..._functions

Edit: Also, what are you trying to pick up? If it's an item, you can just click it. If it's a custom one, you'll need to do more work. There is a script called GiveItem that can give you an inventory item.
This thread belongs in development support, moved!