Frictional Games Forum (read-only)

Full Version: Item pickup trigger sound help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, sorry for posting so much, just running into a few problems that I can't figure out. I want to make it so when the player picks up a key, a sound is played, but besides using an area near the key to simulate that, I can't see a way to do that.

Also, along the same lines, is it possible to take control of player's camera after the key is picked up and turn them to a closet so a monster can come out kinda thing?
You can use PlayGuiSound() if you don't care where the sound is coming from. If you want the sound positioned 3D in the level, use an area with PlaySoundAtEntity().

You can control the player's view with StartPlayerLookAt(). Just tell it where to look (I recommend script areas) and how fast and such. Remember to use StopPlayerLookAt() or else they will be stuck looking there. Combine these with AddTimer() to have it happen at specific times.

You'll find all the info on the scripts page. Just ctrl-F what you need:
https://wiki.frictionalgames.com/doku.ph..._functions
When I run the game, it crashes and says expected data type. I'm pretty sure my code is wrong, I'll put it here:

void OnStart()
{

AddUseItemCallback("", "Key", "Door", "UseKeyOnDoor", true);
AddUseItemCallback("OpenDoor", "LevelKey1", "LevelDoor1", "UseKeyOnLevelDoor", true);
AddEntityCollideCallback("Player", "SpawnScare", "SoundCheck2", true, 1);
AddEntityCollideCallback("Player", "OpenScare", "SoundCheck", true, 1);
SetEntityCallbackFunc("Key", PickUp);
}



void PickUp("Key", "OnPickup")
{
PlaySoundAtEntity("pickupsound", "21_screams.snt", "PickupSound", 0.01f, false);
}


void SoundCheck2(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("ambientsound", "ambience_wind_eerie.snt", "SpawnScare", 0.01f, true);
}

void SoundCheck(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("scaresound", "notice.snt", "Player", 0.01f, false);
}

void UseKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "unlock_door.snt", asEntity, 0, false);
RemoveItem(asItem);
}

void UseKeyOnLevelDoor(string &in asItem, string &in asEntity)
{

SetLevelDoorLocked(asEntity, false);
PlaySoundAtEntity("", "unlock_door.snt", asEntity, 0, false);
RemoveItem(asItem);
}
void OnLeave()
{
SetupLoadScreen("Loading", "LoadScreen1", 0, "LoadingScreen1.jpg");
}
void PickUp("Key", "OnPickup")

This line; you're not supposed to fill in the constructor. Copy and paste the original callback syntax.
Also, this isn't really related but I didn't want to start a whole thread, but how do I import custom sounds? I took a YouTube link, converted to MP3, and then exported to OGG, but when I put in my script, no sound plays in the level. It's in my custom story folder so I don't know whats wrong.

Oh never mind, got it to snt
I also just noticed this line

SetEntityCallbackFunc("Key", PickUp);

is missing a pair of quotes around PickUp. Other than that, what did you mean by your last comment?
Oh that was just me getting the sound to work, kinda worded it weirdly.