Frictional Games Forum (read-only)
[SCRIPT] Random Looped Sound - 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: [SCRIPT] Random Looped Sound (/thread-25751.html)

Pages: 1 2


Random Looped Sound - Plazmater - 07-25-2014

Everyone knows that the sound in game is the most important thing for atmosphere.

And its not only PlayMusic or PlaySoundAtEntity (with looped "amb" sound).

What i want to do is to create area from where looped snt. sound will be played with intervals.
(So it can play randomly between every 15-25 secs in loop).

But i have no idea how to script this. Any idea ?


RE: Random Looped Sound - i3670 - 07-25-2014

void FunctionTimer(string &in asTimer)
{
int iArea = RandFloat(1, 7); <--- if you want the sound to be played at different areas: insert the number of areas.
float fTime = RandFloat(4.5f,7.5f); <--- insert the number of seconds between timers, in your case 15.0f and 25.0f

PlaySoundAtEntity("NameOfSoundInGame"+iArea , "NameOfSound.snt", "AreaWhereTheSoundPlays"+iArea , 0.0f, false);

AddTimer("TimerName", 5.5f+fTime , "FunctionTimer");
}


RE: Random Looped Sound - Plazmater - 07-25-2014

"int iArea = RandFloat(1, 7); <--- if you want the sound to be played at different areas: insert the number of areas."

I cant quite understand that , if i would set it (1, 3) , so it would play sound at original area and 2 others. But at which 2 other areas ? Should I create them and SOMEHOW script it as another areas for the same sound. Or it would randomly found 2 more areas that exist on the map and play it there ?

void FunctionTimer(string &in asTimer)
{
int iArea = RandFloat(1, 3);
float fTime = RandFloat(5f,7f);

PlaySoundAtEntity("afx_spooky_mansion_whisper"+iArea , "afx_spooky_mansion_whisper.snt", "ScriptArea_1"+iArea , 0.0f, false);

AddTimer("TimerName", 1.0f+fTime , "FunctionTimer");
}

I keep getting error:

FATAL ERROR: Could not load script file 'MyFC/maps/Level1.hps'!
main (15, 26) : ERR : Expected ')' or ','


RE: Random Looped Sound - Mudbill - 07-25-2014

When you copy an area, it makes a new one with another number at the end. For example ScriptArea_1 and ScriptArea_2. That allows you to write the name "ScriptArea_" because they both have this name, and then you can, through the script, add all the numbers at the end.

In this example, the int variable iArea will add the numbers randomly. If you have 10 areas with the same name, just different numbers at the end, then make iArea = RandFloat(1, 10);

Then when you do "ScriptArea_" + iArea in your script, it will add a random number to the name and thus play the sound at a random area, as long as the names match.

PS: I think int iArea needs to use RandInt and not RandFloat because it is an int and not a float.


RE: Random Looped Sound - Plazmater - 07-25-2014

int iArea = RandInt(1, 3);

Still the same error.


RE: Random Looped Sound - Mudbill - 07-25-2014

What's your whole script?

By the way, do not do "ScriptArea_1"+iArea because that will result in ScriptArea_11.


RE: Random Looped Sound - Plazmater - 07-25-2014

void FunctionTimer(string &in asTimer)
{
int iArea = RandInt(1, 3);
float fTime = RandFloat(5f, 7f);

PlaySoundAtEntity("afx_spooky_mansion_whisper"+iArea, "afx_spooky_mansion_whisper.snt", "ScriptArea_"+iArea, 0.0f, false);

AddTimer("TimerName", 1.0f+fTime, "FunctionTimer");
}


RE: Random Looped Sound - Mudbill - 07-25-2014

Your error says you have something wrong at line 15. This can't be your whole script because this isn't even 15 lines.


RE: Random Looped Sound - Plazmater - 07-25-2014

This is from start:


void LanternEvent(string &in asEntity, string &in type)
{
AddPlayerLampOil(70.0f);

SetSwingDoorLocked("mansion_6", false, false);
PlayMusic("music_mansion_lanternpickup.ogg", false, 1.0f, 0, 0, true);
}


void FunctionTimer(string &in asTimer)
{
int iArea = RandInt(1, 3);
float fTime = RandFloat(5f, 7f);

PlaySoundAtEntity("afx_spooky_mansion_whisper"+iArea, "afx_spooky_mansion_whisper.snt", "ScriptArea_"+iArea, 0.0f, false);

AddTimer("TimerName", 1.0f+fTime, "FunctionTimer");
}


RE: Random Looped Sound - i3670 - 07-25-2014

try

float fTime = RandFloat(5.0f, 7.0f);

Also, don't forget to add the timer in the OnStart or else it won't trigger.