Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An eager newcomer who wants to learn...
C-zom Offline
Junior Member

Posts: 22
Threads: 3
Joined: Aug 2009
Reputation: 0
#11
RE: An eager newcomer who wants to learn...

I hate to bump this but literally everything is solved except my sound problem.

I've got no idea how to make a sound play when you enter an area. I've followed the Script Functions wiki up and down, but its difficult.

I need someone to help me with two aspects of sound.

One,

I really would appreciate whoever helps me. You can teach me a little tutorial one, like playing a pin drop or a footstep. Anything to get me familiar with the script to advance on my own with it .

Two,

Ambient sound, how do I get a sound file like a music .ogg or something to play throughout an entire level on startup so that it loops until you leave the level?

08-11-2011, 11:12 PM
Find
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#12
RE: An eager newcomer who wants to learn...

question 1:
there are three ways to make a sound play, two of those can be activated when entering an area.

- way 1: place a sound entity in Level Editor. These cannot be manipulated, only good for sounds which will be constantly there (like rain patter or fire sound)

- way 2: PlayGuiSound("soundfile.snt" , 1.0f); - this can be activated when entering an area, and creates the sound at the player. however, the sound cannot be stopped with stopsound. this is useful for gasps and sighs by the player.

- way 3: PlaySoundAtEntity("" , "soundfile.snt" , "entity" , 0.0f , false); - this is the way which you would probably like to use and can also be enabled when collidind with an area, it creates a sound at an entity (this can be a door, a script area, an enemy, or even you - "Player")

now to create the sound when you touch an area. in your void OnStart() use
AddEntityCollideCallback("ParentEntity" , "ChildEntity" , "FunctionName" , true , 1);
in this case ParentEntity == "Player"
ChildEntity == "NameofScriptArea"
FunctionName == "Whatever you want"
then create a function for your callback.

void FunctionName(string &in asParent , string &in asChild , int alState)
{
// here use the playsoundatentity i described earlier
}

"(string &in asParent , string &in asChild , int alState)" is something specific to AddEntityCollideCallback. Every AddEntityCollideCallback will link to a function with these 'parameters' (sorry if thats wrong word to use).

Question 2 -

this is a lot easier. in void OnEnter() add

PlayMusic("musicfile.ogg" , true , 1.0f , 10.0f , 1 , true);

the music files can be found in Amnesia - the dark descent>Redist>Music browse to the one you like, then put it in the script!

(This post was last modified: 08-11-2011, 11:37 PM by DRedshot.)
08-11-2011, 11:31 PM
Find
Acies Offline
Posting Freak

Posts: 1,643
Threads: 60
Joined: Feb 2011
Reputation: 73
#13
RE: An eager newcomer who wants to learn...

Script functions can be found here: http://wiki.frictionalgames.com/hpl2/amn..._functions

-- I have taken the liberty to copy paste the functions regarding sound --

This is for playing music:
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

Can be used to play a sound (without any specific location):

void PlayGuiSound(string& asSoundFile, float afVolume);
Plays a sound, not using 3D.

asSoundFile - the sound to play (extension is .snt) **Acies comment: The extension might very well be .ogg - I don't know why the user set it so be .snt , but .snt works too.**
afVolume - the volume of the sound

This functions plays a sound at a specific location:

void PlaySoundAtEntity(string& asSoundName, string& asSoundFile, string& asEntity, float afFadeTime, bool abSaveSound);
Creates a sound on an entity.

asSoundName - internal name
asSoundFile - the sound to use + extension .snt
asEntity - the entity to create the sound at, can be “Player”
afFadeTime - time in seconds the sound needs to fade
abSaveSound - determines whether a sound should “remember” its state. If true, the sound is never attached to the entity! Also note that saving should on be used on looping sounds!

I think that for a "location sound" the extension must be ".snt".

Some other comments on playing sounds:
- Playgui works on every sound.
- PlaySoundAtEntity can use a scriptarea as an entity (good to create an invisible place from where the sound is played).
- The "alPrio" concerning playing music is important when stopping music.
void StopMusic(float afFadeTime, int alPrio);
Stops music.

afFadeTime - time in seconds until music stops
alPrio - the priority of the music that should stop

When stopping music the alPrio must be the same number as issued at Playmusic.

[Image: mZiYnxe.png]


(This post was last modified: 08-11-2011, 11:35 PM by Acies.)
08-11-2011, 11:34 PM
Find
C-zom Offline
Junior Member

Posts: 22
Threads: 3
Joined: Aug 2009
Reputation: 0
#14
RE: An eager newcomer who wants to learn...

Thanks to both of you so much. I really appreciate this, it'll help me on my way with my mod quite a lot. Big Grin

08-11-2011, 11:35 PM
Find
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#15
RE: An eager newcomer who wants to learn...

When the player collides with an area of some sorts, which in this example I'll call "ScriptArea_1", we have a footstep sound play. When using the PlaySoundAtEntity command function, you have to choose a location at which the sound will be played at. Perhaps behind the player? Lets call this area/object "SoundPlay".

PlaySoundAtEntity(string& asSoundName, string& asSoundFile, string& asEntity, float afFadeTime, bool abSaveSound);

As I take this directly from the script functions page on the wiki, it may be overwhelming to someone who starts scripting for Amnesia. So lets take it apart.

string& asSoundName - This is the name of the sound. It can be left blank if you're dealing with non-repeatable sounds, so if it was, you could call it "Sound01" and then you would use the remove sound command function to disable it from looping continuously.

string& asSoundFile - This is the name of the sound file located in the "sounds" folder under your "amnesia the dark descent" or "Redist" folder. You will notice that there are ".ogg" and ".snt" extensions. ".snt" extensions are just text files that edit what the ".ogg" file does which include sound volume, fade in, fade out, loop, and some more. There is also one feature that allows multiple sounds get set up for one of them to be played at random. If you want to, you can right click on a ".snt" extension file and open it with a text editor. For this PlaySoundAtEntity command function, you can only fill this sound file slot with one that has the extension of ".snt".

string& asEntity - This is the name of the entity/area from which the sound is played at. If the object is too far away from the player, the sound may not be heard.

float afFadeTime - This is where a number is put into this slot for how long it will take the sounds to fade completely in.

bool abSaveSound - I'm not really sure why this is needed, but it maybe used for when stopping the sound and then playing it again but continuing it from the point it stopped at.

Here's what the example code could look like:

void OnStart()
{
     AddEntityCollideCallback("Player", "ScriptArea_1", "Func01", true, 1);
}
void Func01(string &in asParent, string &in asChild, int alState)
{
     PlaySoundAtEntity("", "scare_steps_big.snt", "SoundPlay", 0, false);
}

It appears this has been long gone forgotten and that I have been really late at posting this. Sad

(This post was last modified: 08-11-2011, 11:44 PM by Kyle.)
08-11-2011, 11:43 PM
Find




Users browsing this thread: 1 Guest(s)