Frictional Games Forum (read-only)
Custom sound files when interacting with objects... - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Custom sound files when interacting with objects... (/thread-10413.html)



Custom sound files when interacting with objects... - ZyLogicX - 09-20-2011

I have this awesome Idea for my conversion mod. But I dont know how I should appraoch it.

Basically, I want the player to say things when interacting with objects... so like when you pick up a broom, the audio file starts and says 'I dont know how that is going to work'

Is it possible for me to do, and How?


RE: Custom sound files when interacting with objects... - Obliviator27 - 09-20-2011

(09-20-2011, 04:30 PM)ZyLogicX Wrote: I have this awesome Idea for my conversion mod. But I dont know how I should appraoch it.

Basically, I want the player to say things when interacting with objects... so like when you pick up a broom, the audio file starts and says 'I dont know how that is going to work'

Is it possible for me to do, and How?
You're going to have to add a PlayerInteract callback (which can be made directly from the level editor) that calls a PlaySoundAtEntity function.

Example:
void PlayBroomPickup(string &in asEntity)
{
PlaySoundAtEntity("", "[customsound + .snt extension]", "Player", 0, false);
}

Making sure that you have PlayBroomPickup as your item interact callback in the level editor. If you want this to happen every time you pick up the broom, don't have "callbackautoremove" checked in the editor.

Hopefully this solves your problem. Smile




RE: Custom sound files when interacting with objects... - Pr3d4t0r - 09-20-2011

Oliviator, please can you help me too please because you're here ?

How can I put custom music (ambient) to my CS ?

I made a music, exported it in *.ogg and I copied a snt file from the game and changed its parameters for my sound, but when I play it in the editor, it doesn't play anything... doesn't play in game neither !

Can you help me ?

thanks ^^




RE: Custom sound files when interacting with objects... - Obliviator27 - 09-20-2011

Sure thing!
Ambient music is really quite simple to implement.
You don't need a .snt file for ambient music. All you need is the .ogg.
Then, in your OnStart function, add Playmusic.

Example
void OnStart()
{
PlayMusic
("[musicname + .ogg extension]", [true or false if you want it to loop], [A decimal for volume. Usually below 1, but above 0], [time until music reaches full volume], [Priority of music. Zero is highest priority], [true or false if you want it to resume if it gets interrupted (i.e, monster attack)]);
}

Taken from:

void PlayMusic(string& asMusicFile, bool abLoop, float afVolume, float afFadeTime, int alPrio, bool abResume);

Plays music.

asMusicFile - the music to play + extension .ogg
abLoop - determines whether a music track should loop
afVolume - volume of the music
afFadeTime - time in seconds until music reaches full volume
alPrio - priority of the music. Note that only the music with the highest priority can be heard! 0 - highest, 1 - lower, etc



And have the music.ogg file in a sounds folder in your main directory for your custom story

Feel free to PM me with any more questions you may have. Smile



RE: Custom sound files when interacting with objects... - Pr3d4t0r - 09-20-2011


Thank you very much ! But when will the sound start with these lines ? At the beginning of the map ? Because I just want to implement a music in the beginning of the map, wich is looped BUT only in a certain area ! Something like when you get out of the room, you can't hear the music anymore but when you come back into this room, you can hear this music again.

There is my new code :

Code:
void OnStart()
    {
    PlayMusic("amb_pain.ogg", true, 0.6, 0, 0, true);
    AddUseItemCallback("", "key_001", "door_001", "UsedKeyOnDoor", true);
    SetEntityPlayerInteractCallback("torch_001", "funclamp1", true);
    SetEntityPlayerInteractCallback("torch_002", "funclamp2", true);
    SetEntityPlayerInteractCallback("torch_003", "funclamp3", true);
    AddTimer("1", 2, "IntroTimer");
    AddTimer("2", 4.5f, "IntroTimer");
    AddTimer("3", 6.5f, "IntroTimer");
    AddTimer("4", 9, "IntroTimer");
    AddTimer("5", 11, "IntroTimer");
    AddTimer("6", 14, "IntroTimer");
    AddTimer("7", 19, "IntroTimer");
    StartPlayerLookAt("wine01_1", 1, 2.0f, "");
    FadeOut(0.0f);
    FadePlayerRollTo(80, 55, 55);
    SetPlayerActive(false);
    SetPlayerCrouching(true);
    FadeRadialBlurTo(0.10, 2);
    FadeRadialBlurTo(0.10, 2);
    SetEntityPlayerInteractCallback("lantern", "Monsters", true);
    AddEntityCollideCallback("Player", "ScriptArea_2", "WalkingMonster", true, 1);
    }

    void WalkingMonster(string &in asParent, string &in asChild, int alState)
    {
    SetPlayerActive(false);
    AddTimer("", 0.5f, "Walk");
    StartPlayerLookAt("torch_floor_2", 5, 7, "");
    GiveSanityDamage(5.0f, true);
    }

    void Walk(string &in asTimer)
    {
    SetEntityActive("servant_brute_1", true);
    AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_1", 0, "flex.dae");
    AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_9", 0, "kiss.dae");
    AddTimer("", 8.0f, "Stop");
    }

    void Stop(string &in asTimer)
    {
    StopPlayerLookAt();
    SetPlayerActive(true);
    }

    void Monsters(string &in entity)
    {
    SetEntityActive("invisible_monster_001", true);
    GiveSanityDamage(5.0f, true);
    PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
    StartPlayerLookAt("Invisible_monster_001", 5, 7, "");
    AddTimer("", 1.5f, "Scare");
    SetPlayerActive(false);
    SetPlayerCrouching(true);
    PlaySoundAtEntity("", "amb_hunt.snt", "Player", 0, false);
    }

    void Scare(string &in asTimer)
    {
    StopPlayerLookAt();
    AddTimer("", 1.0f, "Second");
    }

    void Second(string &in asTimer)
    {
    SetEntityActive("invisible_monster_002", true);
    GiveSanityDamage(5.0f, true);
    PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
    AddTimer("", 1.0f, "AllMonstersGone");
    StartPlayerLookAt("invisible_monster_002", 5.0f, 7.0f, "");
    PlaySoundAtEntity("", "amb_hunt.snt", "Player", 0, false);
    }

    void AllMonstersGone(string &in asTimer)
    {
    StopPlayerLookAt();
    SetPlayerActive(true);
    SetLampLit("torch_floor_1", false, false);
    SetLightVisible("PointLight_17", false);
    SetLightVisible("PointLight_16", false);
    }

    void IntroTimer(string &in asTimer)
    {
    if(asTimer == "1"){
    PlayGuiSound("player_cough.snt", 2.0f);
    StopPlayerLookAt();
    FadeIn(2.4f);
    }
    else if(asTimer == "2"){
    FadePlayerRollTo(75, 1, 1); // "Tilts" the players head
    FadeOut(1.5f);
    }
    else if(asTimer == "3"){
    StartPlayerLookAt("chair_wood02_broken_1", 1, 2.0f, "");
    FadeIn(1.5f);
    PlayGuiSound("player_cough.snt", 2.0f);
    }
    else if(asTimer == "4"){
    StopPlayerLookAt();
    StartPlayerLookAt("stool_wood_1", 1, 2.0f, "");
    FadeOut(1.5f);
    }
    else if(asTimer == "5"){
    StopPlayerLookAt();
    StartPlayerLookAt("candlestick_floor_1", 1, 2.0f, "");
    FadeIn(1.5f);
    }
    else if(asTimer == "6"){
    StopPlayerLookAt();
    FadePlayerRollTo(0, 33, 33); // Change all settings to defaults
    FadeOut(1.5f);
    }
    else if(asTimer == "7"){
    FadeImageTrailTo(0, 1.0f);
    FadeRadialBlurTo(0.0, 1);
    SetPlayerActive(true);
    FadeIn(1.5f);
    }
    }

    void UsedKeyOnDoor(string &in asItem, string &in asEntity)
    {
    SetSwingDoorLocked("door_001", false, true);
    PlaySoundAtEntity("", "unlock_door", "door_001", 0, false);
    RemoveItem("key_001");
    }

    void funclamp1(string &in asEntity)
    {
    AddLocalVarInt("LampsX", 1);

    if(GetLocalVarInt("LampsX")==3)
    {

    SetEntityActive("secret_door_001", false);
    SetEntityActive("secret_door_2", true);
    PlayGuiSound("quest_completed.snt", 2.0f);
    return;
    }

    }

    void funclamp2(string &in asEntity)
    {
    AddLocalVarInt("LampsX", 1);

    if(GetLocalVarInt("LampsX")==3)
    {

    SetEntityActive("secret_door_001", false);
    SetEntityActive("secret_door_2", true);
    PlayGuiSound("quest_completed.snt", 2.0f);
    return;
    }

    }

    void funclamp3(string &in asEntity)
    {
    AddLocalVarInt("LampsX", 1);

    if(GetLocalVarInt("LampsX")==3)
    {

    SetEntityActive("secret_door_001", false);
    SetEntityActive("secret_door_2", true);
    PlayGuiSound("quest_completed.snt", 2.0f);
    return;
    }

    }

Now it works in game thank you !! Big Grin

I added a sound entity with my ogg.file in the area where i want my sound to play. But if I leave this area, will the music stop ?



RE: Custom sound files when interacting with objects... - Obliviator27 - 09-20-2011

(09-20-2011, 06:23 PM)Pr3d4t0r Wrote: Thank you very much ! But when will the sound start with these lines ? At the beginning of the map ? Because I just want to implement a music in the beginning of the map, wich is looped BUT only in a certain area ! Something like when you get out of the room, you can't hear the music anymore but when you come back into this room, you can hear this music again.
I added a sound entity with my ogg.file in the area where i want my sound to play. But if I leave this area, will the music stop ?
If I understand your question correctly, the sounds will play over top of the ambient music. And I can't think of any special way of playing the music in a certain room. All I can think of would be to have an area on each side of the door, and corresponding collidecallbacks. In the one outside the room, you use a StopMusic function (on the wiki) and in the one for inside, PlayMusic. Just don't autodelete the collide callback, and it should work fine. There's probably a better way to do this, but it's all I can think of at the moment.




RE: Custom sound files when interacting with objects... - ZyLogicX - 09-20-2011

Thank you Obliviator27... I got it working, thanks


RE: Custom sound files when interacting with objects... - Pr3d4t0r - 09-21-2011

Thank you Obliviator for your help Smile